diff options
author | billf <billf@FreeBSD.org> | 2000-01-20 20:48:51 +0000 |
---|---|---|
committer | billf <billf@FreeBSD.org> | 2000-01-20 20:48:51 +0000 |
commit | 7bb98afc93dc9e188e57008966c7ff4419972d02 (patch) | |
tree | 952d031cf5f53fc14bdf6827c84429818d92e70e /sbin/ping/ping.c | |
parent | b5ac56c3392d5ae818a3d45c102ae026be93b76f (diff) | |
download | FreeBSD-src-7bb98afc93dc9e188e57008966c7ff4419972d02.zip FreeBSD-src-7bb98afc93dc9e188e57008966c7ff4419972d02.tar.gz |
Brucify:
add an upper limit to -t
match the types of return values and the variables they are stuffed in
make the man page and usage() a little more consistantly ugly
less obfuscation.
Submitted by: adrian, billf
Diffstat (limited to 'sbin/ping/ping.c')
-rw-r--r-- | sbin/ping/ping.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 074f367..a525b98 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -104,6 +104,7 @@ static const char rcsid[] = #define MAXICMPLEN 76 #define MAXPACKET (65536 - 60 - 8)/* max packet size */ #define MAXWAIT 10 /* max seconds to wait for response */ +#define MAXALARM (60 * 60) /* max seconds for alarm timeout */ #define NROUTES 9 /* number of record route slots */ #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ @@ -217,7 +218,7 @@ main(argc, argv) char *policy_in = NULL; char *policy_out = NULL; #endif - int alarmtimeout = 0; + unsigned long alarmtimeout; /* * Do the stuff that we need root priv's for *first*, and @@ -230,7 +231,7 @@ main(argc, argv) setuid(getuid()); uid = getuid(); - preload = 0; + alarmtimeout = preload = 0; datap = &outpack[8 + PHDR_LEN]; #ifndef IPSEC @@ -342,11 +343,14 @@ main(argc, argv) source = optarg; break; case 't': - alarmtimeout = (int)strtoul(optarg, &ep, 0); - if (alarmtimeout < 1) + alarmtimeout = strtoul(optarg, &ep, 0); + if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX)) errx(EX_USAGE, "invalid timeout: `%s'", optarg); - alarm(alarmtimeout); + if (alarmtimeout > MAXALARM) + errx(EX_USAGE, "invalid timeout: `%s' > %d", + optarg, MAXALARM); + alarm((int)alarmtimeout); break; case 'T': /* multicast TTL */ ultmp = strtoul(optarg, &ep, 0); @@ -566,9 +570,12 @@ main(argc, argv) if (sigaction(SIGINFO, &si_sa, 0) == -1) { err(EX_OSERR, "sigaction"); } - si_sa.sa_handler = stopit; - if (sigaction(SIGALRM, &si_sa, 0) == -1) - err(EX_OSERR, "sigaction SIGALRM"); + + if (alarmtimeout > 0) { + si_sa.sa_handler = stopit; + if (sigaction(SIGALRM, &si_sa, 0) == -1) + err(EX_OSERR, "sigaction SIGALRM"); + } bzero(&msg, sizeof(msg)); msg.msg_name = (caddr_t)&from; |