23,125
社区成员
发帖
与我相关
我的任务
分享
/**
* @file foo.c
* @brief
*/
#include <unistd.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void
usage(void)
{
fprintf(stderr, "usage: demo -h host -p port\n");
exit(1);
}
int main(int argc, char *argv[])
{
int ch;
int port = 0;
char host[HOST_NAME_MAX + 1] = "";
while ((ch = getopt(argc, argv, "h:p:")) != -1) {
switch (ch) {
case 'h':
strcpy(host, optarg);
break;
case 'p':
port = strtol(optarg, NULL, 10);
break;
default:
usage();
break;
}
}
printf("host=%s port=%d\n", host, port);
return 0;
}