Date: Tue, 15 Jan 2002 18:24:48 +0300 (MSK) From: Maxim Konovalov <maxim@macomnet.ru> To: Ruslan Ermilov <ru@FreeBSD.ORG> Cc: cvs-committers@FreeBSD.ORG, <cvs-all@FreeBSD.ORG> Subject: Re: cvs commit: src/sbin/ping6 ping6.c Message-ID: <20020115181829.W23305-100000@news1.macomnet.ru> In-Reply-To: <200201151510.g0FFAqc46741@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Ruslan,
On 07:10-0800, Jan 15, 2002, Ruslan Ermilov wrote:
> ru 2002/01/15 07:10:52 PST
>
> Modified files:
> sbin/ping6 ping6.c
> Log:
> First ping after a preload (-l) was sent undelayed.
>
> PR: bin/32354
> Obtained from: ping.c,v 1.61
>
> Revision Changes Path
> 1.15 +2 -1 src/sbin/ping6/ping6.c
While you at the ping stuff could you please review a patch below? It
is a Kris patch with my minor modifications. It seems Kris has
no time for it.
Btw, my docs/33639 is also ping(8)/ping6(8) related.
Thanks in advance.
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/sbin/ping/Makefile,v
retrieving revision 1.17
diff -u -r1.17 Makefile
--- Makefile 2001/12/04 02:19:55 1.17
+++ Makefile 2001/12/09 20:16:59
@@ -8,7 +8,7 @@
.if ${MACHINE_ARCH} == "alpha"
CFLAGS+=-fno-builtin # GCC's builtin memcpy doesn't do unaligned copies
.endif
-WARNS= 0
+WARNS= 2
DPADD= ${LIBM}
LDADD= -lm
Index: ping.c
===================================================================
RCS file: /home/ncvs/src/sbin/ping/ping.c,v
retrieving revision 1.60
diff -u -r1.60 ping.c
--- ping.c 2001/09/25 20:22:33 1.60
+++ ping.c 2001/12/09 20:17:19
@@ -101,8 +101,10 @@
#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
/* runs out of buffer space */
#define MAXIPLEN 60
+#define MINIPLEN 20
#define MAXICMPLEN 76
-#define MAXPACKET (65536 - 60 - 8)/* max packet size */
+#define MINICMPLEN ICMP_MINLEN
+#define MAXPAYLOAD (IP_MAXPACKET - MINIPLEN - MINICMPLEN) /* max ICMP payload 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 */
@@ -149,7 +151,7 @@
struct sockaddr_in whereto; /* who to ping */
int datalen = DEFDATALEN;
int s; /* socket file descriptor */
-u_char outpack[MAXPACKET];
+u_char outpack[IP_MAXPACKET - MINIPLEN];
char BSPACE = '\b'; /* characters written for flood */
char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */
char DOT = '.';
@@ -199,7 +201,7 @@
{
struct timeval last, intvl;
struct hostent *hp;
- struct sockaddr_in *to, sin;
+ struct sockaddr_in *to, sock_in;
struct termios ts;
register int i;
int ch, hold, packlen, preload, sockerrno, almost_done = 0, ttl;
@@ -237,7 +239,7 @@
alarmtimeout = preload = 0;
- datap = &outpack[8 + PHDR_LEN];
+ datap = &outpack[MINICMPLEN + PHDR_LEN];
while ((ch = getopt(argc, argv,
"AI:LQRS:T:c:adfi:l:m:np:qrs:t:v"
#ifdef IPSEC
@@ -347,9 +349,9 @@
err(EX_NOPERM, "-s flag");
}
ultmp = strtoul(optarg, &ep, 0);
- if (ultmp > MAXPACKET)
- errx(EX_USAGE, "packet size too large: %lu",
- ultmp);
+ if (ultmp > MAXPAYLOAD)
+ errx(EX_USAGE, "packet size too large: %lu > %u",
+ ultmp, MAXPAYLOAD);
if (*ep || ep == optarg || !ultmp)
errx(EX_USAGE, "invalid packet size: `%s'",
optarg);
@@ -402,9 +404,9 @@
target = argv[optind];
if (source) {
- bzero((char *)&sin, sizeof(sin));
- sin.sin_family = AF_INET;
- if (inet_aton(source, &sin.sin_addr) != 0) {
+ bzero((char *)&sock_in, sizeof(sock_in));
+ sock_in.sin_family = AF_INET;
+ if (inet_aton(source, &sock_in.sin_addr) != 0) {
shostname = source;
} else {
hp = gethostbyname2(source, AF_INET);
@@ -412,17 +414,17 @@
errx(EX_NOHOST, "cannot resolve %s: %s",
source, hstrerror(h_errno));
- sin.sin_len = sizeof sin;
- if (hp->h_length > sizeof(sin.sin_addr))
+ sock_in.sin_len = sizeof sock_in;
+ if (hp->h_length > (int)sizeof(sock_in.sin_addr))
errx(1,"gethostbyname2: illegal address");
- memcpy(&sin.sin_addr, hp->h_addr_list[0],
- sizeof (sin.sin_addr));
+ memcpy(&sock_in.sin_addr, hp->h_addr_list[0],
+ sizeof (sock_in.sin_addr));
(void)strncpy(snamebuf, hp->h_name,
sizeof(snamebuf) - 1);
snamebuf[sizeof(snamebuf) - 1] = '\0';
shostname = snamebuf;
}
- if (bind(s, (struct sockaddr *)&sin, sizeof sin) == -1)
+ if (bind(s, (struct sockaddr *)&sock_in, sizeof sock_in) == -1)
err(1, "bind");
}
@@ -438,7 +440,7 @@
errx(EX_NOHOST, "cannot resolve %s: %s",
target, hstrerror(h_errno));
- if (hp->h_length > sizeof(to->sin_addr))
+ if (hp->h_length > (int)sizeof(to->sin_addr))
errx(1,"gethostbyname2 returned an illegal address");
memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr);
(void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
@@ -457,10 +459,10 @@
errx(EX_USAGE,
"-I, -L, -T flags cannot be used with unicast destination");
- if (datalen >= PHDR_LEN) /* can we time transfer */
+ if (datalen >= (int)PHDR_LEN) /* can we time transfer */
timing = 1;
packlen = datalen + MAXIPLEN + MAXICMPLEN;
- if (!(packet = (u_char *)malloc((size_t)packlen)))
+ if (!(packet = (u_char *)malloc(IP_MAXPACKET)))
err(EX_UNAVAILABLE, "malloc");
if (!(options & F_PINGFILLED))
@@ -562,7 +564,9 @@
* /etc/ethers. But beware: RFC 1122 allows hosts to ignore broadcast
* or multicast pings if they wish.
*/
- hold = 48 * 1024;
+ hold = IP_MAXPACKET+128; /* XXX receive buffer needs undetermined
+ * space for mbuf overhead as well
+ */
(void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold,
sizeof(hold));
@@ -727,7 +731,7 @@
*/
void
stopit(sig)
- int sig;
+ int sig __unused;
{
finish_up = 1;
}
@@ -736,9 +740,9 @@
* pinger --
* Compose and transmit an ICMP ECHO REQUEST packet. The IP packet
* will be added on by the kernel. The ID field is our UNIX process ID,
- * and the sequence number is an ascending integer. The first 8 bytes
- * of the data portion are used to hold a UNIX "timeval" struct in host
- * byte-order, to compute the round-trip time.
+ * and the sequence number is an ascending integer. The first PHDR_LEN
+ * bytes of the data portion are used to hold a UNIX "timeval" struct in
+ * host byte-order, to compute the round-trip time.
*/
static void
pinger(void)
@@ -757,7 +761,7 @@
CLR(icp->icmp_seq % mx_dup_ck);
if (timing)
- (void)gettimeofday((struct timeval *)&outpack[8],
+ (void)gettimeofday((struct timeval *)&outpack[MINICMPLEN],
(struct timezone *)NULL);
cc = datalen + PHDR_LEN; /* skips ICMP portion */
@@ -802,7 +806,7 @@
register struct icmp *icp;
register u_long l;
register int i, j;
- register u_char *cp,*dp;
+ register u_char *cp, *dp;
static int old_rrlen;
static char old_rr[MAX_IPOPTLEN];
struct ip *ip;
@@ -875,7 +879,7 @@
(void)write(STDOUT_FILENO, &BBELL, 1);
/* check the data */
cp = (u_char*)&icp->icmp_data[PHDR_LEN];
- dp = &outpack[8 + PHDR_LEN];
+ dp = &outpack[MINICMPLEN + PHDR_LEN];
for (i = PHDR_LEN; i < datalen; ++i, ++cp, ++dp) {
if (*cp != *dp) {
(void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x",
@@ -887,8 +891,8 @@
(void)printf("\n\t");
(void)printf("%x ", *cp);
}
- printf("\ndp:");
- cp = &outpack[8];
+ (void)printf("\ndp:");
+ cp = &outpack[MINICMPLEN];
for (i = 0; i < datalen; ++i, ++cp) {
if ((i % 32) == 8)
(void)printf("\n\t");
@@ -942,24 +946,32 @@
hlen -= 2;
j = *++cp;
++cp;
- if (j > IPOPT_MINOFF)
+ i = 0;
+ if (j > IPOPT_MINOFF) {
for (;;) {
l = *++cp;
l = (l<<8) + *++cp;
l = (l<<8) + *++cp;
l = (l<<8) + *++cp;
if (l == 0) {
- printf("\t0.0.0.0");
+ (void)printf("\t0.0.0.0");
} else {
struct in_addr ina;
ina.s_addr = ntohl(l);
- printf("\t%s", pr_addr(ina));
+ (void)printf("\t%s", pr_addr(ina));
}
- hlen -= 4;
- j -= 4;
- if (j <= IPOPT_MINOFF)
- break;
- (void)putchar('\n');
+ hlen -= 4;
+ j -= 4;
+ i += 4;
+ if (j <= IPOPT_MINOFF)
+ break;
+ if (i >= MAX_IPOPTLEN) {
+ (void)printf("\t(truncated route)");
+ break;
+ }
+ (void)putchar('\n');
+ }
+
}
break;
case IPOPT_RR:
@@ -995,11 +1007,11 @@
l = (l<<8) + *++cp;
l = (l<<8) + *++cp;
if (l == 0) {
- printf("\t0.0.0.0");
+ (void)printf("\t0.0.0.0");
} else {
struct in_addr ina;
ina.s_addr = ntohl(l);
- printf("\t%s", pr_addr(ina));
+ (void)printf("\t%s", pr_addr(ina));
}
hlen -= 4;
i -= 4;
@@ -1007,7 +1019,8 @@
if (i <= 0)
break;
if (j >= MAX_IPOPTLEN) {
- (void) printf("\t(truncated route)");
+ (void)printf(
+ "\t(truncated route)");
break;
}
(void)putchar('\n');
@@ -1018,6 +1031,8 @@
break;
default:
(void)printf("\nunknown option %x", *cp);
+ hlen = hlen + cp[1] - 1;
+ cp = cp + cp[1] - 1;
break;
}
if (!(options & F_FLOOD)) {
@@ -1091,7 +1106,7 @@
static void
status(sig)
- int sig;
+ int sig __unused;
{
siginfo_p = 1;
}
@@ -1142,7 +1157,7 @@
double n = nreceived + nrepeats;
double avg = tsum / n;
double vari = tsumsq / n - avg * avg;
- printf("round-trip min/avg/max/stddev = "
+ (void)printf("round-trip min/avg/max/stddev = "
"%.3f/%.3f/%.3f/%.3f ms\n",
tmin, avg, tmax, sqrt(vari));
}
@@ -1400,7 +1415,7 @@
fill(bp, patp)
char *bp, *patp;
{
- register int ii, jj, kk;
+ u_int ii, jj, kk;
int pat[16];
char *cp;
@@ -1417,9 +1432,7 @@
&pat[13], &pat[14], &pat[15]);
if (ii > 0)
- for (kk = 0;
- kk <= MAXPACKET - (8 + PHDR_LEN + ii);
- kk += ii)
+ for (kk = 0; kk <= (MAXPAYLOAD - (PHDR_LEN + ii)); kk += ii)
for (jj = 0; jj < ii; ++jj)
bp[jj + kk] = pat[jj];
if (!(options & F_QUIET)) {
@@ -1433,7 +1446,7 @@
static void
usage()
{
- fprintf(stderr, "%s\n%s\n%s\n",
+ (void)fprintf(stderr, "%s\n%s\n%s\n",
"usage: ping [-QRadfnqrv] [-c count] [-i wait] [-l preload] [-m ttl]",
" [-p pattern] "
#ifdef IPSEC
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020115181829.W23305-100000>
