/*显示参数列表*/ void usage() { printf("usage: server [-p:x] [-i:IP] [-o]\n\n"); printf(" -p:x Port number to listen on\n"); printf(" -i:str Interface to listen on\n"); printf(" -o Don't echo the data back\n\n"); ExitProcess(1); } /*验证参数*/ void ValidateArgs(int argc, char **argv) { int i; for (i = 1; i < argc; i++) { if ((argv[i][0] =='-') || (argv[i][0] == '/')) { switch (tolower(argv[i][1])) { /*指定端口*/ case 'p': iPort = atoi(&argv[i][3]); break; /*指定IP*/ case 'i': bInterface = TRUE; if (strlen(argv[i]) > 3) strcpy(szAddress, &argv[i][3]); break; /*只接收消息,不回应*/ case 'o': bRecvOnly = TRUE; break; /*非法参数,显示参数列表*/ default: usage(); break; } } } }
原文地址:http://blog.csdn.net/human_evolution/article/details/41124329