Better error handling for -s.
Submitted by: bde Do not constantify maximum payload size. It is 65467 with -R (record route), and 65507 without it. Reviewed by: silence on -net Proposed by: bde I am going to MFC rev.1.77 - 1.81 ping.c and rev.1.39 and 1.40 ping.8: MFC after: 6 months
This commit is contained in:
parent
261e59bb9e
commit
fb7d32c7ee
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109734
@ -235,7 +235,7 @@ data bytes when combined
|
|||||||
with the 8 bytes of
|
with the 8 bytes of
|
||||||
.Tn ICMP
|
.Tn ICMP
|
||||||
header data.
|
header data.
|
||||||
Only the super-user may use this option.
|
Only the super-user may specify values more than default.
|
||||||
.It Fl S Ar src_addr
|
.It Fl S Ar src_addr
|
||||||
Use the following IP address as the source address in outgoing packets.
|
Use the following IP address as the source address in outgoing packets.
|
||||||
On hosts with more than one IP address, this option can be used to
|
On hosts with more than one IP address, this option can be used to
|
||||||
|
@ -104,7 +104,6 @@ static const char rcsid[] =
|
|||||||
#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)
|
#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)
|
||||||
#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN)
|
#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN)
|
||||||
#define MINICMPLEN ICMP_MINLEN
|
#define MINICMPLEN ICMP_MINLEN
|
||||||
#define MAXPAYLOAD (IP_MAXPACKET - MAXIPLEN - MINICMPLEN)
|
|
||||||
#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 MAXALARM (60 * 60) /* max seconds for alarm timeout */
|
||||||
#define MAXTOS 255
|
#define MAXTOS 255
|
||||||
@ -151,6 +150,7 @@ int mx_dup_ck = MAX_DUP_CHK;
|
|||||||
char rcvd_tbl[MAX_DUP_CHK / 8];
|
char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||||
|
|
||||||
struct sockaddr_in whereto; /* who to ping */
|
struct sockaddr_in whereto; /* who to ping */
|
||||||
|
long maxpayload;
|
||||||
int datalen = DEFDATALEN;
|
int datalen = DEFDATALEN;
|
||||||
int s; /* socket file descriptor */
|
int s; /* socket file descriptor */
|
||||||
u_char outpackhdr[IP_MAXPACKET], *outpack;
|
u_char outpackhdr[IP_MAXPACKET], *outpack;
|
||||||
@ -351,18 +351,16 @@ main(argc, argv)
|
|||||||
options |= F_SO_DONTROUTE;
|
options |= F_SO_DONTROUTE;
|
||||||
break;
|
break;
|
||||||
case 's': /* size of packet to send */
|
case 's': /* size of packet to send */
|
||||||
if (uid) {
|
|
||||||
errno = EPERM;
|
|
||||||
err(EX_NOPERM, "-s flag");
|
|
||||||
}
|
|
||||||
ultmp = strtoul(optarg, &ep, 0);
|
ultmp = strtoul(optarg, &ep, 0);
|
||||||
if (ultmp > MAXPAYLOAD)
|
|
||||||
errx(EX_USAGE,
|
|
||||||
"packet size too large: %lu > %u",
|
|
||||||
ultmp, MAXPAYLOAD);
|
|
||||||
if (*ep || ep == optarg)
|
if (*ep || ep == optarg)
|
||||||
errx(EX_USAGE, "invalid packet size: `%s'",
|
errx(EX_USAGE, "invalid packet size: `%s'",
|
||||||
optarg);
|
optarg);
|
||||||
|
if (uid != 0 && ultmp > DEFDATALEN) {
|
||||||
|
errno = EPERM;
|
||||||
|
err(EX_NOPERM,
|
||||||
|
"packet size too large: %lu > %u",
|
||||||
|
ultmp, DEFDATALEN);
|
||||||
|
}
|
||||||
datalen = ultmp;
|
datalen = ultmp;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
@ -418,6 +416,12 @@ main(argc, argv)
|
|||||||
usage();
|
usage();
|
||||||
target = argv[optind];
|
target = argv[optind];
|
||||||
|
|
||||||
|
maxpayload = IP_MAXPACKET - sizeof(struct ip) - MINICMPLEN;
|
||||||
|
if (options & F_RROUTE)
|
||||||
|
maxpayload -= MAX_IPOPTLEN;
|
||||||
|
if (datalen > maxpayload)
|
||||||
|
errx(EX_USAGE, "packet size too large: %lu > %u", datalen,
|
||||||
|
maxpayload);
|
||||||
if (source) {
|
if (source) {
|
||||||
bzero((char *)&sin, sizeof(sin));
|
bzero((char *)&sin, sizeof(sin));
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
@ -1477,7 +1481,7 @@ fill(bp, patp)
|
|||||||
&pat[13], &pat[14], &pat[15]);
|
&pat[13], &pat[14], &pat[15]);
|
||||||
|
|
||||||
if (ii > 0)
|
if (ii > 0)
|
||||||
for (kk = 0; kk <= MAXPAYLOAD - (PHDR_LEN + ii); kk += ii)
|
for (kk = 0; kk <= maxpayload - (PHDR_LEN + ii); kk += ii)
|
||||||
for (jj = 0; jj < ii; ++jj)
|
for (jj = 0; jj < ii; ++jj)
|
||||||
bp[jj + kk] = pat[jj];
|
bp[jj + kk] = pat[jj];
|
||||||
if (!(options & F_QUIET)) {
|
if (!(options & F_QUIET)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user