From 08ea46ca340d397d03a5d45e6cc1601c00c066bc Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 5 Feb 2017 15:31:44 +0100 Subject: [PATCH] Fixed reference buffer in `xlisten` with `realloc` instead of `malloc` --- client | Bin 17792 -> 17680 bytes client.c | 46 +++++++++++++++++++--------------------------- client.o | Bin 6112 -> 5608 bytes lib.c | 30 ++++++++++++++++-------------- lib.h | 6 +++--- lib.o | Bin 10664 -> 10712 bytes makefile | 2 +- server | Bin 18096 -> 17816 bytes server.c | 51 ++++++++++++++++----------------------------------- server.o | Bin 6752 -> 5744 bytes 10 files changed, 55 insertions(+), 80 deletions(-) diff --git a/client b/client index 3975bb06775fa62567ef37e75591e62d70829451..7d4df29cb07b801de1cd5f8a381ba01f577e7763 100755 GIT binary patch delta 6080 zcmZu#4OCRuoxktR4D;p#m>CcTwK5oph~hv@fa4cKV3J1?TNG_fqCwDLAW45mO|7vth+yvA4sxb!NSZF_{hbzH4}2@*Q?_CelSS~T9cD$pUnxcem=pGp=p$t9h_*4&igg2AY#8?O=f9%qGeNex0zHu!rJ@GF~OZLPU;Gc!jW)uuI^d6UHR637fz#5so9w1b%^V zJmIU~fynrK!Zi02V*>9aOb^P$h`>#R9fSvbf_Od2#cKD05GD72O8sXZSN#{%j`6Ey zYf1+PTs99=2T%6IQ!}_J&clMq2y~-1KDC6gzCo{;hQ>p!T--be8jrvcio!(K^KN$QCcbQX???%2Nf#7k-KZ^@2LX_YZUS?kA zTLxL6993{V9Cfr!hFVhsk31CQZrVsKb&*IDACv8^(H260IStaBc2M8%o$UWb)LRm~shB%<+uWI>-u&e4x6v@y{!e%t z74xV1eS^V6Q0+ev^*4xoX$flw#cYmiv-uj#{BH~1UnZlS?DQn6RU_0>J3UUdlc}96 zN7as#dewhg^}ipSfJI;=8h0mPr}xIKDf72oQT?s_h;^<{xWO~?5e@MjO3?2e?f;lk z3Ze=oBPE)Em(|^6lDfO?DngB^ovou->{9>NrT(Gg7$k%7c1qKGqoW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NWimkZ(iD$&nLR)3W&Y|--gEjD&4`N zU$5p4GO#2z=-}_<{a8B6>+)0hllkvv_!~KB;g<>? zLf)LmqDftULoxOXUQm$c_$5XWH+ppJJi8z><39v7iB&mowsD0YxI0gp;r(}~m7B36 zC6>yTEU1O_jbaC#vX}i9`W=G)`3bJzj%8^D_k)`R@9_mjsKR~{r8+{t^&<50g5_z_ zV|?$jw7Mn;yI2N08ae)vq3r3%SaD5*7`>(YK(|AlzQ4>Z4+!~0ymH-h$?QjDD}(YR zd3fss;)L+zqNuNmn(>p6cfu=@zv;4s-uc9p@Vmq6Ca@wDCv=JwUL?9eM99vp?R9>I$1<%9%Bn@ z1ut4PN5)1!&*nrJX5=C}cG9g;b%IW|qA6i7^ioOZB`eaT98s?kH9n|<;-!AZK8&Jy z-KwpNWHNp$eE9s)e3navXTKQ9BDu@&E?RNp+|NlA;H)Sb_;ul(@<8g!d*y+OFS#UX zobO$o=jb)Mg?GJ?Pz8BEsEv_-Z^Xw?@R#uE)p?fg2(_DMuPL+yBPht5))dD6Aqpu% z9XrPR*W_8Esic=rLMEC(M$EcQJ})TFvregQ0jE^Hy?BKs8fL~{E-ti2wug8CU+sPb=wDyxjQAKkAk)MZXVezM|soQV#}aQAMED+ zYYU}8KDoA7y2`Uli>>!B)HxL<-cq{4(zjTLZ}R@qLd&*n9i{SVpvUPIg)+$t$_nvH j;oHmBq%`L0#B}-wjB*ElMf^nBQcGu{Ah3QuU6%QOre`px diff --git a/client.c b/client.c index 9ef5caf..e110ecc 100644 --- a/client.c +++ b/client.c @@ -7,26 +7,20 @@ int main(int argc, char* argv[]){ /* [1] Initialisation =========================================================*/ /* (1) Socket information */ - // Server socket address - static struct sockaddr_in server_addr; - // Local socket - int sock; + struct sockaddr_in server_addr; // server info + int sock; // socket /* (2) Misc. information */ - // Response - char *msg = "some message\0"; - // Reception buffer - char buffer[BUFSIZE] = {'\0'}; - // Will contain the response - char *response; - // Will contain the length of received/sent data - int nb_bytes; + int bytes; // transfer count + char* to_send = (char*) malloc( BUFSIZE * sizeof(char) ); + char* to_recv = (char*) malloc( BUFSIZE * sizeof(char) ); + - /* [2] UPD socket creation + /* [2] Create UPD socket and get target data =========================================================*/ - sock = xconnect("localhost", 4000, (struct sockaddr*) &server_addr); + sock = xconnect("localhost", 4000, &server_addr); /* (1-) Manage error */ if( sock == -1 ){ @@ -37,37 +31,35 @@ int main(int argc, char* argv[]){ /* [3] Send message =========================================================*/ - /* (1) Send message to server */ - nb_bytes = xsend(sock, msg, (struct sockaddr*) &server_addr); + /* (1) Set message to send */ + strcpy(to_send, "client message"); - /* (2) Check if send succesfully */ - if( nb_bytes == -1 ){ + /* (2) Send message to server */ + bytes = xsend(sock, to_send, &server_addr); + + /* (3) Check if send succesfully */ + if( bytes == -1 ){ perror("erreur envoi message"); exit(1); } - // log - printf("paquet envoyé, nb_bytes = %d\n",nb_bytes); + DEBUG&& printf("*** sent %d bytes\n", bytes); /* [4] Wait for response =========================================================*/ /* (1) Wait for response */ - nb_bytes = xlisten(sock, (struct sockaddr*) &server_addr, buffer, BUFSIZE); + bytes = xlisten(sock, &server_addr, to_recv, BUFSIZE); /* (2) Check if received successfully (and consistently) */ - if( nb_bytes == -1 ){ + if( bytes == -1 ){ perror("erreur réponse serveur"); exit(1); } - /* (3) Copy response into var */ - response = (char*) malloc(nb_bytes * sizeof(char)); - memcpy(response, buffer, nb_bytes); - /* (4) log */ - printf("response recue du serveur : %s\n",response); + printf("*** received : '%s'\n", to_recv); /* [5] Close socket diff --git a/client.o b/client.o index d7c42baf0d41ee0e3ea146b82e4cc61efe4bd261..d109e27dfac1b55683f2ec8783cdd235b62ceee2 100644 GIT binary patch literal 5608 zcmbtYZ-^Vm6`$4WZ25FP-}!7eu0yjizBq9r>13a;wu2qTmy6|)7L#(gEe&EN?MaKJ zU3GVL)|p-ny~d3=LURf95482Akl?hXO-Tz5P2-S2&Mj_nKgC}P{@_AB6xy^93=X*O z&Aidg%}G$&2fH)x_kQoqo3}f&Bb}dm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(3) Copy server address */ - memcpy( &serv_in->sin_addr.s_addr, host->h_addr, host->h_length); + memcpy( &serv->sin_addr.s_addr, host->h_addr, host->h_length); DEBUG&& printf("built\n"); @@ -148,17 +146,17 @@ int xconnect(const char* hostname, const int port, struct sockaddr* serv){ -int xlisten(const int xsocket, const struct sockaddr *client, char* buffer, int bufsize){ +int xlisten(const int xsocket, struct sockaddr_in *client, char* buffer, int bufsize){ /* [1] Wait for message through xsocket =========================================================*/ /* (1) Useful data + memory allocation */ socklen_t sock_len = sizeof(struct sockaddr_in); - buffer = (char*) malloc( sizeof(char) * bufsize ); + buffer = (char*) realloc(buffer, sizeof(char) * bufsize ); /* (2) Listen */ DEBUG&& debug("xlisten", "waiting for data"); - int read = recvfrom(xsocket, buffer, bufsize, 0, (struct sockaddr *) client, &sock_len); + int read = recvfrom(xsocket, buffer, bufsize / sizeof(char) + sizeof(char), 0, (struct sockaddr*) client, &sock_len); /* (3) Manage error */ if( read == -1 ){ @@ -168,8 +166,9 @@ int xlisten(const int xsocket, const struct sockaddr *client, char* buffer, int DEBUG&& printf("received\n"); - - + printf("[xlisten:received] '%s'\n", buffer); + + /* [2] Return number of read characters =========================================================*/ return read; @@ -180,16 +179,16 @@ int xlisten(const int xsocket, const struct sockaddr *client, char* buffer, int -int xsend(const int xsocket, char* buffer, struct sockaddr* target){ +int xsend(const int xsocket, char* buffer, struct sockaddr_in* target){ /* [1] Send buffer (message) to target =========================================================*/ /* (1) Useful data */ - socklen_t addr_len = sizeof(struct sockaddr_in); + size_t addr_len = sizeof(struct sockaddr_in); /* (2) Send data */ DEBUG&& debug("xsend", "sending data"); - int sent = sendto(xsocket, buffer, strlen(buffer), 0, target, addr_len); + int sent = sendto(xsocket, buffer, strlen(buffer)+1, 0, (struct sockaddr*) target, addr_len); /* (3) Manage error */ if( sent == -1 ){ @@ -200,6 +199,9 @@ int xsend(const int xsocket, char* buffer, struct sockaddr* target){ DEBUG&& printf("sent\n"); + printf("[xsend:sent] '%s'\n", buffer); + + /* [2] Return number of sent characters =========================================================*/ return sent; diff --git a/lib.h b/lib.h index 2265e30..cca2bff 100644 --- a/lib.h +++ b/lib.h @@ -31,7 +31,7 @@ int debug(const char* tag, const char* msg); int xbind(const int port); - int xconnect(const char* hostname, const int port, struct sockaddr* serv); - int xlisten(const int xsocket, const struct sockaddr *client, char* buffer, int bufsize); - int xsend(const int xsocket, char* buffer, struct sockaddr* target); + int xconnect(const char* hostname, const int port, struct sockaddr_in* serv); + int xlisten(const int xsocket, struct sockaddr_in *client, char* buffer, int bufsize); + int xsend(const int xsocket, char* buffer, struct sockaddr_in* target); #endif diff --git a/lib.o b/lib.o index 78eba4dc1f289a5aff6187f9e1a137fc384b6287..aa27e385f10ad14b8f72de55e2b2fe85565767e6 100644 GIT binary patch literal 10712 zcmbtadvKK16~FsPvLqygmxchLQ7!~4?3rE_`ve_&qiwUANkUO$E&^J^Y z$n_2ca@hlce*b|$Zr>nsz8uKC4KmpqEP8XjL$BemH=R)J!AdH~`G?;`Sn8EXU+?gl z>=eV!?lVx1J;}ro2i~k^Ob(9jD?x2e(eED`_v&7nNi-+X5gSVG_Yc2@!=(d6&G}D{ z^5^uK>^X(}`Fw(bg2LbMgc~5lgSqVCK(2M5@WfAzGIXlg#Q)5b9GN(*#~`m%V007% z5JpiXjJbl^24pB%rQsW{esrIV>*0~O=H8NcZlx2R!~M;Z0%6=I!-4+hnn1q@^sg8Q z^!?fm+a{2EU#`!nfSno%80-+(l7}#0xfO$vK)-uNEqIEPYuvlf{{=1;PFmW4z4#&f z3XB26U*tU!xM!s!a8K_S;K!jre|7-&#M0bXOLO~w37SNH!B6$|Lf{LpaIN7m&Uf@% z(CUq-opxUcu{|KK{PHecX=|6zDh7r={(FZzO03MRy{e zv8|*?TVX4{(SqS?30la|I`6C*nOWr`V<~6VIFt|qrE9xUScn31Yu!S?KPVn~!j6?~ zt(vNOC4$G9a1Jbh+T|%j!R7GChf_&z0!tMrk0ZCcB%ZWkfRt!liKkbNmPD!6^~M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Q4 zufd;6@+JdcP5h?~9N(v~@H*o0^83Ip;-ee-`Swji&m5^mi1#!;R{1^i6N7&{@lP2z z`#)OC7Z@AfPp23-kLzLs=W)$4aNfuD{EPaZAU~E8pT~NUr)>jFjifR9Hz)`2!zm58{9oEC^kmY8mpiX^_VH@}V00pg>_Hkb`F{Gbg zr8+G##$j@=09v{D2@EWh6I%Rmj?DNi0nF5i{gQO(t~VMDQQTUge-CaDPRM&GkEz z`tM{S-Ff^BZ-Gj=__a~|_`Lz+htCf8=jRIZgb^Y@;6ENx|L3GMeBp63g0ks5whfa1 bVN#BNCn{$j*Hk(CP3SO`XVtBAHSPZg3ceTZ diff --git a/makefile b/makefile index 0a49cce..7ca2720 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -CC=-Wall -Werror -g +CC=-Werror -g client.o: client.h client.c diff --git a/server b/server index 8bcf89c3fd626a37309c2b6c27a7a9cd294e6695..f6d3c2608e3c42eb8be24bded054622fb31d4b28 100755 GIT binary patch delta 4784 zcmZ8l2~d>R9e?lJUG`gcId%bA)NmvocyV|D@raAM`eEV}qfDqr0AayZ1jB-260){b z>&})aeX%hKooJdkX=6JkWE2w>jE<0_3EIYJbsEyax+a-KjZM+Cp}+t87Mk$J{om*N z-i3!-_`V?DldkNW+dBE6WlcPjV@>O&T%}JD4!+Y~?9gS!4woc~#qas$_~6kK&uz>+ ze)r&+G21UKnf1iz{NyLaK4m>$Be-D+FB0dJL{VyRiaiD=7sT=X67CRb#xXoqoa1qP zy_D2S+wDfD&|v$9l$DF+#!S9NY7QHlM%Q`Ds;g_u+2%TLO?@Tv)z?*fYS=n&O@&xy zdi~cC&a`e67mHuK*Bix{ft?TY4Wqpl#uRp?{r-q#Wy~vysZ86^Rc{LUIAdD#8TGX6 z3ZQ+1`Wwz~we!d~IKM95w7U2%@h@wEUu*s{OA9oG0uB9Ipy=XT=*xPO#|#l;qHDn6fQvFRt|^z3<`w1c#>v=V(v%GldFg0b)#I; zS9W7og6{s9qg^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Q7eyo7 zgf!8eS>Ni7T>Ds$_rkwrp}Br|c8uvKqM5@+b-)FX;?Pt0jF{ zA1qA#4iJ86|avQVR)^k(km{GD>M>6CQ3y9J%vUh+i9_-_e|nS1s9{o zW{GyM!$_R)0&&q>Xf(&qdvh$m$fj_w7**V+?6Zn%#UqUV1I)R;Cq_*uG)~=Rjyz(; ygu*1tAajKOo$Z=1Liybo@%@Bx>3W_iEi+8s4{W6H`35Fck2EEhRdH=h)_(!nbKrIW diff --git a/server.c b/server.c index c4f0c3f..916f900 100644 --- a/server.c +++ b/server.c @@ -8,23 +8,16 @@ int main(int argc, char* argv[]){ =========================================================*/ /* (1) Socket info */ // Client - static struct sockaddr_in addr_client; - // Client identifier - struct hostent *host_client = NULL; + struct sockaddr_in addr_client; char client_ip[20]; // Socket int sock; /* (2) Misc. information */ - // response - char *response = "bien recu"; - // reception buffer - char buffer[BUFSIZE]; - // received buffer - char *received; - // length of received/sent data - int buf_len; + char* to_send = (char*) malloc( BUFSIZE * sizeof(char) ); + char* to_recv = (char*) malloc( BUFSIZE * sizeof(char) ); + int bytes; // transfer count @@ -42,11 +35,12 @@ int main(int argc, char* argv[]){ /* [3] Wait for client message =========================================================*/ - buf_len = xlisten(sock, (struct sockaddr*) &addr_client, buffer, BUFSIZE); + /* (1) Listen to data */ + bytes = xlisten(sock, &addr_client, to_recv, BUFSIZE); - /* (1-) Manage error */ - if( buf_len == -1 ){ + /* (2) Manage error */ + if( bytes == -1 ){ perror("erreur réception paquet"); exit(1); } @@ -54,31 +48,18 @@ int main(int argc, char* argv[]){ // Get client ip inet_ntop(AF_INET, &(addr_client.sin_addr), client_ip, 20); - /* (2) Fetch client information */ - // récupère nom de la machine émettrice des données - host_client = gethostbyaddr( &addr_client.sin_addr, // ) client addr (filled) - /* ( */ sizeof(struct in_addr), // ) sizeof addr - /* ( */ AF_INET ); // ipv4 - - /* (2-) Manage error */ - if( host_client == NULL ){ - perror("erreur gethostbyaddr"); - exit(1); - } - - /* (3) Store message */ - received = (char *) malloc(buf_len * sizeof(char)); - memcpy(received, buffer, buf_len); - - printf( "recu message %s de %s:%d\n", received, client_ip, ntohs(addr_client.sin_port) ); + printf("*** received '%s' (%d bytes) from %s:%d\n", to_recv, bytes, client_ip, ntohs(addr_client.sin_port)); /* [4] Send response =========================================================*/ - /* (1) Send response */ - xsend(sock, response, (struct sockaddr*)&addr_client); + /* (1) Set response data */ + strcpy(to_send, "server response"); + + /* (2) Send response */ + bytes = xsend(sock, to_send, &addr_client); - /* (1-) Manage error */ - if( buf_len == -1 ){ + /* (3) Manage error */ + if( bytes == -1 ){ perror("erreur envoi réponse"); exit(1); } diff --git a/server.o b/server.o index dca7da1715ae829e54300a2c4674de7322f8f105..dfff7f12a2fc3af6979085e771beda8ed7004761 100644 GIT binary patch literal 5744 zcmbtXYm6IL6~1G8vrfFP?524r6-*&Z9;)qivR$@`8a53k4oX5rSy5F&W^B*equ4X< z%y{Ds3W26-Yb}eifS^T{k~RXRqCkX%vXKJ2qC5hXAms-L3DEv%p+Asl0ijADg>&wl z+B?L$E+;hJ3yl3vcbA3L0;v*4F6HJ;oEY>7Og&5ns#!pFhO57uc#dNOqX70jY zKHWO^O0LzoT*}SIM)!a|*UG+|Sy|o!>|1CK@_Omk^5sF&wX#bW&Mn<(Y*|K2X}*j# z1dj95w{i=O+w<9_8yKziGYPk{H!qyK+0ADmyP8{=zMWfeW6~+t`q6TPBMx5A{(A8G z3I!Ux{&sHRKz;{ zZQ?+tJ?mIHgbU{N8uULVL&fE4=;OFNJ|0>mk$5k{5iKr(nD7`;OoNb_L!b)S0}nGBy|<0V-t!WmvY1%xy}t*3Bm6|{ zKH2TSGj`@{Y%>)5>n@m0VDrwm(KO)yhOUu-|2w{qSit`i&EukH9H4PvWvRU)7Ow)Z z34TKB`6LcR+$-&c1R{Yly7-DoDub|YP|d~dypZTc4cga|f$s)+eKzXXdnRl)NS zccD=#xgbHkmJMSRZ8iqg1Gn{!X#X3({o`xpOW%lprF`k7_%9-vZ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