use getopt (thanks to Petr Uzel)

This commit is contained in:
Arnout Engelen
2008-12-31 16:44:02 +00:00
parent 3d6ac8bdd3
commit 0072311911

View File

@@ -10,6 +10,7 @@
#include <signal.h> #include <signal.h>
#include <string> #include <string>
#include <string.h> #include <string.h>
#include <getopt.h>
#include <stdarg.h> #include <stdarg.h>
#include <netinet/ip.h> #include <netinet/ip.h>
@@ -268,50 +269,48 @@ int main (int argc, char** argv)
//dp_link_type linktype = dp_link_ethernet; //dp_link_type linktype = dp_link_ethernet;
int promisc = 0; int promisc = 0;
for (argv++; *argv; argv++) int opt;
{ while ((opt = getopt(argc, argv, "Vhbtpd:")) != -1) {
if (**argv=='-') switch(opt) {
{ case 'V':
(*argv)++; versiondisplay();
switch(**argv) exit(0);
{ case 'h':
case 'V': versiondisplay(); help();
exit(0); exit(0);
case 'h': help(); case 'b':
exit(0); bughuntmode = true;
case 'b': bughuntmode = true; tracemode = true;
tracemode = true; break;
break; case 't':
case 't': tracemode = true; tracemode = true;
break; break;
case 'p': promisc = 1; case 'p':
break; promisc = 1;
case 'd': if (argv[1]) break;
{ case 'd':
argv++; refreshdelay=atoi(optarg);
refreshdelay=atoi(*argv); break;
} /*
break; case 'f':
/*case 'f': if (argv[1]) argv++;
{ if (strcmp (optarg, "ppp") == 0)
argv++; linktype = dp_link_ppp;
if (strcmp (*argv, "ppp") == 0) else if (strcmp (optarg, "eth") == 0)
linktype = dp_link_ppp; linktype = dp_link_ethernet;
else if (strcmp (*argv, "eth") == 0) }
linktype = dp_link_ethernet; break;
} */
break; default:
*/ help();
default : help(); exit(EXIT_FAILURE);
exit(0);
}
}
else
{
devices = new device (strdup(*argv), devices);
} }
} }
while (optind < argc) {
devices = new device (strdup(argv[optind++]), devices);
}
if (devices == NULL) if (devices == NULL)
{ {
devices = new device (strdup("eth0")); devices = new device (strdup("eth0"));