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
This commit is contained in:
Bill Fumerola 2000-01-20 20:48:51 +00:00
parent 58295f6ace
commit bf113f1b05
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=56342
2 changed files with 16 additions and 8 deletions

View File

@ -50,6 +50,7 @@ packets to network hosts
.Op Fl P Ar policy .Op Fl P Ar policy
.Op Fl s Ar packetsize .Op Fl s Ar packetsize
.Op Fl S Ar src_addr .Op Fl S Ar src_addr
.Op Fl t Ar timeout
.Bo .Bo
.Ar host | .Ar host |
.Op Fl L .Op Fl L

View File

@ -104,6 +104,7 @@ static const char rcsid[] =
#define MAXICMPLEN 76 #define MAXICMPLEN 76
#define MAXPACKET (65536 - 60 - 8)/* max packet size */ #define MAXPACKET (65536 - 60 - 8)/* max packet size */
#define MAXWAIT 10 /* max seconds to wait for response */ #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 NROUTES 9 /* number of record route slots */
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
@ -217,7 +218,7 @@ main(argc, argv)
char *policy_in = NULL; char *policy_in = NULL;
char *policy_out = NULL; char *policy_out = NULL;
#endif #endif
int alarmtimeout = 0; unsigned long alarmtimeout;
/* /*
* Do the stuff that we need root priv's for *first*, and * Do the stuff that we need root priv's for *first*, and
@ -230,7 +231,7 @@ main(argc, argv)
setuid(getuid()); setuid(getuid());
uid = getuid(); uid = getuid();
preload = 0; alarmtimeout = preload = 0;
datap = &outpack[8 + PHDR_LEN]; datap = &outpack[8 + PHDR_LEN];
#ifndef IPSEC #ifndef IPSEC
@ -342,11 +343,14 @@ main(argc, argv)
source = optarg; source = optarg;
break; break;
case 't': case 't':
alarmtimeout = (int)strtoul(optarg, &ep, 0); alarmtimeout = strtoul(optarg, &ep, 0);
if (alarmtimeout < 1) if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX))
errx(EX_USAGE, "invalid timeout: `%s'", errx(EX_USAGE, "invalid timeout: `%s'",
optarg); optarg);
alarm(alarmtimeout); if (alarmtimeout > MAXALARM)
errx(EX_USAGE, "invalid timeout: `%s' > %d",
optarg, MAXALARM);
alarm((int)alarmtimeout);
break; break;
case 'T': /* multicast TTL */ case 'T': /* multicast TTL */
ultmp = strtoul(optarg, &ep, 0); ultmp = strtoul(optarg, &ep, 0);
@ -566,9 +570,12 @@ main(argc, argv)
if (sigaction(SIGINFO, &si_sa, 0) == -1) { if (sigaction(SIGINFO, &si_sa, 0) == -1) {
err(EX_OSERR, "sigaction"); err(EX_OSERR, "sigaction");
} }
si_sa.sa_handler = stopit;
if (sigaction(SIGALRM, &si_sa, 0) == -1) if (alarmtimeout > 0) {
err(EX_OSERR, "sigaction SIGALRM"); si_sa.sa_handler = stopit;
if (sigaction(SIGALRM, &si_sa, 0) == -1)
err(EX_OSERR, "sigaction SIGALRM");
}
bzero(&msg, sizeof(msg)); bzero(&msg, sizeof(msg));
msg.msg_name = (caddr_t)&from; msg.msg_name = (caddr_t)&from;