From fcb0cce437cea8b028bc8d52af921de41301b803 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 20 Feb 2017 08:15:16 -0500 Subject: [PATCH] Minor fixes to the conversion from bytes to MultiAddress --- include/multiaddr/protoutils.h | 9 +++++++-- multiaddr.c | 1 + protoutils.c | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/multiaddr/protoutils.h b/include/multiaddr/protoutils.h index 472e755..027bd0f 100644 --- a/include/multiaddr/protoutils.h +++ b/include/multiaddr/protoutils.h @@ -31,8 +31,13 @@ uint64_t ip2int(const char * ipconvertint); char * int2ip(int inputintip); -//I didn't feel another address_bytes_to_string was necesarry sry guys -int bytes_to_string(char** resultzx, const uint8_t * catx,int xbsize); +/** + * Unserialize the bytes into a string + * @param results where to put the resultant string + * @param bytes the bytes to unserialize + * @param bytes_size the length of the bytes array + */ +int bytes_to_string(char** results, const uint8_t* bytes, int bytes_size); char * address_string_to_bytes(struct Protocol * xx, const char * abc, size_t getsznow); diff --git a/multiaddr.c b/multiaddr.c index fd38920..093219d 100644 --- a/multiaddr.c +++ b/multiaddr.c @@ -50,6 +50,7 @@ struct MultiAddress* multiaddress_new_from_bytes(const uint8_t* byteaddress, int return NULL; } memcpy(out->bytes, byteaddress, size); + out->bsize = size; if(!bytes_to_string(&out->string,byteaddress,size)==1) { multiaddress_free(out); diff --git a/protoutils.c b/protoutils.c index c414d85..33c65dc 100644 --- a/protoutils.c +++ b/protoutils.c @@ -290,20 +290,26 @@ char * int2ip(int inputintip) sprintf(xxx_int2ip_result, "%d.%d.%d.%d", ipint0,ipint1,ipint2,ipint3); return xxx_int2ip_result; } -//I didn't feel another address_bytes_to_string was necesarry sry guys -int bytes_to_string(char** buffer, const uint8_t* catx, int xbsize) + +/** + * Unserialize the bytes into a string + * @param results where to put the resultant string + * @param in_bytes the bytes to unserialize + * @param in_bytes_size the length of the bytes array + */ +int bytes_to_string(char** buffer, const uint8_t* in_bytes, int in_bytes_size) { *buffer = malloc(800); char* resultzx = *buffer; bzero(resultzx, 800); uint8_t * bytes = NULL; int size = 0; - size = xbsize; + size = in_bytes_size; struct ProtocolListItem* head = NULL; load_protocols(&head); - char hex[xbsize*2]; - bzero(hex,xbsize*2); - strcat(hex,Var_To_Hex(size, catx)); + char hex[in_bytes_size*2]; + bzero(hex,in_bytes_size*2); + strcat(hex,Var_To_Hex(size, in_bytes)); //Positioning for memory jump: int lastpos = 0; char pid[3];