warning sprintf

This commit is contained in:
gonzalef 2020-04-28 19:02:02 +02:00
parent 27d38c3fe5
commit 897550a0ac
4 changed files with 10 additions and 10 deletions

BIN
src/debug.o Normal file

Binary file not shown.

BIN
src/hash.o Normal file

Binary file not shown.

View File

@ -464,7 +464,8 @@ int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, in
((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, .iov_base = packet_buff};
int error_while_sending = 0;
@ -472,7 +473,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.
};
@ -802,7 +803,6 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
new_neighbour.sin6_scope_id = ifindex;
// Build network hash
// memset(&new_tlv,0,sizeof(struct network_hash));
build_network_hash(&new_tlv, data_list);
send_single_tlv(&new_tlv, &new_neighbour, socket_num);
@ -820,13 +820,13 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
if (DEBUG_LEVEL > 1) {
printf("\x1b[31m[DEBUG]\x1b[0m >> Our hash : ");
for(int x = 0; x < 16; x++){
for(int x = 0; x < SHA256_DIGEST_LENGTH; x++){
printf("%02x", hash[x]);
fflush(0);
}
printf("\n");
printf("\x1b[31m[DEBUG]\x1b[0m >> Received : ");
for(int x = 0; x < 16; x++){
for(int x = 0; x < SHA256_DIGEST_LENGTH; x++){
printf("%02x", cur_tlv.network_hash->network_hash[x]);
fflush(0);
}
@ -924,7 +924,7 @@ int work_with_tlvs(char * data, int16_t total_packet_len, struct sockaddr_in6 *s
print_debug(">> Received message ! ");
if (DEBUG_LEVEL > 0) {
printf("\nID : %li \nSeqno : %i\n “%s” \n", cur_tlv.node_state->node_id, cur_tlv.node_state->seqno, (char *) cur_tlv.node_state->data);
printf("\n\t %s \n", (char *) cur_tlv.node_state->data);
}
add_data(cur_tlv.node_state->length - 26, cur_tlv.node_state->node_id, cur_tlv.node_state->seqno, cur_tlv.node_state->data);
@ -939,7 +939,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
@ -1049,7 +1049,7 @@ int run_node(int sock_fd){
t_ask_for_more_peers(sock_fd);
t_update_neighbours();
t_get_network_state(sock_fd);
delay = time(NULL) + 20 + (rand() % 5);
delay = time(NULL) + 20 + (rand() % 10);
}
// This might be cool to add, but we need to find a way to write to stdin

View File

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