big endian/little endian conversions

This commit is contained in:
gonzalef 2020-04-28 20:22:53 +02:00
parent fae758e4dd
commit 904f0fcc79
2 changed files with 10 additions and 10 deletions

View File

@ -836,7 +836,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
@ -907,7 +907,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) {
@ -926,7 +926,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
@ -940,7 +940,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);
@ -963,7 +963,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 !");
}

View File

@ -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};