diff --git a/src/hash.c b/src/hash.c index 44e3827..a205bad 100644 --- a/src/hash.c +++ b/src/hash.c @@ -17,7 +17,10 @@ void hash_data(pub_data *data, unsigned char *buf) { // Hash every data contained in data_list then return a network hash void hash_network(list *data_list, unsigned char *buf) { - unsigned char *concat = (unsigned char*) malloc(0); + // Get list length to initialize concat buffer + int concat_len = len_list(data_list) * 16; + unsigned char *concat = (unsigned char*) malloc(concat_len); + unsigned char hash[SHA256_DIGEST_LENGTH]; int totlen = 0; list *tmp = data_list; @@ -55,6 +58,5 @@ void concat_data(pub_data *data, unsigned char *buf) { // Concat hash2 to hash1 (hash1 is modified) void concat_hash(unsigned char *hash1, unsigned char *hash2, size_t size) { - hash1 = (unsigned char*) realloc(hash1, size + 16); memcpy(hash1+size, hash2, 16); } diff --git a/src/node.c b/src/node.c index 6aacb35..7c8594f 100644 --- a/src/node.c +++ b/src/node.c @@ -192,7 +192,7 @@ pub_data *get_data(int64_t id) { while(tmp != NULL) { data = (pub_data*) tmp->data; - + tmp = tmp->next; if(data->id == id) return data; } @@ -484,10 +484,12 @@ int add_tlv(packet *pack, tlv *tlv, struct sockaddr_in6 *dest, int socket_num) { // Send length bytes from packet int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, int socket_num) { - ((packet*) packet_buff)->length = htons(((packet*) packet_buff)->length); + ((packet*) packet_buff)->length = htons(((packet*) packet_buff)->length); // Vectorized buffer - struct iovec vec_buff = {.iov_len = length + 4, .iov_base = packet_buff}; + struct iovec vec_buff[1]; + vec_buff[0].iov_len = length + 4; + vec_buff[0].iov_base = packet_buff; int error_while_sending = 0; @@ -495,7 +497,7 @@ int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, in struct msghdr packet_tlv_send_out = { .msg_name = dest, .msg_namelen = sizeof(struct sockaddr_in6), - .msg_iov = &vec_buff, + .msg_iov = vec_buff, .msg_iovlen = 1 // We have only one iovec buffer. But if we had 2, we would write 2. }; @@ -970,7 +972,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s cur_tlv.warning = (warning*) (data + pos); // Print exactly new_tlv.length characters from new_tlv.message - sprintf(warn, "\x1b[31m>> WARNING:\n%%.%ds \x1b[0m", cur_tlv.warning->length + 1); + sprintf(warn, ">> WARNING:\n%%.%ds", cur_tlv.warning->length + 1); printf(warn, cur_tlv.warning->message); // The position is updated diff --git a/src/tlv.c b/src/tlv.c index 82de813..140a9fb 100644 --- a/src/tlv.c +++ b/src/tlv.c @@ -92,7 +92,7 @@ int build_neighbour(tlv *tlv, struct in6_addr ip, int16_t port) { new->type = 3; new->length = 18; new->ip = ip; - new->port = port; + new->port = htons(port); tlv->neighbour = new;