add comment

This commit is contained in:
ubuntu201711081 2020-12-14 11:33:56 +00:00
parent ad881333e0
commit 53f8f003d7
1 changed files with 10 additions and 2 deletions

View File

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