fputs(" -C, --csv output comma separated values\n", out);
fputs(" -l, --raw output raw format\n", out);
fputs(" -p, --split split output\n", out);
+#ifdef HAVE_NCURSES
fputs(" -t, --curses use curses terminal interface\n", out);
+#endif
fputs(" --displaymode MODE select initial display mode\n", out);
+#ifdef HAVE_GTK
fputs(" -g, --gtk use GTK+ xwindow interface\n", out);
+#endif
fputs(" -n, --no-dns do not resove host names\n", out);
fputs(" -b, --show-ips show IP numbers and host names\n", out);
fputs(" -o, --order FIELDS select output fields\n", out);
+#ifdef HAVE_IPINFO
fputs(" -y, --ipinfo NUMBER select ip information in output\n", out);
fputs(" -z, --aslookup display AS number\n", out);
+#endif
fputs(" -h, --help display this help and exit\n", out);
fputs(" -v, --version output version information and exit\n", out);
fputs("\n", out);
/* IMPORTANT: when adding or modifying an option:
0/ try to find a somewhat logical order;
1/ add the long option name in "long_options" below;
- 2/ add the short option name in the "getopt_long" call;
- 3/ update the man page (use the same order);
- 4/ update the help message (see PrintHelp).
+ 2/ update the man page (use the same order);
+ 3/ update the help message (see usage() function).
*/
+ enum {
+ OPT_DISPLAYMODE = CHAR_MAX + 1
+ };
static struct option long_options[] = {
/* option name, has argument, NULL, short name */
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "inet", 0, NULL, '4' }, /* IPv4 only */
+#ifdef ENABLE_IPV6
{ "inet6", 0, NULL, '6' }, /* IPv6 only */
-
+#endif
{ "filename", 1, NULL, 'F' },
{ "report", 0, NULL, 'r' },
{ "report-wide", 0, NULL, 'w' },
{ "xml", 0, NULL, 'x' },
+#ifdef HAVE_NCURSES
{ "curses", 0, NULL, 't' },
+#endif
+#ifdef HAVE_GTK
{ "gtk", 0, NULL, 'g' },
+#endif
{ "raw", 0, NULL, 'l' },
{ "csv", 0, NULL, 'C' },
{ "json", 0, NULL, 'j' },
- { "displaymode", 1, NULL, 'd' },
+ { "displaymode", 1, NULL, OPT_DISPLAYMODE },
{ "split", 0, NULL, 'p' }, /* BL */
/* maybe above should change to -d 'x' */
#endif
{ 0, 0, 0, 0 }
};
+ static const size_t num_options = sizeof(long_options) / sizeof(struct option);
+ char short_options[num_options * 2];
+ size_t n, p;
+
+ for (n = p = 0; n < num_options; n++) {
+ if (CHAR_MAX < long_options[n].val) {
+ continue;
+ }
+ short_options[p] = long_options[n].val;
+ p++;
+ if (long_options[n].has_arg == 1) {
+ short_options[p] = ':';
+ p++;
+ }
+ /* optional options need two ':', but ignore them now as they are not in use */
+ }
opt = 0;
while(1) {
- opt = getopt_long(argc, argv,
- "hv46F:rwxtglCjpnbo:y:zi:c:s:B:Q:ea:f:m:U:uTSP:L:Z:G:M:", long_options, NULL);
+ opt = getopt_long(argc, argv, short_options, long_options, NULL);
if(opt == -1)
break;
reportwide = 1;
DisplayMode = DisplayReport;
break;
+#ifdef HAVE_NCURSES
case 't':
DisplayMode = DisplayCurses;
break;
+#endif
+#ifdef HAVE_GTK
case 'g':
DisplayMode = DisplayGTK;
break;
+#endif
case 'p': /* BL */
DisplayMode = DisplaySplit;
break;
DisplayMode = DisplayXML;
break;
- case 'd':
+ case OPT_DISPLAYMODE:
display_mode = (atoi (optarg)) % 3;
break;
case 'c':