diff --git a/src/node.c b/src/node.c index b71cf1e..41e648c 100644 --- a/src/node.c +++ b/src/node.c @@ -835,7 +835,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s memset(&new_neighbour, 0, sizeof(new_neighbour)); new_neighbour.sin6_family = AF_INET6; memcpy(&new_neighbour.sin6_addr, &cur_tlv.neighbour->ip, 16); - new_neighbour.sin6_port = htons(LISTEN_PORT); + new_neighbour.sin6_port = ntohs(cur_tlv.neighbour->port); new_neighbour.sin6_scope_id = ifindex; // Build network hash @@ -906,7 +906,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s //if the hashes are identical nothing has to be done print_debug(">> Received node hash, updating message entry..."); cur_tlv.node_hash = (node_hash*) (data + pos); - pdata = get_data(cur_tlv.node_hash->node_id); + pdata = get_data(ntohl(cur_tlv.node_hash->node_id)); // If data is found for this id then we check that both hashes are the same if(pdata != NULL) { @@ -925,7 +925,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s } // If no pub_data was found or the hashes differ then we send a node state request - build_node_state_req(&new_tlv, cur_tlv.node_hash->node_id); + build_node_state_req(&new_tlv, ntohl(cur_tlv.node_hash->node_id)); add_tlv(&pack, &new_tlv, sender, socket_num); // The position is updated @@ -939,7 +939,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s // if no pub_data exists for this id nothing is sent print_debug(">> Received node state request. Processing..."); cur_tlv.node_state_req = (node_state_req*) (data + pos); - pdata = get_data(cur_tlv.node_state_req->node_id); + pdata = get_data(ntohl(cur_tlv.node_state_req->node_id)); if(pdata != NULL) { build_node_state(&new_tlv, pdata->id, pdata->seqno, pdata->data, pdata->length); @@ -962,7 +962,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s if (DEBUG_LEVEL > 0) { printf("\n\t %s \n", (char *) cur_tlv.node_state->data); } - int rc = add_data(cur_tlv.node_state->length - 26, cur_tlv.node_state->node_id, cur_tlv.node_state->seqno, cur_tlv.node_state->data); + int rc = add_data(cur_tlv.node_state->length - 26, ntohl(cur_tlv.node_state->node_id), ntohs(cur_tlv.node_state->seqno), cur_tlv.node_state->data); if (rc < 0) { print_debug(">> Error while adding note state !"); } diff --git a/src/tlv.c b/src/tlv.c index 140a9fb..70207a7 100644 --- a/src/tlv.c +++ b/src/tlv.c @@ -145,8 +145,8 @@ int build_node_hash(tlv *tlv, int64_t node_id, int16_t seqno, char *data) { new->type = 6; new->length = 26; - new->node_id = node_id; - new->seqno = seqno; + new->node_id = htonl(node_id); + new->seqno = htons(seqno); pub_data pdata = (pub_data) {.id = node_id, .seqno = seqno, .data = data}; hash_data(&pdata, (unsigned char*) new->node_hash); @@ -167,7 +167,7 @@ int build_node_state_req(tlv *tlv, int64_t node_id) { new->type = 7; new->length = 8; - new->node_id = node_id; + new->node_id = htonl(node_id); tlv->node_state_req = new; @@ -192,8 +192,8 @@ int build_node_state(tlv *tlv, int64_t node_id, int16_t seqno, char *data, size_ new->type = 8; new->length = 26 + len; - new->node_id = node_id; - new->seqno = seqno; + new->node_id = htonl(node_id); + new->seqno = htons(seqno); memcpy(new->data, data, len); pub_data pdata = (pub_data) {.id = node_id, .seqno = seqno, .data = data};