add comment

This commit is contained in:
ubuntu201711081 2020-12-14 11:33:56 +00:00
parent ad881333e0
commit 53f8f003d7

View File

@ -211,6 +211,9 @@ int send_response(int sock,int fd, uint8_t * buf, size_t bufsize){
#endif #endif
return 0; return 0;
} }
/** print help message
* arg `n`: executable name
*/
const char * help(const char * n){ const char * help(const char * n){
const char * msg = "USASE : %s [Option] ...\n" const char * msg = "USASE : %s [Option] ...\n"
"Options and arguments: \n" "Options and arguments: \n"
@ -219,7 +222,8 @@ const char * help(const char * n){
printf(msg,n); printf(msg,n);
return msg; return msg;
} }
/** return 0 ok. otherwise invalid format*/ /** parse arguments.
* if return 0, success. otherwise arguments are invalid format.*/
int parse_args(int argc,const char * argv[] , in_port_t * port){ int parse_args(int argc,const char * argv[] , in_port_t * port){
int pos = 1; int pos = 1;
const char * opt; const char * opt;
@ -236,10 +240,14 @@ int parse_args(int argc,const char * argv[] , in_port_t * port){
const char * value = argv[pos++]; const char * value = argv[pos++];
*port = atoi(value); *port = atoi(value);
if (port == 0){ // either not number or zero if (port == 0){ // either not number or zero
fprintf(stderr,"port argument is either not number or zero\n");
return 2; return 2;
} }
} }
else return 2; //failed to find argument. else{
fprintf(stderr,"need argument\n");
return 2; //failed to find argument.
}
} }
} }
return 0; return 0;