From 03b786779a6d69c98c3fc33513206fa0f71bf52c Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 5 Feb 2017 22:17:48 +0100 Subject: [PATCH] Argument management --- client | Bin 17680 -> 17888 bytes client.c | 56 ++++++++++++++++++++++++++++++++++++++++++------------- client.o | Bin 5608 -> 6752 bytes server | Bin 17816 -> 17976 bytes server.c | 50 +++++++++++++++++++++++++++++++++++++++---------- server.o | Bin 5744 -> 6680 bytes 6 files changed, 83 insertions(+), 23 deletions(-) diff --git a/client b/client index 7d4df29cb07b801de1cd5f8a381ba01f577e7763..c2d77653fbb2cabfe58e45a3c2059fb3dbaa01f0 100755 GIT binary patch delta 4738 zcmZu#3s75C8b0@iKoY_uAtcc5mWw3(9^;jfG&7dO`vN`7dkQjZ8+`jRR*2)P7z<0jlF3*S8yF zok4PGH_%tPGlu*B{M);dK0G}Cjpq5>v1-42>yBe;`fGkIS3{?G6St1_Evzr2oT89x zq(#slW|H4wPle(*`VZc~^)uN!bX;NL986PF$~5~G8QkMcSHJ;I(Ij@zzp zbL?rl@x~nvN0Y6ynRN9y9rUxfXSfpDtjysFPd&<|+mr;JV*U}rkvRBINUAh9Vrpwk zB1B0(kY!H|JQGjA=2ICPm|j87%D87qo0Kw_f%UDfdzXLt% z4l&Lv)WvWyVin>>hF1V~wL)P?sD=ryK?4n93&TqgCn8?SupY4%vB0nfF)RcLr83MT zPDV@^o;LzcK|J##2+aRQjB6MQFnr!9xJauG1(Qs04h{5({S2Q$oQ8Oa;lCrs4IUa~ zmytV%*gPYI1T zlREMGNmy&qJ(nzcKEHSAD01P_>Kc5g2nWFWQ5K-#IId)KK?IMXzD|7P!X*8x+MFv{ zr(}_a<5GZ!H)KMBq(@f=%)w5G+;Bn}PmP)?-RnPu!nnPimvqyXt4s5@ z`A8-5d_z%>qac-5|Ag=DsPsjUdabjfw|Z`uxJqlzgOuTtX{WsIC&BD7KQLO5k&iMSz&lg+OhwARx;MujjrDvs z;<*n!-rQ)IOvU`S{(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KbJSd^!8SOjk4u=w{EHB&gav?N;_+gm=ipd?=#t8q8` zVM!tFW}PL4iaSpBprk;z)+LQ_L(Pgy^R(F+61>C?mgZ}3&5+O%)>E2KGuZvoLPhsN aw$NRmb>LA)Vh7#%T1UPF-eNuO)c*pv`;_Vc diff --git a/client.c b/client.c index e110ecc..48ced06 100644 --- a/client.c +++ b/client.c @@ -4,23 +4,56 @@ int main(int argc, char* argv[]){ - /* [1] Initialisation + /* [1] Initialization + arguments =========================================================*/ /* (1) Socket information */ struct sockaddr_in server_addr; // server info int sock; // socket + int port; // chosen port + char hostname[24]; // chosen hostname /* (2) Misc. information */ int bytes; // transfer count char* to_send = (char*) malloc( BUFSIZE * sizeof(char) ); char* to_recv = (char*) malloc( BUFSIZE * sizeof(char) ); - - - /* [2] Create UPD socket and get target data + /* [2] Manage arguments =========================================================*/ - sock = xconnect("localhost", 4000, &server_addr); + /* (1) Manage arguments count */ + if( argc < 3 ){ + printf("Missing arguments\nUsage: client hostname port [message]\n"); + return 1; + } + + /* (2) Manage @hostname argument */ + if( strlen(argv[1]) > 24 || sscanf(argv[1], "%s", hostname) <= 0 ){ + printf("argument error: hostname must be a string (max: 24 characters long)\n"); + return 1; + } + + /* (3) Manage port argument */ + if( sscanf(argv[2], "%d", &port) <= 0 ){ + printf("argument error: port must be a valid integer\n"); + return 1; + } + + /* (4) Manage optional @message argument */ + if( argc >= 4 ){ + + if( strlen(argv[3]) > BUFSIZE || sscanf(argv[3], "%s", to_send) <= 0 ){ + printf("argument error: message must be a string (max: %d characters long)\n", BUFSIZE); + return 1; + } + + }else + strcpy(to_send, "client default message"); + + + + /* [3] Create UPD socket and get target data + =========================================================*/ + sock = xconnect(hostname, port, &server_addr); /* (1-) Manage error */ if( sock == -1 ){ @@ -29,15 +62,12 @@ int main(int argc, char* argv[]){ } - /* [3] Send message + /* [4] Send message =========================================================*/ - /* (1) Set message to send */ - strcpy(to_send, "client message"); - - /* (2) Send message to server */ + /* (1) Send message to server */ bytes = xsend(sock, to_send, &server_addr); - /* (3) Check if send succesfully */ + /* (2) Check if send succesfully */ if( bytes == -1 ){ perror("erreur envoi message"); exit(1); @@ -47,7 +77,7 @@ int main(int argc, char* argv[]){ - /* [4] Wait for response + /* [5] Wait for response =========================================================*/ /* (1) Wait for response */ bytes = xlisten(sock, &server_addr, to_recv, BUFSIZE); @@ -62,7 +92,7 @@ int main(int argc, char* argv[]){ printf("*** received : '%s'\n", to_recv); - /* [5] Close socket + /* [6] Close socket =========================================================*/ close(sock); diff --git a/client.o b/client.o index d109e27dfac1b55683f2ec8783cdd235b62ceee2..8cae374e0f00de274827739fd608cd71fd86caeb 100644 GIT binary patch literal 6752 zcmbtYeT-CB6~Aw0Scd&#VJR-s=&Q2wVP|F+mKC;wQ|PvX0yb?o(zImyX6EhelbJW` zdvBIm;zH83Ez=E#6>a(l6-uft2_`iVvlvn~k^n|*+89%#M*9aOHZe-o7!pbFoO{om zy?b{iY4jxX?mfTrdC$A=-1p|l;O<95hQTBmY&)CdB+8h1-`qUOr%84nTh4}3)my2_ zzdl!;IG3uHPv=rok?wUMPgMu+^v+&h0n@*rI`H$k>ys1bLPu6yMj_Xj!LT3w4X&xF z!PBY9*=TAC%&rOZ$va&KyH&xlp%33dThN%nk*mEhyU^pwIgcIa@z~IXPiB|}Lr5}w z_*shEH9w&hwS>4}YG}5u-@Wf(5%@ai5*3TZx`Xf8)WvMUvE9JTrK-`?MSIvP7Xq`G zs-~jXk{!11Tf^6qEAsZ$B2 zJ2g0ys=iAFtqxwAoVe7$VruYG^{SR}YHH|u>R9UzVEns)AI7=B9z8&9`dccJz!F$MoNC*T1DF&EqQ_YOc9He zxA(JdA94edcBbulC2zp2=@-j>U}kL7GX22A29XGJ^wpTAMC1%c<%nRF{TM)LHLCSX7Gqc{6vsU1gT+=UQ57>dk zZFj8XnB?8j?4|B1E$iGoN%A$P$t%2zho0~+U1sI#*$Baeaz=25C#yI&tXty9L6vERd zj}VJ~!qdl(@WL9+AAnA1Iw`mobQ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_Cj@oRa@f-r|1QDgFm$!W2MFrJ%4gf)&}@VA z$fLjI(dFmti@AViBHItvIVQN4)ADHKJceOK!tk}feYEA|Y1Pp!Ctp{6DCQYeH&oAU zIr+wI5q zdXnJvf?Qz%3>K7TY{I&jnTdHKjUjJ;2)kN`yHr44VX`s_HN3E~(5Rhy>et|0fzi|> zYezb>MfUO@tqMb&-sbc^*N?|t$@{hhE7$x?*4KkD&nV31bRp5a8d-Cx+~8+r%{r7* zR8!;r3Aa4}m*yEwzeXLcXkr6X&h{qve4bV()GJE%+$ZlyzvO7tbIRCN?)eL%u(wDx zXJm@k2H7t15tJj_F*sLb%u7*FyjYznRv9R#Ohg)`Bj25v|yL$+`ZT=V9t*(v1lVtl21;C zAG-3A;m(rj+5!2}8=#K>9JydBwP+((VNjM@VO^;uwnV-*OQ5T?7^Ko9F(|;z(%jfc zC=zI`#oEY&)}#u%tb=t{i`pxHLwaN3h_z_^lhQ{Y4>)c`!%b_hI?{%C-|K8ey2vx< z#UGC}UKXInmaCrdRe8i#q;}!^mWE5`9J1{f@cCO;W{Hh-kO#WTis3+65?n7U5xk%+ zFU9+IRe7m;a|SnK-znild6BRI2Fpuh)8>SQ3&CVB#xKxS_EKRvblFQ|C3-?}%!M2F QV)gFgFd9<8iN!Pj3nNajGynhq diff --git a/server.c b/server.c index 916f900..f40639f 100644 --- a/server.c +++ b/server.c @@ -10,6 +10,7 @@ int main(int argc, char* argv[]){ // Client struct sockaddr_in addr_client; char client_ip[20]; + int port; // chosen port // Socket int sock; @@ -20,11 +21,40 @@ int main(int argc, char* argv[]){ int bytes; // transfer count + /* [2] Manage arguments + =========================================================*/ + /* (1) Manage arguments count */ + if( argc < 2 ){ + printf("Missing arguments\nUsage: server port [message]\n"); + printf("port = 0 : automatic port\n"); + return 1; + } - /* [2] Create socket + /* (2) Manage port argument */ + if( sscanf(argv[1], "%d", &port) <= 0 ){ + printf("argument error: port must be a valid integer\n"); + printf("port = 0 : automatic port\n"); + return 1; + } + + /* (3) Manage optional @message argument */ + if( argc >= 3 ){ + + if( strlen(argv[2]) > BUFSIZE || sscanf(argv[2], "%s", to_send) <= 0 ){ + printf("argument error: message must be a string (max: %d characters long)\n", BUFSIZE); + return 1; + } + + }else + strcpy(to_send, "server default message"); + + + + + /* [3] Create socket =========================================================*/ /* (1) Create socket */ - sock = xbind(4000); + sock = xbind(port); /* (1-) Manage error */ if( sock == -1 ){ @@ -33,7 +63,7 @@ int main(int argc, char* argv[]){ } - /* [3] Wait for client message + /* [4] Wait for client message =========================================================*/ /* (1) Listen to data */ bytes = xlisten(sock, &addr_client, to_recv, BUFSIZE); @@ -50,21 +80,21 @@ int main(int argc, char* argv[]){ printf("*** received '%s' (%d bytes) from %s:%d\n", to_recv, bytes, client_ip, ntohs(addr_client.sin_port)); - /* [4] Send response + /* [5] Send response =========================================================*/ - /* (1) Set response data */ - strcpy(to_send, "server response"); - - /* (2) Send response */ + /* (1) Send response */ bytes = xsend(sock, to_send, &addr_client); - /* (3) Manage error */ + /* (2) Manage error */ if( bytes == -1 ){ perror("erreur envoi réponse"); exit(1); } - /* [5] Close socket + + /* [6] Close socket =========================================================*/ close(sock); + + return 0; } diff --git a/server.o b/server.o index dfff7f12a2fc3af6979085e771beda8ed7004761..4e516f91caad5aac914871a0fc7808e6aaea9807 100644 GIT binary patch delta 1941 zcmaJ?U1%It6rMYq?9NP*-JPA?Ow#%@l?Jx0m{ih)M6yk2(u}E=fJCt>aokL%3)$T; zGid@P-C+FbCRR+31wnLcs1iXmA*G}~v|A`fBK|&Tm9!}Ip(03Mggg}V-uY=Rse0hv zGv_ciUDh^=JRqROpyMs>^5hF3e|hWD5 zzPLJ9_z1euk;0Q1%gW>oMKg`Dte&$iVZhQ1yo)!(ynM@ zc0Q}wnY2PcreTOoh4Fb5-8A!NyW>-`W0tMFq$`?oOdH7zDVdzD8@kCfSl#y|c%`Tu z%Qi`e$*eZft~3lO>7$ydrET4`l#zVS*d;&-?SpG*Kl%mgScPq7m)qIh2x}M)s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