diff options
Diffstat (limited to 'netbytes.c')
-rw-r--r-- | netbytes.c | 40 |
1 files changed, 37 insertions, 3 deletions
@@ -165,6 +165,8 @@ int nb_add_u8arr( netbyte_store *store, nb_u8arr *u8arr ) int nb_add_u16( netbyte_store *store, nb_u16 *u16 ) { + nb_u16 *new_u16 = NULL; + if ( store->count >= __NBT_MAX_TYPES - 1 ) return -1; @@ -172,7 +174,11 @@ int nb_add_u16( netbyte_store *store, nb_u16 *u16 ) return -2; store->types[store->count].type = NBT_U16; - store->types[store->count].nb_val = (uint8_t *)u16; + + new_u16 = malloc(sizeof(nb_u16)); + memcpy(new_u16, u16, sizeof(nb_u16)); + store->types[store->count].nb_val = (uint8_t *)new_u16; + store->count += 1; return 0; } @@ -195,6 +201,8 @@ int nb_add_u16arr( netbyte_store *store, nb_u16arr *u16arr ) int nb_add_u32( netbyte_store *store, nb_u32 *u32 ) { + nb_u32 *new_u32 = NULL; + if ( store->count >= __NBT_MAX_TYPES - 1 ) return -1; @@ -202,7 +210,11 @@ int nb_add_u32( netbyte_store *store, nb_u32 *u32 ) return -2; store->types[store->count].type = NBT_U32; - store->types[store->count].nb_val = (uint8_t *)u32; + + new_u32 = malloc(sizeof(nb_u32)); + memcpy(new_u32, u32, sizeof(nb_u32)); + store->types[store->count].nb_val = (uint8_t *)new_u32; + store->count += 1; return 0; } @@ -225,6 +237,8 @@ int nb_add_u32arr( netbyte_store *store, nb_u32arr *u32arr ) int nb_add_u64( netbyte_store *store, nb_u64 *u64 ) { + nb_u64 *new_u64 = NULL; + if ( store->count >= __NBT_MAX_TYPES - 1 ) return -1; @@ -232,7 +246,11 @@ int nb_add_u64( netbyte_store *store, nb_u64 *u64 ) return -2; store->types[store->count].type = NBT_U64; - store->types[store->count].nb_val = (uint8_t *)u64; + + new_u64 = malloc(sizeof(nb_u64)); + memcpy(new_u64, u64, sizeof(nb_u64)); + store->types[store->count].nb_val = (uint8_t *)new_u64; + store->count += 1; return 0; } @@ -463,6 +481,15 @@ int nb_free(netbyte_store *store) store->types[i].type=0; break; } + case NBT_U32: + { + nb_u32 *u32 = (nb_u32 *)val; + //free(u32); + //u32 = NULL; + store->types[i].nb_val=NULL; + store->types[i].type=0; + break; + } default: printf("Unknown type\n"); } @@ -766,6 +793,13 @@ int nb_print(netbyte_store *store) u8arr->type, u8arr->len, u8arr->val); break; } + case NBT_U32: + { + nb_u32 *u32 = (nb_u32 *)store->types[i].nb_val; + printf("u32: t=0x%x v=0x%x", + u32->type, u32->val); + break; + } default: printf("Unknown"); } |