Fixing unintialized values
This commit is contained in:
parent
c19f5e7c3c
commit
f9c1cda499
57
src/node.c
57
src/node.c
@ -1126,13 +1126,64 @@ int t_ask_for_more_peers(int sock_fd){
|
|||||||
return ask_for_peers(sock_fd);
|
return ask_for_peers(sock_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* For every peer we know about, we send out a TLV network hash
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
int t_get_network_state(int sock_fd){
|
int t_get_network_state(int sock_fd){
|
||||||
print_debug(">> Getting network state...");
|
print_debug(">> Getting network state...");
|
||||||
|
print_debug(">> Sending out a TLV network hash to every peer we know of.");
|
||||||
|
if (neighbour_list == NULL) {
|
||||||
|
print_error("Our peer list is empty !");
|
||||||
|
print_error("Skipping..");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
// Build the network hash
|
||||||
|
// We use another variable so that we don't interfier with the current list
|
||||||
|
list * tmp_list = neighbour_list;
|
||||||
|
while (tmp_list != NULL) {
|
||||||
|
|
||||||
|
neighbour_peer * peer = (neighbour_peer *) tmp_list->data;
|
||||||
|
tlv * new_tlv = malloc(sizeof(union tlv));
|
||||||
|
memset(new_tlv, 0, sizeof(union tlv));
|
||||||
|
if (new_tlv == NULL) {
|
||||||
|
print_error("Error while allocating memory for the TLV !");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the structure for the receiver.
|
||||||
|
struct sockaddr_in6 * receiver = malloc(sizeof(struct sockaddr_in6));
|
||||||
|
memset(receiver, 0, sizeof(struct sockaddr_in6));
|
||||||
|
if (receiver == NULL) {
|
||||||
|
print_error("Error while allocating memory for the peer address!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
receiver->sin6_family = AF_INET6;
|
||||||
|
receiver->sin6_addr = peer->ip;
|
||||||
|
receiver->sin6_port = htons(peer->port);
|
||||||
|
receiver->sin6_scope_id = 0;
|
||||||
|
|
||||||
|
// Send out a TLV network state.
|
||||||
|
list * tmp_data_list = data_list;
|
||||||
|
|
||||||
|
if (build_network_hash(new_tlv, tmp_data_list) < 0) {
|
||||||
|
print_error("Error while building a network hash.");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if (send_single_tlv(new_tlv, receiver, sock_fd) < 0) {
|
||||||
|
print_error("Error while sending a network hash to a peer.");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
print_debug(">> Sent network hash to a peer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(new_tlv);
|
||||||
|
free(receiver);
|
||||||
|
if (tmp_list->next == NULL) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
tmp_list = tmp_list->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/tlv.c
13
src/tlv.c
@ -33,6 +33,7 @@ int build_pad1(tlv *tlv) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
pad1 *new = (pad1*) malloc(sizeof(pad1));
|
pad1 *new = (pad1*) malloc(sizeof(pad1));
|
||||||
|
memset(new, 0, sizeof(pad1));
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -49,6 +50,7 @@ int build_padn(tlv *tlv, size_t len) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
padn *new = (padn*) malloc(sizeof(padn));
|
padn *new = (padn*) malloc(sizeof(padn));
|
||||||
|
memset(new, 0, sizeof(padn));
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -67,6 +69,7 @@ int build_neighbour_req(tlv *tlv) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
neighbour_req *new = (neighbour_req*) malloc(sizeof(neighbour_req));
|
neighbour_req *new = (neighbour_req*) malloc(sizeof(neighbour_req));
|
||||||
|
memset(new, 0, sizeof(neighbour_req));
|
||||||
|
|
||||||
if(new == NULL){
|
if(new == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
@ -89,6 +92,7 @@ int build_neighbour(tlv *tlv, struct in6_addr ip, int16_t port) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
neighbour *new = (neighbour*) malloc(sizeof(neighbour));
|
neighbour *new = (neighbour*) malloc(sizeof(neighbour));
|
||||||
|
memset(new, 0, sizeof(neighbour));
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -108,6 +112,7 @@ int build_network_hash(tlv *tlv, list *data_list) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
network_hash *new = (network_hash*) malloc(sizeof(network_hash));
|
network_hash *new = (network_hash*) malloc(sizeof(network_hash));
|
||||||
|
memset(new, 0, sizeof(network_hash));
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -126,6 +131,7 @@ int build_network_state_req(tlv *tlv) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
network_state_req *new = (network_state_req*) malloc(sizeof(network_state_req));
|
network_state_req *new = (network_state_req*) malloc(sizeof(network_state_req));
|
||||||
|
memset(new,0,sizeof(network_state_req));
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -143,6 +149,7 @@ int build_node_hash(tlv *tlv, int64_t node_id, int16_t seqno, char *data) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
node_hash *new = (node_hash*) malloc(sizeof(node_hash));
|
node_hash *new = (node_hash*) malloc(sizeof(node_hash));
|
||||||
|
memset(new,0,sizeof(node_hash));
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -165,6 +172,8 @@ int build_node_state_req(tlv *tlv, int64_t node_id) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
node_state_req *new = (node_state_req*) malloc(sizeof(node_state_req));
|
node_state_req *new = (node_state_req*) malloc(sizeof(node_state_req));
|
||||||
|
memset(new, 0, sizeof(node_state_req));
|
||||||
|
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -183,6 +192,8 @@ int build_node_state(tlv *tlv, int64_t node_id, int16_t seqno, char *data, size_
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
node_state *new = (node_state*) malloc(sizeof(node_state));
|
node_state *new = (node_state*) malloc(sizeof(node_state));
|
||||||
|
memset(new, 0, sizeof(node_state));
|
||||||
|
|
||||||
int len = data_len + 26;
|
int len = data_len + 26;
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
@ -213,6 +224,8 @@ int build_warning(tlv *tlv, char *message, size_t message_len) {
|
|||||||
free(tlv->pad1);
|
free(tlv->pad1);
|
||||||
|
|
||||||
warning *new = (warning*) malloc(sizeof(warning));
|
warning *new = (warning*) malloc(sizeof(warning));
|
||||||
|
memset(new, 0, sizeof(warning));
|
||||||
|
|
||||||
int len = message_len;
|
int len = message_len;
|
||||||
|
|
||||||
if(new == NULL)
|
if(new == NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user