#include #include static struct option const long_options[] = { {"portal", required_argument, NULL, 'p'}, {"discover", no_argument, NULL, 'D'}, {NULL, 0, NULL, 0}, }; static char *short_options = "Dp:"; int main(int argc, char **argv) { int ch, longindex; optopt = 0; while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'D': printf("D\n"); break; case 'p': printf("p\n"); } } if (optopt) printf("unrecognized character '%c'\n", optopt); }