Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/sbin/ping6 Pullup by patch (sync with HEAD) [itojun]:
details: https://anonhg.NetBSD.org/src/rev/fc63b657b575
branches: netbsd-1-5
changeset: 489910:fc63b657b575
user: tv <tv%NetBSD.org@localhost>
date: Wed Oct 18 17:04:38 2000 +0000
description:
Pullup by patch (sync with HEAD) [itojun]:
Format string cleanups by Bill Sommerfeld.
----------------------------
fix truncated response handling; sync with kame
----------------------------
repair fd_set size attack.
some of cleanups from kame (inet_ntop error check, unnecessary headers,
stddev computation like ping(8)).
----------------------------
- bugfix: truncated FQDN printing
- allow < 1 second interval on -i (root only).
----------------------------
DNS compression support.
be more picky about DNS label validation.
(sync with kame)
diffstat:
sbin/ping6/Makefile | 6 +-
sbin/ping6/ping6.c | 881 +++++++++++++++++++++++++++++++++++----------------
2 files changed, 605 insertions(+), 282 deletions(-)
diffs (truncated from 1388 to 300 lines):
diff -r deca51333405 -r fc63b657b575 sbin/ping6/Makefile
--- a/sbin/ping6/Makefile Wed Oct 18 17:01:51 2000 +0000
+++ b/sbin/ping6/Makefile Wed Oct 18 17:04:38 2000 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.5 1999/12/13 15:25:59 itojun Exp $
+# $NetBSD: Makefile,v 1.5.4.1 2000/10/18 17:04:38 tv Exp $
PROG= ping6
MAN= ping6.8
@@ -9,8 +9,8 @@
CPPFLAGS+=-DINET6
CPPFLAGS+=-DIPSEC
-LDADD+= -lipsec
-DPADD+= ${LIBIPSEC}
+LDADD+= -lipsec -lm
+DPADD+= ${LIBIPSEC} ${LIBM}
# KAME scope id hack
CPPFLAGS+=-DKAME_SCOPEID
diff -r deca51333405 -r fc63b657b575 sbin/ping6/ping6.c
--- a/sbin/ping6/ping6.c Wed Oct 18 17:01:51 2000 +0000
+++ b/sbin/ping6/ping6.c Wed Oct 18 17:04:38 2000 +0000
@@ -1,5 +1,5 @@
-/* $NetBSD: ping6.c,v 1.15.2.2 2000/10/16 23:31:30 tv Exp $ */
-/* $KAME: ping6.c,v 1.55 2000/06/12 16:18:32 itojun Exp $ */
+/* $NetBSD: ping6.c,v 1.15.2.3 2000/10/18 17:04:38 tv Exp $ */
+/* $KAME: ping6.c,v 1.91 2000/10/07 06:23:06 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -81,7 +81,7 @@
#else
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ping6.c,v 1.15.2.2 2000/10/16 23:31:30 tv Exp $");
+__RCSID("$NetBSD: ping6.c,v 1.15.2.3 2000/10/18 17:04:38 tv Exp $");
#endif
#endif
@@ -116,19 +116,20 @@
#include <net/if.h>
#include <net/route.h>
-#include <netinet/in_systm.h>
#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
#include <netinet/ip6.h>
#include <netinet/icmp6.h>
#include <arpa/inet.h>
+#include <arpa/nameser.h>
#include <netdb.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+#include <math.h>
+#endif
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -140,14 +141,19 @@
#include <netinet6/ipsec.h>
#endif
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <md5.h>
+#else
+#include "md5.h"
+#endif
#define MAXPACKETLEN 131072
#define IP6LEN 40
#define ICMP6ECHOLEN 8 /* icmp echo header len excluding time */
#define ICMP6ECHOTMLEN sizeof(struct timeval)
#define ICMP6_NIQLEN (ICMP6ECHOLEN + 8)
-#define ICMP6_NIRLEN (ICMP6ECHOLEN + 12) /* 64 bits of nonce + 32 bits ttl */
+/* FQDN case, 64 bits of nonce + 32 bits ttl */
+#define ICMP6_NIRLEN (ICMP6ECHOLEN + 12)
#define EXTRA 256 /* for AH and various other headers. weird. */
#define DEFDATALEN ICMP6ECHOTMLEN
#define MAXDATALEN MAXPACKETLEN - IP6LEN - ICMP6ECHOLEN
@@ -185,6 +191,8 @@
#define F_HOSTNAME 0x10000
#define F_FQDNOLD 0x20000
#define F_NIGROUP 0x40000
+#define F_SUPTYPES 0x80000
+#define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES)
u_int options;
#define IN6LEN sizeof(struct in6_addr)
@@ -212,6 +220,7 @@
char DOT = '.';
char *hostname;
int ident; /* process id to identify our packets */
+u_int8_t nonce[8]; /* nonce field for node information */
struct in6_addr srcaddr;
/* counters */
@@ -219,7 +228,7 @@
long nreceived; /* # of packets we got back */
long nrepeats; /* number of duplicates */
long ntransmitted; /* sequence # for outbound packets = #sent */
-int interval = 1; /* interval between packets */
+struct timeval interval = {1, 0}; /* interval between packets */
int hoplimit = -1; /* hoplimit */
/* timing */
@@ -227,6 +236,9 @@
double tmin = 999999999.0; /* minimum round trip time */
double tmax = 0.0; /* maximum round trip time */
double tsum = 0.0; /* sum of all times, for doing average */
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+double tsumsq = 0.0; /* sum of all times squared, for std. dev. */
+#endif
/* for node addresses */
u_short naflags;
@@ -248,6 +260,10 @@
void pr_icmph __P((struct icmp6_hdr *, u_char *));
void pr_iph __P((struct ip6_hdr *));
void pr_nodeaddr __P((struct icmp6_nodeinfo *, int));
+int myechoreply __P((const struct icmp6_hdr *));
+int mynireply __P((const struct icmp6_nodeinfo *));
+char *dnsdecode __P((const u_char **, const u_char *, const u_char *,
+ u_char *, size_t));
void pr_pack __P((u_char *, int, struct msghdr *));
void pr_exthdrs __P((struct msghdr *));
void pr_ip6opt __P((void *));
@@ -268,7 +284,8 @@
struct sockaddr_in6 from;
struct timeval timeout;
struct addrinfo hints;
- fd_set fdset;
+ fd_set *fdmaskp;
+ int fdmasks;
register int cc, i;
int ch, fromlen, hold, packlen, preload, optval, ret_ga;
u_char *datap, *packet;
@@ -281,10 +298,14 @@
#ifdef USE_RFC2292BIS
struct ip6_rthdr *rthdr = NULL;
#endif
+#ifndef __OpenBSD__
+ struct timeval tv;
+#endif
#ifdef IPSEC_POLICY_IPSEC
char *policy_in = NULL;
char *policy_out = NULL;
#endif
+ double intval;
size_t rthlen;
/* just to be sure */
@@ -294,54 +315,54 @@
preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
#ifndef IPSEC
- while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:vwW")) != EOF)
+ while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:tvwW")) != EOF)
#else
#ifdef IPSEC_POLICY_IPSEC
- while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:vwWP:")) != EOF)
+ while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:tvwWP:")) != EOF)
#else
- while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:vwWAE")) != EOF)
+ while ((ch = getopt(argc, argv, "a:b:c:dfHh:I:i:l:nNp:qRS:s:tvwWAE")) != EOF)
#endif /*IPSEC_POLICY_IPSEC*/
#endif
{
- switch(ch) {
- case 'a':
- {
- char *cp;
+ switch (ch) {
+ case 'a':
+ {
+ char *cp;
- options |= F_NODEADDR;
- datalen = 2048; /* XXX: enough? */
- for (cp = optarg; *cp != '\0'; cp++) {
- switch(*cp) {
- case 'a':
- naflags |= NI_NODEADDR_FLAG_ALL;
- break;
- case 'c':
- case 'C':
- naflags |= NI_NODEADDR_FLAG_COMPAT;
- break;
- case 'l':
- case 'L':
- naflags |= NI_NODEADDR_FLAG_LINKLOCAL;
- break;
- case 's':
- case 'S':
- naflags |= NI_NODEADDR_FLAG_SITELOCAL;
- break;
- case 'g':
- case 'G':
- naflags |= NI_NODEADDR_FLAG_GLOBAL;
- break;
- case 'A': /* experimental. not in the spec */
- naflags |= NI_NODEADDR_FLAG_ANYCAST;
- break;
- default:
- usage();
- /*NOTREACHED*/
- }
- }
- break;
- }
- case 'b':
+ options &= ~F_NOUSERDATA;
+ options |= F_NODEADDR;
+ for (cp = optarg; *cp != '\0'; cp++) {
+ switch (*cp) {
+ case 'a':
+ naflags |= NI_NODEADDR_FLAG_ALL;
+ break;
+ case 'c':
+ case 'C':
+ naflags |= NI_NODEADDR_FLAG_COMPAT;
+ break;
+ case 'l':
+ case 'L':
+ naflags |= NI_NODEADDR_FLAG_LINKLOCAL;
+ break;
+ case 's':
+ case 'S':
+ naflags |= NI_NODEADDR_FLAG_SITELOCAL;
+ break;
+ case 'g':
+ case 'G':
+ naflags |= NI_NODEADDR_FLAG_GLOBAL;
+ break;
+ case 'A': /* experimental. not in the spec */
+ naflags |= NI_NODEADDR_FLAG_ANYCAST;
+ break;
+ default:
+ usage();
+ /*NOTREACHED*/
+ }
+ }
+ break;
+ }
+ case 'b':
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
sockbufsize = atoi(optarg);
#else
@@ -383,10 +404,23 @@
#endif
break;
case 'i': /* wait between sending packets */
- interval = strtol(optarg, &e, 10);
- if (interval <= 0 || *optarg == '\0' || *e != '\0')
- errx(1,
- "illegal timing interval -- %s", optarg);
+ intval = strtod(optarg, &e);
+ if (*optarg == '\0' || *e != '\0')
+ errx(1, "illegal timing interval %s", optarg);
+ if (intval < 1 && getuid()) {
+ errx(1, "%s: only root may use interval < 1s",
+ strerror(EPERM));
+ }
+ interval.tv_sec = (long)intval;
+ interval.tv_usec =
+ (long)((intval - interval.tv_sec) * 1000000);
+ if (interval.tv_sec < 0)
+ errx(1, "illegal timing interval %s", optarg);
+ /* less than 1/hz does not make sense */
+ if (interval.tv_sec == 0 && interval.tv_usec < 10000) {
+ warnx("too small interval, raised to 0.01");
+ interval.tv_usec = 10000;
+ }
options |= F_INTERVAL;
break;
case 'l':
@@ -429,18 +463,25 @@
datalen = strtol(optarg, &e, 10);
if (datalen <= 0 || *optarg == '\0' || *e != '\0')
errx(1, "illegal datalen value -- %s", optarg);
- if (datalen > MAXDATALEN)
+ if (datalen > MAXDATALEN) {
errx(1,
"datalen value too large, maximum is %d",
MAXDATALEN);
+ }
+ break;
+ case 't':
+ options &= ~F_NOUSERDATA;
+ options |= F_SUPTYPES;
break;
case 'v':
options |= F_VERBOSE;
break;
case 'w':
Home |
Main Index |
Thread Index |
Old Index