From 402dcd042153b74e5ddebe0c984d76f65beec0ad Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 1 Feb 2017 19:11:53 +0100 Subject: [PATCH] Init: code cleanup + comments --- client | Bin 0 -> 9368 bytes client.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ client.h | 18 +++++++++ client.o | Bin 0 -> 3416 bytes lib.c | 0 lib.h | 0 lib.o | Bin 0 -> 944 bytes makefile | 26 ++++++++++++ server.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ server.h | 19 +++++++++ server.o | Bin 0 -> 944 bytes 11 files changed, 300 insertions(+) create mode 100755 client create mode 100644 client.c create mode 100644 client.h create mode 100644 client.o create mode 100644 lib.c create mode 100644 lib.h create mode 100644 lib.o create mode 100644 makefile create mode 100644 server.c create mode 100644 server.h create mode 100644 server.o diff --git a/client b/client new file mode 100755 index 0000000000000000000000000000000000000000..8918d9fc7cc1a3cd39a3fde0f908ce16129fbacc GIT binary patch literal 9368 zcmd5?4QyN06~4Cf+aJd*1wzZ#C)T1+EhZ^x2!HEy61Oi^+J-cRAqcOI{gQa~Pxjt( zmXwus3v~6eK(;XyZA_||7-KLkOce`EYf=g=FbRbr5M!HQXds)8E&QzNHfVOvefQYU zFSdjxP1>pQ&OP5f=iI+@f8DPIJGZ%AE=J^LUtlOnRWgUHFJrG=%0+>-uxci=_3Tns z0Z2Lg$vg+Sl_GvlxF%jD^gO`J;IGAP0WEHsCx}yV#HohJvAjIVB584Rr6m%FmT&;= zu&zEY7lH5N3F4EY9@B!89g1jIC+zBk9r1ZlG2+xdY#aXd2!B0p86=ctWUQTk^Bi@N zy52S;n3h*?5xC3~#G5Rb5huGF!4B*BX~`!PyG41W`ei}1kGK%om9c1FbJLZvNPR4t zNR8Bwv^3W@H~EdEe=~14`bXXEyY}*us2?Seu+D4X4`TrH=Wh9JY*YH_<_{lye(cV* z$=AG3zWxT<(jO#0HC+#ytBYuFD1l#G0^d>sH%s7&68Ie@@O>rl3BV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6-leX26Ncceej7$VK~BOD%UVJ0c9|odHGk<+Q&CFzge0=b-!B zf&l3K1XMVQZY7bWA!WCxd!7%23dzyobnYg8pHQLled7G@6BVWUa$oRq%0F`0)A>dc zirp9-HllI~`Y|Nz^{4x#i9rceZL!?f+5Sf$2kmM6=v;S5*w5uGt%S4w_wK@@+)9dW3#7w zaxFRqa_T$fKZ6d|pN5I<)6%E3e+O(acF3OY-Sqz`=>JPld{Oxn2UCvn>37p}*eD>< zx1_vG_}?MJUVldCZc)G_846Bz#LqeG={_h_addr, // ) + /* ( */ server_host->h_length ); + + + + + /* [3] Send message + =========================================================*/ + // calculate server id struct size + sock_len = sizeof(struct sockaddr_in); + + /* (1) Send message to server (identified by ) */ + nb_bytes = sendto( sock, // ) socket + /* ( */ msg, // ) buffer + /* ( */ strlen(msg) + 1, // ) buffer size + /* ( */ 0, // ) flags + /* ( */ (struct sockaddr*) &server_addr, // ) server identifier + /* ( */ sock_len ); // identifier size + + + /* (2) Check if send succesfully */ + if( nb_bytes == -1 ){ + perror("erreur envoi message"); + exit(1); + } + + // log + printf("paquet envoyé, nb_bytes = %d\n",nb_bytes); + + + + /* [4] Wait for response + =========================================================*/ + nb_bytes = recvfrom( sock, // ) socket + /* ( */ buffer, // ) receive buffer + /* ( */ BUFSIZE, // ) buffer size + /* ( */ 0, // ) flags + /* ( */ (struct sockaddr*) &server_addr, // ) server identifier + /* ( */ &sock_len ); // identifier size + + /* (2) Check if received successfully (and consistently) */ + if( nb_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); + + + /* [5] Close socket + =========================================================*/ + close(sock); + + return 0; +} diff --git a/client.h b/client.h new file mode 100644 index 0000000..ca6902c --- /dev/null +++ b/client.h @@ -0,0 +1,18 @@ +#ifndef _CLIENT_H_ + + #define _CLIENT_H_ + + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #define BUFSIZE 20 + + +#endif diff --git a/client.o b/client.o new file mode 100644 index 0000000000000000000000000000000000000000..c7aec517195b391aad190372a1777bba6b9ed18a GIT binary patch literal 3416 zcmb_eU1%It6h52nkH(~?HEJLQ2XwVUJKZ#C)Pk}xOf!m=QX5oC+|JJ4%`VxU+0IYM z7Pfs@P=+-S@Fk$2Pii3#5%Lf#G=Yf8lT=X97kv`);EO(rG@dha@8)LM0UtceoqNxB zzw>i{&dlD{-niJ4N`a6RyaM~0Kmmq&_s6+#n1g=kg=szb{Vl!qM>%MIq6hv`QEwm0 zoI-*gXuBhu`nI-C?7Q^1*MpA@dhC)KXsfN}>YhKiL0SlHQ0QpX!O+pB-fC__cjCPP zWbS(?Z67Af9@zNoQSPb~gpl6WHru&D-MmjDy`3A<+nD8d`?lNK3OQ@ftRQ1u54OWh z^u^05z3s2JwbhB>mx*vWUsDV|A82c>=32rs+S(eA5ZZBv(<}O-e;*yb7W^PNygT^c zz3R)I`~qzU!_c}GFVWg|^x*r>WT-}K+|K|b^W;NJZ_n%&_0f~zxp{}9BwOE>ugz?M zYuA`kW3Fq=GGLCwd`B^ztviNSu`R{5%{k^l)i#Z4*>*j_Fp3VEFvVrgJX#2tS@U+K zc$P9c?!)mw(gu(tU|uf@R+N-tYnJ4!Vm-2ZA)?p=s!XnX8KGi`XZKcLCLsy zS*Io^FDR#`3%=#~%6WB6&7K+eLv7^N$hevvQ^%f z-6V~kx=9+si+*5=$~GnO>4FPM!%;Cj(5IpMV$yKr0FRVmY$v4r!@WUF!6wH-HI(P@ z*$r0{@X-W(A_1RDz%M1>R}=7S33wp^uO#430^Uf#ZztejRx8Z%R1?CQa`Hy8=%{1o zvZGKlDi+phSc!EkQ5)-Rq2j?T^Qa~Z4a=x8DBNU@4P_6@2x_cm)*Ik@PL-i4vx=S# zb*Ex^B`hp+zU0_7bX&!`#<;f2AfINc_hnejmNCP{h7nj8r(z@%X+COSrsmnV6sJ+|OBwPw!lj|D?nh zYbBGb68~|DUy%58uc&@VW+lFSuWm@VoaZeGe**1AJ|9cCyw6{7T^8cfR4@tPf{n0*C>xk+$YMxO56{|Pu%VOlPs-b#p!2`8ucm}8i*9FzFBgM39 zHGG4BYS|uBr{0`C6P7d*$c&ZqC5PS<|C1=_hn5!qV&o7b5#NbOi@0J;J$+Z`{Bzi3 zd67H3&OeRx{-HSHi$!}#@+>yO<6qFH4s0edBjLv&R5*)ZMz_Ddw{l70zo@OQ)yh_b$C6V0PMC= zv!uJsQeuCf{l$@+e$O8k1J46(9^6BRGz;)b)>S50(^>9449N9V7kuptRSvfs|=Tqt4XQi^wm9k59XXSJR_R?mdP#D z0pqjPB>HA#wff9*N1W3#j}ff3uarh_name, ntohs(addr_client.sin_port) ); + + /* [4] Send response + =========================================================*/ + /* (1) Send response */ + buf_len = sendto(sock, // ) socket + /* ( */ response, // ) response + /* ( */ strlen(response)+1, // ) response length + /* ( */ 0, // ) flags + /* ( */ (struct sockaddr*) &addr_client, // ) client identifier + /* ( */ sock_len ); // identifier length + + /* (1-) Manage error */ + if( buf_len == -1 ){ + perror("erreur envoi réponse"); + exit(1); + } + + /* [5] Close socket + =========================================================*/ + close(sock); +} diff --git a/server.h b/server.h new file mode 100644 index 0000000..e766838 --- /dev/null +++ b/server.h @@ -0,0 +1,19 @@ +#ifndef _SERVER_H_ + + #define _SERVER_H_ + + + + #include + #include + #include + #include + #include + #include + #include + #include + #include + + + +#endif diff --git a/server.o b/server.o new file mode 100644 index 0000000000000000000000000000000000000000..33457c9b5e51d3153db6c08d202c363db79c3fb4 GIT binary patch literal 944 zcmbVL%}&EG40gBid*g=0rJNXuMJehk!2v~@#x4`LJwRJ3A)$7tNzu5#>+pI!0oZM# zW@&c-ONsq`{v1bc`Z-@d3_K5vd2kOcGAzKWMT(jha0L4Ri`neXAFq)&% zs!{L}M2v?lyli;?h6fRk_-%V?H=;Hp`2Oi;0EWFcBYw~)M}D}2-`l~Dy1dNFx2$9- z0F&>ziWBszZ2Yr{RJKvTo?;aPOQZyruJb%AkSo?IV~fYtM5;J_=^p=A<_rsHMmYH` z6I-YS)@Q59bKHq@CnM@?cXR76P;!XtzxCHxOJ{Oiwh0ZUHi@z6Z#?BqY)dN}Sh1@; v!JK<{l3!`z+^VI}ttZ^~+BUlGOM9Bp0WR`nr;WpZroX?h8y#z%ac=)#%N{T^ literal 0 HcmV?d00001