while ((c = getopt(ac, av, "r:u:p:h:P:s:S:t:iRbo:n:")) != EOF)
{
switch(c)
{
case 'b':
isbsd++;
break;
case 'R':
detectos++;
break;
case 'r':
root = strdup(optarg);
break;
case 'i':
is_scramble = 1;
break;
case 's':
saddr = strtoul(optarg, 0, 0);
break;
case 't':
timeout = strtoul(optarg, 0, 0);
break;
case 'S':
size = strtoul(optarg, 0, 0);
break;
case 'u':
user = strdup(optarg);
break;
case 'p':
pass = strdup(optarg);
break;
case 'h':
host = strdup(optarg);
break;
case 'P':
port = strtoul(optarg, 0, 0);
break;
case 'o':
heapbase = strtoul(optarg, 0, 0);
break;
case 'n':
scnum = strtoul(optarg, 0, 0);
break;
default:
usage(av[0]);
}
}
저는 getopt 기능이 새롭고 결코 사용하지 않았습니다. (ac는 argc, av는 argv 임)C getopt, strdup 기능 코드
이 코드는 어떻게 작동합니까? 내가 혼란스러워하는 것은 "r : u ..."이 어떻게 작동하는지입니다.
또한이 코드에서 strdup 및 strtoul은 무엇을합니까?
감사합니다.
"이 코드에서 strdup 및 strtoul은 무엇을합니까?" 이 기능이 무엇인지 알아보기 위해 설명서를 읽으려고 했습니까? –
당신은 [getopt에 대한 문서]를 읽을나요 (http://www.gnu.org/software/libc/manual/html_node/Getopt.html)? 그것은 모두 거기에 설명되어 있습니다. –