From 897550a0acafed8b5b9d73f1722b1cbc095e3b71 Mon Sep 17 00:00:00 2001 From: gonzalef Date: Tue, 28 Apr 2020 19:02:02 +0200 Subject: [PATCH] warning sprintf --- src/debug.o | Bin 0 -> 1584 bytes src/hash.o | Bin 0 -> 2584 bytes src/node.c | 18 +++++++++--------- src/tlv.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 src/debug.o create mode 100644 src/hash.o diff --git a/src/debug.o b/src/debug.o new file mode 100644 index 0000000000000000000000000000000000000000..f402994105591610dd5628c2fc860deaac488e3e GIT binary patch literal 1584 zcmbtUL2DCH5T0$+wi=}tkzzdTMNzSjU2CxjmTh8^3X2781PS`sq+28HCS~^ps)u^j zgWyU0H+uB1c+;y0b>`&_Szk6Dbi(e;d~d#a^Jd=WO+9SPI1aElunuF7QGo9=V>{4h z0B4~Lo9|c2+kE%a|MHoL-^i`BSNx=Xzg}%MpHId2=k+6S4i}tCd3Npt<|q8JUIDmh^xqVfbOL@H7sZqc zPYO`NUy+nBQ<0S5WD$&6W~bnD6ZpJFrsX*`5q}Pm#a#W|i%WE z3nHv}aFD+2E2$xn&2X!_5z4Jb<8ggkZf{h>x&$e8%&zSA_GlaK6kQKG)vx1`EYczh zb*zjJ<1X4H6ra0N03v&psHlTlr6b*AD~x_cN$?6@a)(L+m3y1_~);Z}t?Tlac`Oo805&x|zsyC);%jW+E%o}ct literal 0 HcmV?d00001 diff --git a/src/hash.o b/src/hash.o new file mode 100644 index 0000000000000000000000000000000000000000..9de82471d9309121a76665a50f123532c62eb3f9 GIT binary patch literal 2584 zcmbtU&2Jk;6d$i$$2jS((<0%jNb#XTF=|&fZJ{a>c$3(kpj9Ign}XV~IF600_(QVS zkfN#}xv5w!L0sTJ;KqSd!T}_w2~v9Dh$?!CkV+Fks8vK{MAY)$?o2W=4npv(o%iN9 zzxOe3X8e9qPe~pR;o>1Lk^LD*2?_V@+X=@^kO9(9wv}3+GU#7bhHf}0wbKE8F%_hi zUs+CvidHJ1EGg8!7;gO$XdK&F@ip~@+h)JAB<-w7AEtuM>^3+PYD?5g1+8^zUz0i$ z)-}?hi`S3P*8R>zw4+CFjeAz8_5I40cbk5`T2y&HTXMYYjI^s+8L|tpKEOh(b!9mt zJt`vjNZ@Cwb#IDV+qCuTxmjxahDU%*t>k9Btt|EFi!?}E?PJ3aynsg6sP)q(Mx%?_ zwr+h#t^3ZjsML~eY9}{m>1j8DGU#pksXg7fy~-G@AKGhLcEZ}xGFiy_CuEHYS;tR| z#M=&kWy44F9XHp)-3e>WeCL}GB%ZMD6_ufJsK9YcU{Qn$|9B)7qO`xWD~=#&;m)FUw9MWhjB? z>sJPSPpy*l*x32VNOq=KHJgza)U#^r)aj-(i(ikQQ)6eME{gF8dD2zH^WLk(GavFC zALt8w0v8K6^)y=xFpXG@*`F~T0S()BfWqG|mJfJ?Xr@-+^l za_D1eR1PnClXB!EpC*soJfz97mOm}OCEWfyaU%5dyC3h(z2 z*vS9VK?!ks4t5ki&SguEdiel6bpU=5aEu>ee=g2>0XBO8zj6R>9)Mp39OG}W_z#DDW(p7fK^P;s7GShqdiK zcI6?0Ab1l7;N$pFwhzP)3;39TD*}E&!126zoEpP1Z&1KL75HM_I|44|y(Qp-LYxTL zC>S3x8&i?+! zj>7_;eS#C1F0rS6ht2UWVJQB-!wi3h;obi{QSp!%7gbj|7iCQ_&VW&M-PznlI#1KMIxuzCMD{0bPo`k!D2I?ssMfBaYG{=EOVkM7*) v5@rouXB)*giN4+b7`MCk0FezW3S_}mdn4}~2k?#d^8bp}{{|;A-R=Ju5(aYf literal 0 HcmV?d00001 diff --git a/src/node.c b/src/node.c index ef470d7..6dbea63 100644 --- a/src/node.c +++ b/src/node.c @@ -461,10 +461,11 @@ 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, .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 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;