Created
July 21, 2015 21:04
-
-
Save bholzer/b823e629fca85741403d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* If your shitbox doesn't have getopt, step into the nineties already. */ | |
/* optarg, optind = next-argv-component [i.e. flag arg]; optopt = last-char */ | |
while ((x = getopt (argc, argv, "ae:g:G:hi:lno:p:rs:tuvw:z")) != EOF) { | |
/* Debug (("in go: x now %c, optarg %x optind %d", x, optarg, optind)) */ | |
switch (x) { | |
case 'a': | |
bail ("all-A-records NIY"); | |
o_alla++; break; | |
#ifdef GAPING_SECURITY_HOLE | |
case 'e': /* prog to exec */ | |
pr00gie = optarg; | |
break; | |
#endif | |
case 'G': /* srcrt gateways pointer val */ | |
x = atoi (optarg); | |
if ((x) && (x == (x & 0x1c))) /* mask off bits of fukt values */ | |
gatesptr = x; | |
else | |
bail ("invalid hop pointer %d, must be multiple of 4 <= 28", x); | |
break; | |
case 'g': /* srcroute hop[s] */ | |
if (gatesidx > 8) | |
bail ("too many -g hops"); | |
if (gates == NULL) /* eat this, Billy-boy */ | |
gates = (HINF **) Hmalloc (sizeof (HINF *) * 10); | |
gp = gethostpoop (optarg, o_nflag); | |
if (gp) | |
gates[gatesidx] = gp; | |
gatesidx++; | |
break; | |
case 'h': | |
errno = 0; | |
#ifdef HAVE_HELP | |
helpme(); /* exits by itself */ | |
#else | |
bail ("no help available, dork -- RTFS"); | |
#endif | |
case 'i': /* line-interval time */ | |
o_interval = atoi (optarg) & 0xffff; | |
if (! o_interval) | |
bail ("invalid interval time %s", optarg); | |
break; | |
case 'l': /* listen mode */ | |
o_listen++; break; | |
case 'n': /* numeric-only, no DNS lookups */ | |
o_nflag++; break; | |
case 'o': /* hexdump log */ | |
stage = (unsigned char *) optarg; | |
o_wfile++; break; | |
case 'p': /* local source port */ | |
o_lport = getportpoop (optarg, 0); | |
if (o_lport == 0) | |
bail ("invalid local port %s", optarg); | |
break; | |
case 'r': /* randomize various things */ | |
o_random++; break; | |
case 's': /* local source address */ | |
/* do a full lookup [since everything else goes through the same mill], | |
unless -n was previously specified. In fact, careful placement of -n can | |
be useful, so we'll still pass o_nflag here instead of forcing numeric. */ | |
wherefrom = gethostpoop (optarg, o_nflag); | |
ouraddr = &wherefrom->iaddrs[0]; | |
break; | |
#ifdef TELNET | |
case 't': /* do telnet fakeout */ | |
o_tn++; break; | |
#endif /* TELNET */ | |
case 'u': /* use UDP */ | |
o_udpmode++; break; | |
case 'v': /* verbose */ | |
o_verbose++; break; | |
case 'w': /* wait time */ | |
o_wait = atoi (optarg); | |
if (o_wait <= 0) | |
bail ("invalid wait-time %s", optarg); | |
timer1 = (struct timeval *) Hmalloc (sizeof (struct timeval)); | |
timer2 = (struct timeval *) Hmalloc (sizeof (struct timeval)); | |
timer1->tv_sec = o_wait; /* we need two. see readwrite()... */ | |
break; | |
case 'z': /* little or no data xfer */ | |
o_zero++; | |
break; | |
default: | |
errno = 0; | |
bail ("nc -h for help"); | |
} /* switch x */ | |
} /* while getopt */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment