CVS commit: src/sbin/ping6
Module Name:src Committed By: dholland Date: Mon Jun 7 22:13:34 UTC 2021 Modified Files: src/sbin/ping6: ping6.8 ping6.c Log Message: In ping6, there's no blank space in the ping packets by default. - document that if you use -p to specify a fill pattern you need to make the packets bigger with -s; - warn if -p is used and there's not at least one byte of fill space. PR 56057 To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/sbin/ping6/ping6.8 cvs rdiff -u -r1.104 -r1.105 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.8 diff -u src/sbin/ping6/ping6.8:1.33 src/sbin/ping6/ping6.8:1.34 --- src/sbin/ping6/ping6.8:1.33 Mon Apr 23 18:44:39 2018 +++ src/sbin/ping6/ping6.8 Mon Jun 7 22:13:34 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: ping6.8,v 1.33 2018/04/23 18:44:39 maxv Exp $ +.\" $NetBSD: ping6.8,v 1.34 2021/06/07 22:13:34 dholland Exp $ .\" $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 23, 2018 +.Dd June 7, 2021 .Dt PING6 8 .Os .Sh NAME @@ -202,6 +202,10 @@ For example, .Dq Li \-p ff will cause the sent packet to be filled with all ones. +Note that for IPv6 there is no fill space by default so it is +necessary to also use the +.Fl s +option to expand the packet. .\" new IPsec .It Fl q Quiet output. Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.104 src/sbin/ping6/ping6.c:1.105 --- src/sbin/ping6/ping6.c:1.104 Sun May 23 07:17:50 2021 +++ src/sbin/ping6/ping6.c Mon Jun 7 22:13:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.104 2021/05/23 07:17:50 thorpej Exp $ */ +/* $NetBSD: ping6.c,v 1.105 2021/06/07 22:13:34 dholland Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.104 2021/05/23 07:17:50 thorpej Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.105 2021/06/07 22:13:34 dholland Exp $"); #endif #endif @@ -569,6 +569,10 @@ main(int argc, char *argv[]) } else target = argv[argc - 1]; + if ((options & F_PINGFILLED) != 0 && datalen <= (int)ICMP6ECHOTMLEN) { + warnx("-p: No fill space; increase packet size with -s"); + } + /* getaddrinfo */ memset(, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_CANONNAME;
CVS commit: src/sbin/ping6
Module Name:src Committed By: thorpej Date: Sun May 23 07:17:51 UTC 2021 Modified Files: src/sbin/ping6: ping6.c Log Message: Make sure the output packet buffer and the control message buffer are aligned. Fixes bin/56198. To generate a diff of this commit: cvs rdiff -u -r1.103 -r1.104 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.103 src/sbin/ping6/ping6.c:1.104 --- src/sbin/ping6/ping6.c:1.103 Tue Apr 24 07:22:32 2018 +++ src/sbin/ping6/ping6.c Sun May 23 07:17:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.103 2018/04/24 07:22:32 maxv Exp $ */ +/* $NetBSD: ping6.c,v 1.104 2021/05/23 07:17:50 thorpej Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.103 2018/04/24 07:22:32 maxv Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.104 2021/05/23 07:17:50 thorpej Exp $"); #endif #endif @@ -201,7 +201,7 @@ static struct sockaddr_in6 src; /* src a static socklen_t srclen; static int datalen = DEFDATALEN; static int s;/* socket file descriptor */ -static u_char outpack[MAXPACKETLEN]; +static u_char outpack[MAXPACKETLEN] __aligned(sizeof(u_long)); static char BSPACE = '\b'; /* characters written for flood */ static char DOT = '.'; static char *hostname; @@ -923,7 +923,7 @@ doit(u_char *packet, u_int packlen) for (;;) { struct msghdr m; - u_char buf[1024]; + u_long buf[1024 / sizeof(u_long)]; struct iovec iov[2]; clock_gettime(CLOCK_MONOTONIC, );
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Tue Apr 24 07:12:04 UTC 2018 Modified Files: src/sbin/ping6: ping6.c Log Message: Remove annoying (void) casts. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.101 src/sbin/ping6/ping6.c:1.102 --- src/sbin/ping6/ping6.c:1.101 Mon Apr 23 18:48:30 2018 +++ src/sbin/ping6/ping6.c Tue Apr 24 07:12:04 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.101 2018/04/23 18:48:30 maxv Exp $ */ +/* $NetBSD: ping6.c,v 1.102 2018/04/24 07:12:04 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.101 2018/04/23 18:48:30 maxv Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.102 2018/04/24 07:12:04 maxv Exp $"); #endif #endif @@ -587,7 +587,7 @@ main(int argc, char *argv[]) if (!res->ai_addr) errx(1, "getaddrinfo failed"); - (void)memcpy(, res->ai_addr, res->ai_addrlen); + memcpy(, res->ai_addr, res->ai_addrlen); if ((s = prog_socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) @@ -1169,7 +1169,7 @@ pinger(void) if (i < 0 || i != cc) { if (i < 0) warn("sendmsg"); - (void)printf("ping6: wrote %s %d chars, ret=%d\n", + printf("ping6: wrote %s %d chars, ret=%d\n", hostname, cc, i); } if (!(options & F_QUIET) && options & F_FLOOD) @@ -1370,9 +1370,9 @@ pr_pack(u_char *buf, int cc, struct msgh if (options & F_FLOOD) (void)write(STDOUT_FILENO, , 1); else { - (void)printf("%d bytes from %s, icmp_seq=%u", cc, + printf("%d bytes from %s, icmp_seq=%u", cc, pr_addr(from, fromlen), seq); - (void)printf(" hlim=%d", hoplim); + printf(" hlim=%d", hoplim); if ((options & F_VERBOSE) != 0) { struct sockaddr_in6 dstsa; @@ -1383,20 +1383,20 @@ pr_pack(u_char *buf, int cc, struct msgh #endif dstsa.sin6_scope_id = pktinfo->ipi6_ifindex; dstsa.sin6_addr = pktinfo->ipi6_addr; -(void)printf(" dst=%s", +printf(" dst=%s", pr_addr((struct sockaddr *), sizeof(dstsa))); } if (timing) -(void)printf(" time=%.3f ms", triptime); +printf(" time=%.3f ms", triptime); if (dupflag) -(void)printf("(DUP!)"); +printf("(DUP!)"); /* check the data */ cp = buf + off + ICMP6ECHOLEN + ICMP6ECHOTMLEN; dp = outpack + ICMP6ECHOLEN + ICMP6ECHOTMLEN; for (i = 8; cp < end; ++i, ++cp, ++dp) { if (*cp != *dp) { - (void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x", i, *dp, *cp); + printf("\nwrong data byte #%d should be 0x%x but was 0x%x", i, *dp, *cp); break; } } @@ -1417,7 +1417,7 @@ pr_pack(u_char *buf, int cc, struct msgh if (options & F_QUIET) return; - (void)printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); + printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); switch (ntohs(ni->ni_code)) { case ICMP6_NI_SUCCESS: @@ -1484,15 +1484,15 @@ pr_pack(u_char *buf, int cc, struct msgh int32_t ttl; int comma = 0; -(void)printf(" ("); /*)*/ +printf(" ("); /*)*/ switch (ni->ni_code) { case ICMP6_NI_REFUSED: - (void)printf("refused"); + printf("refused"); comma++; break; case ICMP6_NI_UNKNOWN: - (void)printf("unknown qtype"); + printf("unknown qtype"); comma++; break; } @@ -1507,14 +1507,14 @@ pr_pack(u_char *buf, int cc, struct msgh if (comma) printf(","); if (!(ni->ni_flags & NI_FQDN_FLAG_VALIDTTL)) { - (void)printf("TTL=%d:meaningless", + printf("TTL=%d:meaningless", (int)ttl); } else { if (ttl < 0) { - (void)printf("TTL=%d:invalid", + printf("TTL=%d:invalid", ttl); } else - (void)printf("TTL=%d", ttl); + printf("TTL=%d", ttl); } comma++; @@ -1537,7 +1537,7 @@ pr_pack(u_char *buf, int cc, struct msgh cc - off - ICMP6_NIRLEN - 1 && oldfqdn) { if (comma) printf(","); - (void)printf("invalid namelen:%d/%lu", + printf("invalid namelen:%d/%lu", buf[off + ICMP6_NIRLEN], (u_long)cc - off - ICMP6_NIRLEN - 1); comma++; @@ -1552,7 +1552,7 @@ pr_pack(u_char *buf, int cc, struct msgh /* We've got something other than an ECHOREPLY */ if (!(options & F_VERBOSE)) return; - (void)printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); + printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); pr_icmph(icp, end); } @@ -1804,14 +1804,14 @@ pr_nodeaddr(struct icmp6_nodeinfo *ni, / if (options & F_VERBOSE) { switch (ni->ni_code) { case ICMP6_NI_REFUSED: - (void)printf("refused"); + printf("refused"); break; case ICMP6_NI_UNKNOWN: - (void)printf("unknown
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Mon Apr 23 18:48:30 UTC 2018 Modified Files: src/sbin/ping6: ping6.c Log Message: Remove double include and unused macros. To generate a diff of this commit: cvs rdiff -u -r1.100 -r1.101 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.100 src/sbin/ping6/ping6.c:1.101 --- src/sbin/ping6/ping6.c:1.100 Mon Apr 23 18:44:39 2018 +++ src/sbin/ping6/ping6.c Mon Apr 23 18:48:30 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.100 2018/04/23 18:44:39 maxv Exp $ */ +/* $NetBSD: ping6.c,v 1.101 2018/04/23 18:48:30 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.100 2018/04/23 18:44:39 maxv Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.101 2018/04/23 18:48:30 maxv Exp $"); #endif #endif @@ -133,7 +133,6 @@ __RCSID("$NetBSD: ping6.c,v 1.100 2018/0 #include #ifdef IPSEC -#include #include #endif @@ -168,7 +167,6 @@ struct tv32 { #define F_INTERVAL 0x0002 #define F_PINGFILLED 0x0008 #define F_QUIET 0x0010 -#define F_RROUTE 0x0020 #define F_SO_DEBUG 0x0040 #define F_VERBOSE 0x0100 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) @@ -182,17 +180,12 @@ struct tv32 { #define F_FQDNOLD 0x2 #define F_NIGROUP 0x4 #define F_SUPTYPES 0x8 -#define F_NOMINMTU 0x10 #define F_ONCE 0x20 #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) static u_int options; -#define IN6LEN sizeof(struct in6_addr) -#define SA6LEN sizeof(struct sockaddr_in6) #define DUMMY_PORT 10101 -#define SIN6(s) ((struct sockaddr_in6 *)(s)) - /* * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum * number of received sequence numbers we can keep track of. Change 128
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Mon Apr 23 18:44:39 UTC 2018 Modified Files: src/sbin/ping6: ping6.8 ping6.c Log Message: Remove the "-R" option. It uses IPV6_REACHCONF, but we've never had this. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/sbin/ping6/ping6.8 cvs rdiff -u -r1.99 -r1.100 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.8 diff -u src/sbin/ping6/ping6.8:1.32 src/sbin/ping6/ping6.8:1.33 --- src/sbin/ping6/ping6.8:1.32 Mon Apr 23 07:25:36 2018 +++ src/sbin/ping6/ping6.8 Mon Apr 23 18:44:39 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: ping6.8,v 1.32 2018/04/23 07:25:36 wiz Exp $ +.\" $NetBSD: ping6.8,v 1.33 2018/04/23 18:44:39 maxv Exp $ .\" $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -37,7 +37,7 @@ .Sh SYNOPSIS .Nm ping6 .\" without IPsec, or new IPsec -.Op Fl dfHmnNoqRtvwW +.Op Fl dfHmnNoqtvwW .\" old IPsec .\" .Op Fl AdEfnNqRtvwW .Op Fl a Ar addrtype @@ -207,13 +207,6 @@ ones. Quiet output. Nothing is displayed except the summary lines at startup time and when finished. -.It Fl R -Make the kernel believe that the target -.Ar host -is reachable, by injecting upper-layer reachability confirmation hint. -The option is meaningful only if the target -.Ar host -is a neighbor. .It Fl S Ar sourceaddr Specifies the source address of request packets. The source address must be one of the unicast addresses of the sending node, Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.99 src/sbin/ping6/ping6.c:1.100 --- src/sbin/ping6/ping6.c:1.99 Mon Apr 23 18:37:19 2018 +++ src/sbin/ping6/ping6.c Mon Apr 23 18:44:39 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.99 2018/04/23 18:37:19 maxv Exp $ */ +/* $NetBSD: ping6.c,v 1.100 2018/04/23 18:44:39 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.99 2018/04/23 18:37:19 maxv Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.100 2018/04/23 18:44:39 maxv Exp $"); #endif #endif @@ -178,9 +178,6 @@ struct tv32 { #define F_FQDN 0x1000 #define F_INTERFACE 0x2000 #define F_SRCADDR 0x4000 -#ifdef IPV6_REACHCONF -#define F_REACHCONF 0x8000 -#endif #define F_HOSTNAME 0x1 #define F_FQDNOLD 0x2 #define F_NIGROUP 0x4 @@ -325,7 +322,7 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "init failed"); while ((ch = getopt(argc, argv, - "a:b:c:dfHg:h:I:i:l:mnNop:qRS:s:tvwWx:X:" ADDOPTS)) != -1) { + "a:b:c:dfHg:h:I:i:l:mnNop:qS:s:tvwWx:X:" ADDOPTS)) != -1) { #undef ADDOPTS switch (ch) { case 'a': @@ -484,13 +481,6 @@ main(int argc, char *argv[]) case 'q': options |= F_QUIET; break; - case 'R': -#ifdef IPV6_REACHCONF - options |= F_REACHCONF; - break; -#else - errx(1, "-R is not supported in this configuration"); -#endif case 'S': memset(, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; /* allow hostname? */ @@ -778,11 +768,6 @@ main(int argc, char *argv[]) if (hoplimit != -1) ip6optlen += CMSG_SPACE(sizeof(int)); -#ifdef IPV6_REACHCONF - if (options & F_REACHCONF) - ip6optlen += CMSG_SPACE(0); -#endif - /* set IP6 packet options */ if (ip6optlen) { if ((scmsg = (char *)malloc(ip6optlen)) == 0) @@ -819,15 +804,6 @@ main(int argc, char *argv[]) scmsgp = CMSG_NXTHDR(, scmsgp); } -#ifdef IPV6_REACHCONF - if (options & F_REACHCONF) { - scmsgp->cmsg_len = CMSG_LEN(0); - scmsgp->cmsg_level = IPPROTO_IPV6; - scmsgp->cmsg_type = IPV6_REACHCONF; - - scmsgp = CMSG_NXTHDR(, scmsgp); - } -#endif if (!(options & F_SRCADDR)) { /* @@ -2546,14 +2522,9 @@ static void usage(void) { (void)fprintf(stderr, - "usage: ping6 [-" - "dfHmNnq" -#ifdef IPV6_REACHCONF - "R" -#endif - "tvWw" - "] [-a addrtype] [-b bufsize] [-c count] [-g gateway]\n" -"\t[-h hoplimit] [-I interface] [-i wait] [-l preload]" + "usage: ping6 [-dfHmNnqtvWw] [-a addrtype] [-b bufsize]\n" + "\t[-c count] [-g gateway] [-h hoplimit] [-I interface]\n" + "\t[-i wait] [-l preload]" #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) " [-P policy]" #endif
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Mon Apr 23 18:37:20 UTC 2018 Modified Files: src/sbin/ping6: ping6.c Log Message: Fix usage(), A/E don't exist. To generate a diff of this commit: cvs rdiff -u -r1.98 -r1.99 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.98 src/sbin/ping6/ping6.c:1.99 --- src/sbin/ping6/ping6.c:1.98 Mon Apr 23 18:32:18 2018 +++ src/sbin/ping6/ping6.c Mon Apr 23 18:37:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.98 2018/04/23 18:32:18 maxv Exp $ */ +/* $NetBSD: ping6.c,v 1.99 2018/04/23 18:37:19 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.98 2018/04/23 18:32:18 maxv Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.99 2018/04/23 18:37:19 maxv Exp $"); #endif #endif @@ -2547,13 +2547,7 @@ usage(void) { (void)fprintf(stderr, "usage: ping6 [-" -#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) - "dfH" -#else - "AdEfH" -#endif - "m" - "Nnq" + "dfHmNnq" #ifdef IPV6_REACHCONF "R" #endif
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Mon Apr 23 18:32:18 UTC 2018 Modified Files: src/sbin/ping6: ping6.c Log Message: Simplify: remove #ifdefs for constants that are always defined, and remove their #else's (some of which can't compile, since they use values that since got removed). To generate a diff of this commit: cvs rdiff -u -r1.97 -r1.98 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.97 src/sbin/ping6/ping6.c:1.98 --- src/sbin/ping6/ping6.c:1.97 Mon Apr 23 10:35:20 2018 +++ src/sbin/ping6/ping6.c Mon Apr 23 18:32:18 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.97 2018/04/23 10:35:20 maxv Exp $ */ +/* $NetBSD: ping6.c,v 1.98 2018/04/23 18:32:18 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.97 2018/04/23 10:35:20 maxv Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.98 2018/04/23 18:32:18 maxv Exp $"); #endif #endif @@ -171,14 +171,9 @@ struct tv32 { #define F_RROUTE 0x0020 #define F_SO_DEBUG 0x0040 #define F_VERBOSE 0x0100 -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) #define F_POLICY 0x0400 -#else -#define F_AUTHHDR 0x0200 -#define F_ENCRYPT 0x0400 -#endif /*IPSEC_POLICY_IPSEC*/ -#endif /*IPSEC*/ +#endif #define F_NODEADDR 0x0800 #define F_FQDN 0x1000 #define F_INTERFACE 0x2000 @@ -282,11 +277,9 @@ static int pr_bitrange(u_int32_t, int, static void pr_retip(struct ip6_hdr *, u_char *); static void summary(void); static void tvsub(struct timeval *, struct timeval *); -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) static int setpolicy(int, char *); -#endif /* IPSEC_POLICY_IPSEC */ -#endif /* IPSEC */ +#endif static char *nigroup(char *); static double timespec_to_sec(const struct timespec *tp); static double diffsec(struct timespec *, struct timespec *); @@ -303,10 +296,8 @@ main(int argc, char *argv[]) char *e, *target, *ifname = NULL, *gateway = NULL; int ip6optlen = 0; struct cmsghdr *scmsgp = NULL; -#if defined(SO_SNDBUF) && defined(SO_RCVBUF) u_long lsockbufsize; int sockbufsize = 0; -#endif int usepktinfo = 0; struct in6_pktinfo *pktinfo = NULL; struct ip6_rthdr *rthdr = NULL; @@ -315,9 +306,7 @@ main(int argc, char *argv[]) char *policy_out = NULL; #endif double intval; -#ifdef IPV6_USE_MIN_MTU int mflag = 0; -#endif /* just to be sure */ memset(, 0, sizeof(smsghdr)); @@ -325,14 +314,11 @@ main(int argc, char *argv[]) preload = 0; datap = [ICMP6ECHOLEN + ICMP6ECHOTMLEN]; -#ifndef IPSEC -#define ADDOPTS -#else -#ifdef IPSEC_POLICY_IPSEC + +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) #define ADDOPTS "P:" #else -#define ADDOPTS "AE" -#endif /*IPSEC_POLICY_IPSEC*/ +#define ADDOPTS #endif if (prog_init && prog_init() == -1) @@ -386,7 +372,6 @@ main(int argc, char *argv[]) break; } case 'b': -#if defined(SO_SNDBUF) && defined(SO_RCVBUF) errno = 0; e = NULL; lsockbufsize = strtoul(optarg, , 10); @@ -394,10 +379,6 @@ main(int argc, char *argv[]) if (errno || !*optarg || *e || (u_long)sockbufsize != lsockbufsize) errx(1, "invalid socket buffer size"); -#else - errx(1, -"-b option ignored: SO_SNDBUF/SO_RCVBUF socket options not supported"); -#endif break; case 'c': l = strtol(optarg, , 10); @@ -485,13 +466,8 @@ main(int argc, char *argv[]) preload = l; break; case 'm': -#ifdef IPV6_USE_MIN_MTU mflag++; break; -#else - errx(1, "-%c is not supported on this platform", ch); - /*NOTREACHED*/ -#endif case 'n': options &= ~F_HOSTNAME; break; @@ -573,8 +549,8 @@ main(int argc, char *argv[]) errx(EXIT_FAILURE, "Bad/invalid deadline time: " "%s", optarg); break; -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC + +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) case 'P': options |= F_POLICY; if (!strncmp("in", optarg, 2)) { @@ -586,15 +562,7 @@ main(int argc, char *argv[]) } else errx(1, "invalid security policy"); break; -#else - case 'A': - options |= F_AUTHHDR; - break; - case 'E': - options |= F_ENCRYPT; - break; -#endif /*IPSEC_POLICY_IPSEC*/ -#endif /*IPSEC*/ +#endif default: usage(); /*NOTREACHED*/ @@ -758,34 +726,13 @@ main(int argc, char *argv[]) err(1, "setsockopt(IPV6_RECVPATHMTU)"); } -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) if (options & F_POLICY) { if (setpolicy(s, policy_in) < 0) errx(1, "%s", ipsec_strerror()); if (setpolicy(s, policy_out) < 0) errx(1, "%s", ipsec_strerror()); } -#else - if (options & F_AUTHHDR) { - optval = IPSEC_LEVEL_REQUIRE; -#ifdef
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Mon Apr 23 10:35:21 UTC 2018 Modified Files: src/sbin/ping6: ping6.c Log Message: Remove dead/broken code, we want to favor RFC3542 over RFC2292. No functional change. traceroute6 and rtadvd did the same. To generate a diff of this commit: cvs rdiff -u -r1.96 -r1.97 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.96 src/sbin/ping6/ping6.c:1.97 --- src/sbin/ping6/ping6.c:1.96 Mon Apr 23 07:25:36 2018 +++ src/sbin/ping6/ping6.c Mon Apr 23 10:35:20 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.96 2018/04/23 07:25:36 wiz Exp $ */ +/* $NetBSD: ping6.c,v 1.97 2018/04/23 10:35:20 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.96 2018/04/23 07:25:36 wiz Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.97 2018/04/23 10:35:20 maxv Exp $"); #endif #endif @@ -681,24 +681,14 @@ main(int argc, char *argv[]) if ((options & F_VERBOSE) != 0) { int opton = 1; -#ifdef IPV6_RECVHOPOPTS if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPOPTS, , sizeof(opton))) err(1, "setsockopt(IPV6_RECVHOPOPTS)"); -#else /* old adv. API */ - if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_HOPOPTS, , - sizeof(opton))) - err(1, "setsockopt(IPV6_HOPOPTS)"); -#endif -#ifdef IPV6_RECVDSTOPTS + if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RECVDSTOPTS, , sizeof(opton))) err(1, "setsockopt(IPV6_RECVDSTOPTS)"); -#else /* old adv. API */ - if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_DSTOPTS, , - sizeof(opton))) - err(1, "setsockopt(IPV6_DSTOPTS)"); -#endif + #ifdef IPV6_RECVRTHDRDSTOPTS if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RECVRTHDRDSTOPTS, , sizeof(opton))) @@ -754,23 +744,19 @@ main(int argc, char *argv[]) if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, , sizeof(optval)) == -1) err(1, "IPV6_MULTICAST_HOPS"); -#ifdef IPV6_USE_MIN_MTU + if (mflag != 1) { optval = mflag > 1 ? 0 : 1; if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_USE_MIN_MTU, , sizeof(optval)) == -1) err(1, "setsockopt(IPV6_USE_MIN_MTU)"); - } -#ifdef IPV6_RECVPATHMTU - else { + } else { optval = 1; if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RECVPATHMTU, , sizeof(optval)) == -1) err(1, "setsockopt(IPV6_RECVPATHMTU)"); } -#endif /* IPV6_RECVPATHMTU */ -#endif /* IPV6_USE_MIN_MTU */ #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC @@ -825,15 +811,9 @@ main(int argc, char *argv[]) if ((options & F_VERBOSE) != 0) { int opton = 1; -#ifdef IPV6_RECVRTHDR if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RECVRTHDR, , sizeof(opton))) err(1, "setsockopt(IPV6_RECVRTHDR)"); -#else /* old adv. API */ - if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RTHDR, , - sizeof(opton))) - err(1, "setsockopt(IPV6_RTHDR)"); -#endif } /* @@ -975,25 +955,14 @@ main(int argc, char *argv[]) optval = 1; #ifndef USE_SIN6_SCOPE_ID -#ifdef IPV6_RECVPKTINFO if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, , sizeof(optval)) < 0) warn("setsockopt(IPV6_RECVPKTINFO)"); /* XXX err? */ -#else /* old adv. API */ - if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_PKTINFO, , - sizeof(optval)) < 0) - warn("setsockopt(IPV6_PKTINFO)"); /* XXX err? */ #endif -#endif /* USE_SIN6_SCOPE_ID */ -#ifdef IPV6_RECVHOPLIMIT + if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, , sizeof(optval)) < 0) warn("setsockopt(IPV6_RECVHOPLIMIT)"); /* XXX err? */ -#else /* old adv. API */ - if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_HOPLIMIT, , - sizeof(optval)) < 0) - warn("setsockopt(IPV6_HOPLIMIT)"); /* XXX err? */ -#endif printf("PING6(%lu=40+8+%lu bytes) ", (unsigned long)(40 + pingerlen()), (unsigned long)(pingerlen() - 8));
CVS commit: src/sbin/ping6
Module Name:src Committed By: wiz Date: Mon Apr 23 07:25:36 UTC 2018 Modified Files: src/sbin/ping6: ping6.8 ping6.c Log Message: Sort options. Sort option descriptions. Remove Tn. Sync usage (more) with man page. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/sbin/ping6/ping6.8 cvs rdiff -u -r1.95 -r1.96 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.8 diff -u src/sbin/ping6/ping6.8:1.31 src/sbin/ping6/ping6.8:1.32 --- src/sbin/ping6/ping6.8:1.31 Mon Apr 23 06:51:25 2018 +++ src/sbin/ping6/ping6.8 Mon Apr 23 07:25:36 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: ping6.8,v 1.31 2018/04/23 06:51:25 maxv Exp $ +.\" $NetBSD: ping6.8,v 1.32 2018/04/23 07:25:36 wiz Exp $ .\" $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -33,9 +33,7 @@ .Os .Sh NAME .Nm ping6 -.Nd send -.Tn ICMPv6 ECHO_REQUEST -packets to network hosts +.Nd send ICMPv6 ECHO_REQUEST packets to network hosts .Sh SYNOPSIS .Nm ping6 .\" without IPsec, or new IPsec @@ -50,28 +48,24 @@ packets to network hosts .Op Fl I Ar interface .Op Fl i Ar wait .Op Fl l Ar preload -.Op Fl p Ar pattern .\" new IPsec .Op Fl P Ar policy +.Op Fl p Ar pattern .Op Fl S Ar sourceaddr .Op Fl s Ar packetsize -.Op Fl x Ar maxwait .Op Fl X Ar deadline +.Op Fl x Ar maxwait .Ar host .Sh DESCRIPTION .Nm -uses the -.Tn ICMPv6 -protocol's mandatory -.Tn ICMP6_ECHO_REQUEST +uses the ICMPv6 protocol's mandatory +.Dv ICMP6_ECHO_REQUEST datagram to elicit an -.Tn ICMP6_ECHO_REPLY +.Dv ICMP6_ECHO_REPLY from a host or gateway. -.Tn ICMP6_ECHO_REQUEST +.Dv ICMP6_ECHO_REQUEST datagrams (``pings'') have an IPv6 header, -and -.Tn ICMPv6 -header formatted as documented in RFC 2463. +and ICMPv6 header formatted as documented in RFC 2463. The options are as follows: .Bl -tag -width Ds .\" old IPsec @@ -110,7 +104,7 @@ Set socket buffer size. Stop after sending .Pq and receiving .Ar count -.Tn ECHO_RESPONSE +.Dv ECHO_RESPONSE packets. .It Fl d Set the @@ -124,11 +118,11 @@ Flood ping. Outputs packets as fast as they come back or one hundred times per second, whichever is more. For every -.Tn ECHO_REQUEST +.Dv ECHO_REQUEST sent a period .Dq \&. is printed, while for every -.Tn ECHO_REPLY +.Dv ECHO_REPLY received a backspace is printed. This provides a rapid display of how many packets are being dropped. Only the super-user may use this option. @@ -178,9 +172,6 @@ when the option is specified once, the b unicast packets. When the option is specified more than once, it will be disabled for both unicast and multicast packets. -.It Fl n -Numeric output only. -No attempt will be made to lookup symbolic names from addresses in the reply. .It Fl N Probe node information multicast group .Pq Li ff02::2:: . @@ -194,8 +185,14 @@ Since node information multicast group i outgoing interface needs to be specified by .Fl I option. +.It Fl n +Numeric output only. +No attempt will be made to lookup symbolic names from addresses in the reply. .It Fl o Exit successfully after receiving one reply packet. +.It Fl P Ar policy +.Ar policy +specifies IPsec policy to be used for the probe. .It Fl p Ar pattern You may specify up to 16 .Dq pad @@ -206,9 +203,6 @@ For example, will cause the sent packet to be filled with all ones. .\" new IPsec -.It Fl P Ar policy -.Ar policy -specifies IPsec policy to be used for the probe. .It Fl q Quiet output. Nothing is displayed except the summary lines at startup time and @@ -226,12 +220,8 @@ The source address must be one of the un and must be numeric. .It Fl s Ar packetsize Specifies the number of data bytes to be sent. -The default is 56, which translates into 64 -.Tn ICMP -data bytes when combined -with the 8 bytes of -.Tn ICMP -header data. +The default is 56, which translates into 64 ICMP data bytes when combined +with the 8 bytes of ICMP header data. You may need to specify .Fl b as well to extend socket buffer size. @@ -244,16 +234,9 @@ has no effect if is specified. .It Fl v Verbose output. -.Tn ICMP -packets other than -.Tn ECHO_RESPONSE +ICMP packets other than +.Dv ECHO_RESPONSE that are received are listed. -.It Fl w -Generate ICMPv6 Node Information DNS Name query, rather than echo-request. -.Fl s -has no effect if -.Fl w -is specified. .It Fl W Same as .Fl w , @@ -263,13 +246,19 @@ This option is present for backward comp has no effect if .Fl w is specified. -.It Fl x Ar maxwait -Time in milliseconds to wait for a reply for each packet sent. +.It Fl w +Generate ICMPv6 Node Information DNS Name query, rather than echo-request. +.Fl s +has no effect if +.Fl w +is specified. .It Fl X Ar deadline Specify a timeout, in seconds, before ping exits regardless of how many packets have been received. .It Ar host IPv6 address of the final destination
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Mon Apr 23 06:51:26 UTC 2018 Modified Files: src/sbin/ping6: ping6.8 ping6.c Log Message: Remove the "hops" parameter, it uses RH0, which is deprecated by RFC5095, and doesn't work on modern networks anymore. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/sbin/ping6/ping6.8 cvs rdiff -u -r1.94 -r1.95 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.8 diff -u src/sbin/ping6/ping6.8:1.30 src/sbin/ping6/ping6.8:1.31 --- src/sbin/ping6/ping6.8:1.30 Fri May 15 08:02:39 2015 +++ src/sbin/ping6/ping6.8 Mon Apr 23 06:51:25 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: ping6.8,v 1.30 2015/05/15 08:02:39 kefren Exp $ +.\" $NetBSD: ping6.8,v 1.31 2018/04/23 06:51:25 maxv Exp $ .\" $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 23, 2015 +.Dd April 23, 2018 .Dt PING6 8 .Os .Sh NAME @@ -57,7 +57,6 @@ packets to network hosts .Op Fl s Ar packetsize .Op Fl x Ar maxwait .Op Fl X Ar deadline -.Op Ar hops ... .Ar host .Sh DESCRIPTION .Nm @@ -217,16 +216,9 @@ when finished. .It Fl R Make the kernel believe that the target .Ar host -.Po -or the first -.Ar hop -if you specify -.Ar hops -.Pc is reachable, by injecting upper-layer reachability confirmation hint. The option is meaningful only if the target .Ar host -.Pq or the first hop is a neighbor. .It Fl S Ar sourceaddr Specifies the source address of request packets. @@ -276,9 +268,6 @@ Time in milliseconds to wait for a reply .It Fl X Ar deadline Specify a timeout, in seconds, before ping exits regardless of how many packets have been received. -.It Ar hops -IPv6 addresses for intermediate nodes, -which will be put into type 0 routing header. .It Ar host IPv6 address of the final destination node. .El Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.94 src/sbin/ping6/ping6.c:1.95 --- src/sbin/ping6/ping6.c:1.94 Sun Apr 15 08:27:21 2018 +++ src/sbin/ping6/ping6.c Mon Apr 23 06:51:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.94 2018/04/15 08:27:21 maxv Exp $ */ +/* $NetBSD: ping6.c,v 1.95 2018/04/23 06:51:25 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.94 2018/04/15 08:27:21 maxv Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.95 2018/04/23 06:51:25 maxv Exp $"); #endif #endif @@ -315,7 +315,6 @@ main(int argc, char *argv[]) char *policy_out = NULL; #endif double intval; - size_t rthlen; #ifdef IPV6_USE_MIN_MTU int mflag = 0; #endif @@ -605,21 +604,11 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc < 1) { + if (argc != 1) { usage(); /*NOTREACHED*/ } - if (argc > 1) { - rthlen = CMSG_SPACE(inet6_rth_space(IPV6_RTHDR_TYPE_0, - argc - 1)); - if (rthlen == 0) { - errx(1, "too many intermediate hops"); - /*NOTREACHED*/ - } - ip6optlen += rthlen; - } - if (options & F_NIGROUP) { target = nigroup(argv[argc - 1]); if (target == NULL) { @@ -913,39 +902,6 @@ main(int argc, char *argv[]) } #endif - if (argc > 1) { /* some intermediate addrs are specified */ - int hops, error; - int rthdrlen; - - rthdrlen = inet6_rth_space(IPV6_RTHDR_TYPE_0, argc - 1); - scmsgp->cmsg_len = CMSG_LEN(rthdrlen); - scmsgp->cmsg_level = IPPROTO_IPV6; - scmsgp->cmsg_type = IPV6_RTHDR; - rthdr = (struct ip6_rthdr *)CMSG_DATA(scmsgp); - rthdr = inet6_rth_init((void *)rthdr, rthdrlen, - IPV6_RTHDR_TYPE_0, argc - 1); - if (rthdr == NULL) - errx(1, "can't initialize rthdr"); - - for (hops = 0; hops < argc - 1; hops++) { - struct addrinfo *iaip; - - if ((error = getaddrinfo(argv[hops], NULL, , - ))) -errx(1, "%s", gai_strerror(error)); - if (SIN6(iaip->ai_addr)->sin6_family != AF_INET6) -errx(1, -"bad addr family of an intermediate addr"); - - if (inet6_rth_add(rthdr, - &(SIN6(iaip->ai_addr))->sin6_addr)) -errx(1, "can't add an intermediate node"); - freeaddrinfo(iaip); - } - - scmsgp = CMSG_NXTHDR(, scmsgp); - } - if (!(options & F_SRCADDR)) { /* * get the source address. XXX since we revoked the root @@ -2699,6 +2655,6 @@ usage(void) "[-X deadline]\n" "\t[-x maxwait] [-S sourceaddr] " "[-s packetsize] [-h hoplimit]\n" - "\t[-g gateway] [hops...] host\n"); + "\t[-g gateway] host\n"); exit(1); }
CVS commit: src/sbin/ping6
Module Name:src Committed By: maxv Date: Sun Apr 15 08:27:21 UTC 2018 Modified Files: src/sbin/ping6: ping6.c Log Message: typo in comment To generate a diff of this commit: cvs rdiff -u -r1.93 -r1.94 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.93 src/sbin/ping6/ping6.c:1.94 --- src/sbin/ping6/ping6.c:1.93 Sun Dec 18 01:30:54 2016 +++ src/sbin/ping6/ping6.c Sun Apr 15 08:27:21 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.93 2016/12/18 01:30:54 dholland Exp $ */ +/* $NetBSD: ping6.c,v 1.94 2018/04/15 08:27:21 maxv Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.93 2016/12/18 01:30:54 dholland Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.94 2018/04/15 08:27:21 maxv Exp $"); #endif #endif @@ -686,7 +686,7 @@ main(int argc, char *argv[]) } /* - * let the kerel pass extension headers of incoming packets, + * let the kernel pass extension headers of incoming packets, * for privileged socket options */ if ((options & F_VERBOSE) != 0) {
CVS commit: src/sbin/ping6
Module Name:src Committed By: dholland Date: Sun Dec 18 01:30:54 UTC 2016 Modified Files: src/sbin/ping6: ping6.c Log Message: Merge the PR 36997 fixes into ping6. It already didn't accept too small or wildly too large intervals, but it did allow intervals that failed at poll(). Since that's signed integer overflow and thus UB, better not to. To generate a diff of this commit: cvs rdiff -u -r1.92 -r1.93 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.92 src/sbin/ping6/ping6.c:1.93 --- src/sbin/ping6/ping6.c:1.92 Mon Feb 29 16:25:06 2016 +++ src/sbin/ping6/ping6.c Sun Dec 18 01:30:54 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.92 2016/02/29 16:25:06 riastradh Exp $ */ +/* $NetBSD: ping6.c,v 1.93 2016/12/18 01:30:54 dholland Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.92 2016/02/29 16:25:06 riastradh Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.93 2016/12/18 01:30:54 dholland Exp $"); #endif #endif @@ -297,6 +297,7 @@ main(int argc, char *argv[]) { struct addrinfo hints; u_int i, packlen; + long l; int ch, hold, preload, optval, ret_ga; u_char *datap, *packet; char *e, *target, *ifname = NULL, *gateway = NULL; @@ -400,10 +401,16 @@ main(int argc, char *argv[]) #endif break; case 'c': - npackets = strtol(optarg, , 10); - if (npackets <= 0 || *optarg == '\0' || *e != '\0') + l = strtol(optarg, , 10); + if (l <= 0 || *optarg == '\0' || *e != '\0') errx(1, "illegal number of packets -- %s", optarg); +#if INT_MAX < LONG_MAX + if (l > INT_MAX) +errx(EXIT_FAILURE, +"Too many packets to count: %ld", l); +#endif + npackets = l; break; case 'd': options |= F_SO_DEBUG; @@ -447,15 +454,18 @@ main(int argc, char *argv[]) errx(1, "%s: only root may use interval < 1s", strerror(EPERM)); } - interval.tv_sec = (long)intval; + if (intval > INT_MAX/1000.0 - 1.0) { +errx(1, "Interval %s too large", optarg); + } + interval.tv_sec = (time_t)intval; interval.tv_nsec = (long)((intval - interval.tv_sec) * 10); - if (interval.tv_sec < 0) + if (interval.tv_sec < 0 || interval.tv_nsec < 0) errx(1, "illegal timing interval %s", optarg); /* less than 1/hz does not make sense */ if (interval.tv_sec == 0 && interval.tv_nsec < 1000) { -warnx("too small interval, raised to 0.01"); +warnx("Interval too small; raised to 0.01"); interval.tv_nsec = 1000; } options |= F_INTERVAL; @@ -465,9 +475,15 @@ main(int argc, char *argv[]) errno = EPERM; errx(1, "Must be superuser to preload"); } - preload = strtol(optarg, , 10); - if (preload < 0 || *optarg == '\0' || *e != '\0') + l = strtol(optarg, , 10); + if (l < 0 || *optarg == '\0' || *e != '\0') errx(1, "illegal preload value -- %s", optarg); +#if INT_MAX < LONG_MAX + if (l > INT_MAX) +errx(EXIT_FAILURE, +"Too many preload packets: %ld", l); +#endif + preload = l; break; case 'm': #ifdef IPV6_USE_MIN_MTU
CVS commit: src/sbin/ping6
Module Name:src Committed By: riastradh Date: Mon Feb 29 16:25:06 UTC 2016 Modified Files: src/sbin/ping6: ping6.c Log Message: #ifdef forward declaration of setpolicy like definition. To generate a diff of this commit: cvs rdiff -u -r1.91 -r1.92 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.91 src/sbin/ping6/ping6.c:1.92 --- src/sbin/ping6/ping6.c:1.91 Wed Nov 4 08:07:54 2015 +++ src/sbin/ping6/ping6.c Mon Feb 29 16:25:06 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.91 2015/11/04 08:07:54 ozaki-r Exp $ */ +/* $NetBSD: ping6.c,v 1.92 2016/02/29 16:25:06 riastradh Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.91 2015/11/04 08:07:54 ozaki-r Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.92 2016/02/29 16:25:06 riastradh Exp $"); #endif #endif @@ -282,7 +282,11 @@ static int pr_bitrange(u_int32_t, int, static void pr_retip(struct ip6_hdr *, u_char *); static void summary(void); static void tvsub(struct timeval *, struct timeval *); +#ifdef IPSEC +#ifdef IPSEC_POLICY_IPSEC static int setpolicy(int, char *); +#endif /* IPSEC_POLICY_IPSEC */ +#endif /* IPSEC */ static char *nigroup(char *); static double timespec_to_sec(const struct timespec *tp); static double diffsec(struct timespec *, struct timespec *);
CVS commit: src/sbin/ping6
Module Name:src Committed By: ozaki-r Date: Wed Nov 4 08:07:54 UTC 2015 Modified Files: src/sbin/ping6: ping6.c Log Message: Fix rump.ping6 -c N (N > 1) doesn't work 2nd packet and subsequent packets are sent based on SIGALRM and it depends on poll(2) returns with EINTR by the signal. However, currently poll is rump-ified while signals aren't so the signal doesn't wake up poll and ping6 doesn't work expectedly. Rump-ifying signals is unsure (nobody does it for now) and the combination use of signals and poll makes the logic a bit complex. So let's fix the defect by stopping using signals for packet transmissions. The new logic is derived from ping(8). Bonus: ping6 -i 0.01 works as we expect now while the original didn't work enough fast. To generate a diff of this commit: cvs rdiff -u -r1.90 -r1.91 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.90 src/sbin/ping6/ping6.c:1.91 --- src/sbin/ping6/ping6.c:1.90 Wed Nov 4 07:59:25 2015 +++ src/sbin/ping6/ping6.c Wed Nov 4 08:07:54 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.90 2015/11/04 07:59:25 ozaki-r Exp $ */ +/* $NetBSD: ping6.c,v 1.91 2015/11/04 08:07:54 ozaki-r Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.90 2015/11/04 07:59:25 ozaki-r Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.91 2015/11/04 08:07:54 ozaki-r Exp $"); #endif #endif @@ -229,7 +229,10 @@ static long npackets; /* max packets t static long nreceived; /* # of packets we got back */ static long nrepeats; /* number of duplicates */ static long ntransmitted; /* sequence # for outbound packets = #sent */ -static struct timeval interval = {1, 0}; /* interval between packets */ +static struct timespec interval = {1, 0}; /* interval between packets */ + +static struct timespec now, last_tx, next_tx, first_tx; +static int lastrcvd = 1; /* last ping sent has been received */ /* timing */ static int timing; /* flag to do timing */ @@ -248,21 +251,20 @@ static struct msghdr smsghdr; static struct iovec smsgiov; static char *scmsg = 0; -static volatile sig_atomic_t seenalrm; static volatile sig_atomic_t seenint; #ifdef SIGINFO static volatile sig_atomic_t seeninfo; #endif +__dead static void doit(u_char *, u_int); static void fill(char *, char *); static int get_hoplim(struct msghdr *); static int get_pathmtu(struct msghdr *); static struct in6_pktinfo *get_rcvpktinfo(struct msghdr *); static void onsignal(int); -static void retransmit(void); __dead static void onsigexit(int); static size_t pingerlen(void); -static int pinger(void); +static void pinger(void); static const char *pr_addr(struct sockaddr *, int); static void pr_icmph(struct icmp6_hdr *, u_char *); static void pr_iph(struct ip6_hdr *); @@ -283,17 +285,13 @@ static void tvsub(struct timeval *, str static int setpolicy(int, char *); static char *nigroup(char *); static double timespec_to_sec(const struct timespec *tp); +static double diffsec(struct timespec *, struct timespec *); __dead static void usage(void); int main(int argc, char *argv[]) { - struct itimerval itimer; - struct sockaddr_in6 from; - int timeout; struct addrinfo hints; - struct pollfd fdmaskp[1]; - int cc; u_int i, packlen; int ch, hold, preload, optval, ret_ga; u_char *datap, *packet; @@ -316,8 +314,6 @@ main(int argc, char *argv[]) #ifdef IPV6_USE_MIN_MTU int mflag = 0; #endif - struct timespec now; - double exitat = 0.0; /* just to be sure */ memset(, 0, sizeof(smsghdr)); @@ -415,6 +411,8 @@ main(int argc, char *argv[]) } options |= F_FLOOD; setbuf(stdout, NULL); + interval.tv_sec = 0; + interval.tv_nsec = 10 * 1000 * 1000; /* 10 ms */ break; case 'g': gateway = optarg; @@ -446,14 +444,15 @@ main(int argc, char *argv[]) strerror(EPERM)); } interval.tv_sec = (long)intval; - interval.tv_usec = - (long)((intval - interval.tv_sec) * 100); + interval.tv_nsec = + (long)((intval - interval.tv_sec) * 10); 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 < 1) { + if (interval.tv_sec == 0 && + interval.tv_nsec < 1000) { warnx("too small interval, raised to 0.01"); -interval.tv_usec = 1; +interval.tv_nsec = 1000; } options |= F_INTERVAL; break; @@ -1026,50 +1025,51 @@ main(int argc, char *argv[]) printf("%s\n", pr_addr((struct sockaddr *), sizeof(dst))); while (preload--) /* Fire off them quickies. */ - (void)pinger(); + pinger(); (void)signal(SIGINT, onsignal); #ifdef SIGINFO
CVS commit: src/sbin/ping6
Module Name:src Committed By: knakahara Date: Wed Nov 4 01:14:02 UTC 2015 Modified Files: src/sbin/ping6: ping6.c ping6_hostops.c ping6_rumpops.c prog_ops.h Log Message: rump.ping6 supports "-S" option. To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/sbin/ping6/ping6.c cvs rdiff -u -r1.1 -r1.2 src/sbin/ping6/ping6_hostops.c \ src/sbin/ping6/ping6_rumpops.c src/sbin/ping6/prog_ops.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.88 src/sbin/ping6/ping6.c:1.89 --- src/sbin/ping6/ping6.c:1.88 Thu Aug 6 14:45:54 2015 +++ src/sbin/ping6/ping6.c Wed Nov 4 01:14:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.88 2015/08/06 14:45:54 ozaki-r Exp $ */ +/* $NetBSD: ping6.c,v 1.89 2015/11/04 01:14:02 knakahara Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.88 2015/08/06 14:45:54 ozaki-r Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.89 2015/11/04 01:14:02 knakahara Exp $"); #endif #endif @@ -636,7 +636,7 @@ main(int argc, char *argv[]) /* set the source address if specified. */ if ((options & F_SRCADDR) && - bind(s, (struct sockaddr *), srclen) != 0) { + prog_bind(s, (struct sockaddr *), srclen) != 0) { err(1, "bind"); } Index: src/sbin/ping6/ping6_hostops.c diff -u src/sbin/ping6/ping6_hostops.c:1.1 src/sbin/ping6/ping6_hostops.c:1.2 --- src/sbin/ping6/ping6_hostops.c:1.1 Thu Aug 6 14:45:54 2015 +++ src/sbin/ping6/ping6_hostops.c Wed Nov 4 01:14:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6_hostops.c,v 1.1 2015/08/06 14:45:54 ozaki-r Exp $ */ +/* $NetBSD: ping6_hostops.c,v 1.2 2015/11/04 01:14:02 knakahara Exp $ */ /* * Copyright (c) 2015 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: ping6_hostops.c,v 1.1 2015/08/06 14:45:54 ozaki-r Exp $"); +__RCSID("$NetBSD: ping6_hostops.c,v 1.2 2015/11/04 01:14:02 knakahara Exp $"); #endif /* !lint */ #include @@ -42,6 +42,7 @@ __RCSID("$NetBSD: ping6_hostops.c,v 1.1 const struct prog_ops prog_ops = { .op_socket = socket, + .op_bind = bind, .op_setsockopt = setsockopt, .op_getsockname = getsockname, .op_poll = poll, Index: src/sbin/ping6/ping6_rumpops.c diff -u src/sbin/ping6/ping6_rumpops.c:1.1 src/sbin/ping6/ping6_rumpops.c:1.2 --- src/sbin/ping6/ping6_rumpops.c:1.1 Thu Aug 6 14:45:54 2015 +++ src/sbin/ping6/ping6_rumpops.c Wed Nov 4 01:14:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6_rumpops.c,v 1.1 2015/08/06 14:45:54 ozaki-r Exp $ */ +/* $NetBSD: ping6_rumpops.c,v 1.2 2015/11/04 01:14:02 knakahara Exp $ */ /* * Copyright (c) 2015 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: ping6_rumpops.c,v 1.1 2015/08/06 14:45:54 ozaki-r Exp $"); +__RCSID("$NetBSD: ping6_rumpops.c,v 1.2 2015/11/04 01:14:02 knakahara Exp $"); #endif /* !lint */ #include @@ -47,6 +47,7 @@ const struct prog_ops prog_ops = { .op_init = rumpclient_init, .op_socket = rump_sys_socket, + .op_bind = rump_sys_bind, .op_setsockopt= rump_sys_setsockopt, .op_getsockname=rump_sys_getsockname, .op_poll = rump_sys_poll, Index: src/sbin/ping6/prog_ops.h diff -u src/sbin/ping6/prog_ops.h:1.1 src/sbin/ping6/prog_ops.h:1.2 --- src/sbin/ping6/prog_ops.h:1.1 Thu Aug 6 14:45:54 2015 +++ src/sbin/ping6/prog_ops.h Wed Nov 4 01:14:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: prog_ops.h,v 1.1 2015/08/06 14:45:54 ozaki-r Exp $ */ +/* $NetBSD: prog_ops.h,v 1.2 2015/11/04 01:14:02 knakahara Exp $ */ /* * Copyright (c) 2015 The NetBSD Foundation, Inc. @@ -36,6 +36,7 @@ struct prog_ops { int (*op_init)(void); int (*op_socket)(int, int, int); + int (*op_bind)(int, const struct sockaddr *, socklen_t); int (*op_setsockopt)(int, int, int, const void *, socklen_t); int (*op_getsockname)(int, struct sockaddr * restrict, socklen_t * restrict); @@ -56,6 +57,7 @@ extern const struct prog_ops prog_ops; #define prog_init prog_ops.op_init #define prog_socket prog_ops.op_socket +#define prog_bind prog_ops.op_bind #define prog_setsockopt prog_ops.op_setsockopt #define prog_getsockname prog_ops.op_getsockname #define prog_shutdown prog_ops.op_shutdown @@ -70,6 +72,7 @@ extern const struct prog_ops prog_ops; #else #define prog_init ((int (*)(void))NULL) #define prog_socket socket +#define prog_bind bind #define prog_setsockopt setsockopt #define prog_getsockname getsockname #define prog_shutdown shutdown
CVS commit: src/sbin/ping6
Module Name:src Committed By: ozaki-r Date: Wed Nov 4 07:59:25 UTC 2015 Modified Files: src/sbin/ping6: ping6.c Log Message: Fix exit status when -c and -X is used It exited with status 0 when at least one packet was received and timed out. However, when we specify -c N (while N > 0), we expect that it fails if it times out before all sent requests are replied. To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.89 src/sbin/ping6/ping6.c:1.90 --- src/sbin/ping6/ping6.c:1.89 Wed Nov 4 01:14:02 2015 +++ src/sbin/ping6/ping6.c Wed Nov 4 07:59:25 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.89 2015/11/04 01:14:02 knakahara Exp $ */ +/* $NetBSD: ping6.c,v 1.90 2015/11/04 07:59:25 ozaki-r Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 ( #else #include #ifndef lint -__RCSID("$NetBSD: ping6.c,v 1.89 2015/11/04 01:14:02 knakahara Exp $"); +__RCSID("$NetBSD: ping6.c,v 1.90 2015/11/04 07:59:25 ozaki-r Exp $"); #endif #endif @@ -1146,7 +1146,10 @@ main(int argc, char *argv[]) break; } summary(); - exit(nreceived == 0); + if (npackets) + exit(nreceived != npackets); + else + exit(nreceived == 0); } static void
CVS commit: src/sbin/ping6
Module Name:src Committed By: kefren Date: Fri May 15 08:02:39 UTC 2015 Modified Files: src/sbin/ping6: ping6.8 ping6.c Log Message: Add options -X for deadline and -x for reply maxwait (flag names matching FreeBSD). Unline FreeBSD, currently -x doesn't count late packets to statistics. After discussion with, and help from ozaki-r@ Should fix PR/49896 To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/sbin/ping6/ping6.8 cvs rdiff -u -r1.86 -r1.87 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.8 diff -u src/sbin/ping6/ping6.8:1.29 src/sbin/ping6/ping6.8:1.30 --- src/sbin/ping6/ping6.8:1.29 Fri Apr 24 00:42:56 2015 +++ src/sbin/ping6/ping6.8 Fri May 15 08:02:39 2015 @@ -1,4 +1,4 @@ -.\ $NetBSD: ping6.8,v 1.29 2015/04/24 00:42:56 christos Exp $ +.\ $NetBSD: ping6.8,v 1.30 2015/05/15 08:02:39 kefren Exp $ .\ $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\ .\ Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -55,6 +55,8 @@ packets to network hosts .Op Fl P Ar policy .Op Fl S Ar sourceaddr .Op Fl s Ar packetsize +.Op Fl x Ar maxwait +.Op Fl X Ar deadline .Op Ar hops ... .Ar host .Sh DESCRIPTION @@ -269,6 +271,11 @@ This option is present for backward comp has no effect if .Fl w is specified. +.It Fl x Ar maxwait +Time in milliseconds to wait for a reply for each packet sent. +.It Fl X Ar deadline +Specify a timeout, in seconds, before ping exits regardless of +how many packets have been received. .It Ar hops IPv6 addresses for intermediate nodes, which will be put into type 0 routing header. Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.86 src/sbin/ping6/ping6.c:1.87 --- src/sbin/ping6/ping6.c:1.86 Fri Apr 24 00:42:56 2015 +++ src/sbin/ping6/ping6.c Fri May 15 08:02:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.86 2015/04/24 00:42:56 christos Exp $ */ +/* $NetBSD: ping6.c,v 1.87 2015/05/15 08:02:39 kefren Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = @(#)ping.c 8.1 ( #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.86 2015/04/24 00:42:56 christos Exp $); +__RCSID($NetBSD: ping6.c,v 1.87 2015/05/15 08:02:39 kefren Exp $); #endif #endif @@ -235,6 +235,8 @@ static double tmin = 9.0; /* min static double tmax = 0.0; /* maximum round trip time */ static double tsum = 0.0; /* sum of all times, for doing average */ static double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ +static double maxwait = 0.0; /* maxwait for reply in ms */ +static double deadline = 0.0; /* max running time in seconds */ /* for node addresses */ static u_short naflags; @@ -278,6 +280,7 @@ static void summary(void); static void tvsub(struct timeval *, struct timeval *); static int setpolicy(int, char *); static char *nigroup(char *); +static double timespec_to_sec(const struct timespec *tp); __dead static void usage(void); int @@ -311,6 +314,8 @@ main(int argc, char *argv[]) #ifdef IPV6_USE_MIN_MTU int mflag = 0; #endif + struct timespec now; + double exitat = 0.0; /* just to be sure */ memset(smsghdr, 0, sizeof(smsghdr)); @@ -328,7 +333,7 @@ main(int argc, char *argv[]) #endif /*IPSEC_POLICY_IPSEC*/ #endif while ((ch = getopt(argc, argv, - a:b:c:dfHg:h:I:i:l:mnNop:qRS:s:tvwW ADDOPTS)) != -1) { + a:b:c:dfHg:h:I:i:l:mnNop:qRS:s:tvwWx:X: ADDOPTS)) != -1) { #undef ADDOPTS switch (ch) { case 'a': @@ -532,6 +537,18 @@ main(int argc, char *argv[]) options = ~F_NOUSERDATA; options |= F_FQDNOLD; break; + case 'x': + maxwait = strtod(optarg, e); + if (*e != '\0' || maxwait = 0) +errx(EXIT_FAILURE, Bad/invalid maxwait time: +%s, optarg); + break; + case 'X': + deadline = strtod(optarg, e); + if (*e != '\0' || deadline = 0) +errx(EXIT_FAILURE, Bad/invalid deadline time: +%s, optarg); +break; #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC case 'P': @@ -790,7 +807,7 @@ main(int argc, char *argv[]) } #endif /*ICMP6_FILTER*/ - /* let the kerel pass extension headers of incoming packets */ + /* let the kernel pass extension headers of incoming packets */ if ((options F_VERBOSE) != 0) { int opton = 1; @@ -1019,6 +1036,11 @@ main(int argc, char *argv[]) retransmit(); } + if (deadline 0) { + clock_gettime(CLOCK_MONOTONIC, now); + exitat = timespec_to_sec(now) + deadline; + } + seenalrm = seenint = 0; #ifdef SIGINFO seeninfo = 0; @@ -1029,6 +1051,13 @@ main(int argc, char *argv[]) u_char buf[1024]; struct iovec iov[2]; + /* check deadline */ + if (exitat 0) { + clock_gettime(CLOCK_MONOTONIC, now); + if (exitat = timespec_to_sec(now)) +break; + } + /* signal handling */ if (seenalrm) { retransmit(); @@ -1047,10 +1076,11 @@ main(int
CVS commit: src/sbin/ping6
Module Name:src Committed By: christos Date: Fri Apr 24 00:42:56 UTC 2015 Modified Files: src/sbin/ping6: ping6.8 ping6.c Log Message: Add the once -o option like ping To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/sbin/ping6/ping6.8 cvs rdiff -u -r1.85 -r1.86 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.8 diff -u src/sbin/ping6/ping6.8:1.28 src/sbin/ping6/ping6.8:1.29 --- src/sbin/ping6/ping6.8:1.28 Sun Apr 8 18:00:37 2012 +++ src/sbin/ping6/ping6.8 Thu Apr 23 20:42:56 2015 @@ -1,4 +1,4 @@ -.\ $NetBSD: ping6.8,v 1.28 2012/04/08 22:00:37 wiz Exp $ +.\ $NetBSD: ping6.8,v 1.29 2015/04/24 00:42:56 christos Exp $ .\ $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\ .\ Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -28,7 +28,7 @@ .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\ SUCH DAMAGE. .\ -.Dd May 18, 2006 +.Dd April 23, 2015 .Dt PING6 8 .Os .Sh NAME @@ -39,7 +39,7 @@ packets to network hosts .Sh SYNOPSIS .Nm ping6 .\ without IPsec, or new IPsec -.Op Fl dfHmnNqRtvwW +.Op Fl dfHmnNoqRtvwW .\ old IPsec .\ .Op Fl AdEfnNqRtvwW .Op Fl a Ar addrtype @@ -193,6 +193,8 @@ Since node information multicast group i outgoing interface needs to be specified by .Fl I option. +.It Fl o +Exit successfully after receiving one reply packet. .It Fl p Ar pattern You may specify up to 16 .Dq pad Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.85 src/sbin/ping6/ping6.c:1.86 --- src/sbin/ping6/ping6.c:1.85 Tue Sep 16 21:00:41 2014 +++ src/sbin/ping6/ping6.c Thu Apr 23 20:42:56 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.85 2014/09/17 01:00:41 ozaki-r Exp $ */ +/* $NetBSD: ping6.c,v 1.86 2015/04/24 00:42:56 christos Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = @(#)ping.c 8.1 ( #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.85 2014/09/17 01:00:41 ozaki-r Exp $); +__RCSID($NetBSD: ping6.c,v 1.86 2015/04/24 00:42:56 christos Exp $); #endif #endif @@ -189,6 +189,7 @@ struct tv32 { #define F_NIGROUP 0x4 #define F_SUPTYPES 0x8 #define F_NOMINMTU 0x10 +#define F_ONCE 0x20 #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) static u_int options; @@ -327,7 +328,7 @@ main(int argc, char *argv[]) #endif /*IPSEC_POLICY_IPSEC*/ #endif while ((ch = getopt(argc, argv, - a:b:c:dfHg:h:I:i:l:mnNp:qRS:s:tvwW ADDOPTS)) != -1) { + a:b:c:dfHg:h:I:i:l:mnNop:qRS:s:tvwW ADDOPTS)) != -1) { #undef ADDOPTS switch (ch) { case 'a': @@ -468,6 +469,9 @@ main(int argc, char *argv[]) case 'N': options |= F_NIGROUP; break; + case 'o': + options |= F_ONCE; + break; case 'p': /* fill buffer with user pattern */ options |= F_PINGFILLED; fill((char *)datap, optarg); @@ -1102,6 +1106,8 @@ main(int argc, char *argv[]) } if (npackets nreceived = npackets) break; + if (nreceived != 0 (options F_ONCE)) + break; } summary(); exit(nreceived == 0);
CVS commit: src/sbin/ping6
Module Name:src Committed By: christos Date: Tue Sep 16 21:29:13 UTC 2014 Modified Files: src/sbin/ping6: ping6.c Log Message: PR/49206: ping6 dies with SIGINT even when it just fails to ping When reusing the same handler for SIGALRM, make don't pretend you got SIGINT. To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.83 src/sbin/ping6/ping6.c:1.84 --- src/sbin/ping6/ping6.c:1.83 Fri Aug 22 16:54:29 2014 +++ src/sbin/ping6/ping6.c Tue Sep 16 17:29:12 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.83 2014/08/22 20:54:29 matt Exp $ */ +/* $NetBSD: ping6.c,v 1.84 2014/09/16 21:29:12 christos Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = @(#)ping.c 8.1 ( #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.83 2014/08/22 20:54:29 matt Exp $); +__RCSID($NetBSD: ping6.c,v 1.84 2014/09/16 21:29:12 christos Exp $); #endif #endif @@ -255,7 +255,7 @@ static int get_pathmtu(struct msghdr *) static struct in6_pktinfo *get_rcvpktinfo(struct msghdr *); static void onsignal(int); static void retransmit(void); -__dead static void onint(int); +__dead static void onsigexit(int); static size_t pingerlen(void); static int pinger(void); static const char *pr_addr(struct sockaddr *, int); @@ -1032,7 +1032,7 @@ main(int argc, char *argv[]) continue; } if (seenint) { - onint(SIGINT); + onsigexit(SIGINT); seenint = 0; continue; } @@ -1154,7 +1154,7 @@ retransmit(void) itimer.it_interval.tv_usec = 0; itimer.it_value.tv_usec = 0; - (void)signal(SIGALRM, onint); + (void)signal(SIGALRM, onsigexit); (void)setitimer(ITIMER_REAL, itimer, NULL); } @@ -2055,17 +2055,18 @@ tvsub(struct timeval *out, struct timeva } /* - * onint -- - * SIGINT handler. + * onsigexit -- */ /* ARGSUSED */ static void -onint(int notused) +onsigexit(int sig) { summary(); - (void)signal(SIGINT, SIG_DFL); - (void)kill(getpid(), SIGINT); + if (sig == SIGINT) { + (void)signal(SIGINT, SIG_DFL); + (void)kill(getpid(), SIGINT); + } /* NOTREACHED */ exit(1);
CVS commit: src/sbin/ping6
Module Name:src Committed By: ozaki-r Date: Wed Sep 17 01:00:41 UTC 2014 Modified Files: src/sbin/ping6: ping6.c Log Message: Remove out-of-date comments To generate a diff of this commit: cvs rdiff -u -r1.84 -r1.85 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.84 src/sbin/ping6/ping6.c:1.85 --- src/sbin/ping6/ping6.c:1.84 Tue Sep 16 21:29:12 2014 +++ src/sbin/ping6/ping6.c Wed Sep 17 01:00:41 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.84 2014/09/16 21:29:12 christos Exp $ */ +/* $NetBSD: ping6.c,v 1.85 2014/09/17 01:00:41 ozaki-r Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = @(#)ping.c 8.1 ( #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.84 2014/09/16 21:29:12 christos Exp $); +__RCSID($NetBSD: ping6.c,v 1.85 2014/09/17 01:00:41 ozaki-r Exp $); #endif #endif @@ -2057,7 +2057,6 @@ tvsub(struct timeval *out, struct timeva /* * onsigexit -- */ -/* ARGSUSED */ static void onsigexit(int sig) { @@ -2068,7 +2067,6 @@ onsigexit(int sig) (void)kill(getpid(), SIGINT); } - /* NOTREACHED */ exit(1); }
CVS commit: src/sbin/ping6
Module Name:src Committed By: matt Date: Fri Aug 22 20:54:29 UTC 2014 Modified Files: src/sbin/ping6: ping6.c Log Message: Rework to be avoid a conditional assignment which results in: sbin/ping6/ping6.c:1879:8: error: 'cbit.skip' may be used uninitialized in this function [-Werror=maybe-uninitialized] cur += ntohs(cbit.skip) * 32; To generate a diff of this commit: cvs rdiff -u -r1.82 -r1.83 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.82 src/sbin/ping6/ping6.c:1.83 --- src/sbin/ping6/ping6.c:1.82 Sat Oct 19 01:09:16 2013 +++ src/sbin/ping6/ping6.c Fri Aug 22 20:54:29 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.82 2013/10/19 01:09:16 christos Exp $ */ +/* $NetBSD: ping6.c,v 1.83 2014/08/22 20:54:29 matt Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = @(#)ping.c 8.1 ( #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.82 2013/10/19 01:09:16 christos Exp $); +__RCSID($NetBSD: ping6.c,v 1.83 2014/08/22 20:54:29 matt Exp $); #endif #endif @@ -125,6 +125,7 @@ __RCSID($NetBSD: ping6.c,v 1.82 2013/10 #include fcntl.h #include math.h #include signal.h +#include stdbool.h #include stdio.h #include stdlib.h #include string.h @@ -1844,6 +1845,7 @@ pr_suptypes(struct icmp6_nodeinfo *ni /* } while (cp end) { + size_t skip = 0; clen = (size_t)(end - cp); if ((ni-ni_flags NI_SUPTYPE_FLAG_COMPRESS) == 0) { if (clen == 0 || clen MAXQTYPES / 8 || @@ -1860,8 +1862,8 @@ pr_suptypes(struct icmp6_nodeinfo *ni /* return; cp += sizeof(cbit); clen = ntohs(cbit.words) * sizeof(v); - if (cur + clen * 8 + (u_long)ntohs(cbit.skip) * 32 - MAXQTYPES) + skip = (size_t)ntohs(cbit.skip) * 32; + if (cur + clen * 8 + skip MAXQTYPES) return; } @@ -1874,9 +1876,7 @@ pr_suptypes(struct icmp6_nodeinfo *ni /* b = pr_bitrange(0, (int)(cur + off * 8), b); cp += clen; - cur += clen * 8; - if ((ni-ni_flags NI_SUPTYPE_FLAG_COMPRESS) != 0) - cur += ntohs(cbit.skip) * 32; + cur += clen * 8 + skip; } }
CVS commit: src/sbin/ping6
Module Name:src Committed By: christos Date: Sat Oct 19 01:09:16 UTC 2013 Modified Files: src/sbin/ping6: ping6.c Log Message: avoit type punning To generate a diff of this commit: cvs rdiff -u -r1.81 -r1.82 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.81 src/sbin/ping6/ping6.c:1.82 --- src/sbin/ping6/ping6.c:1.81 Mon Sep 10 00:32:24 2012 +++ src/sbin/ping6/ping6.c Fri Oct 18 21:09:16 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.81 2012/09/10 04:32:24 msaitoh Exp $ */ +/* $NetBSD: ping6.c,v 1.82 2013/10/19 01:09:16 christos Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = @(#)ping.c 8.1 ( #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.81 2012/09/10 04:32:24 msaitoh Exp $); +__RCSID($NetBSD: ping6.c,v 1.82 2013/10/19 01:09:16 christos Exp $); #endif #endif @@ -703,8 +703,10 @@ main(int argc, char *argv[]) ident = arc4random() 0x; memset(nonce, 0, sizeof(nonce)); - for (i = 0; i sizeof(nonce); i += sizeof(u_int32_t)) - *((u_int32_t *)nonce[i]) = arc4random(); + for (i = 0; i sizeof(nonce); i += sizeof(u_int32_t)) { + uint32_t r = arc4random(); + memcpy(nonce[i], r, sizeof(r)); + } hold = 1; @@ -1019,7 +1021,6 @@ main(int argc, char *argv[]) for (;;) { struct msghdr m; - struct cmsghdr *cm; u_char buf[1024]; struct iovec iov[2]; @@ -1067,7 +1068,6 @@ main(int argc, char *argv[]) iov[0].iov_len = packlen; m.msg_iov = iov; m.msg_iovlen = 1; - cm = (struct cmsghdr *)buf; m.msg_control = (caddr_t)buf; m.msg_controllen = sizeof(buf);
CVS commit: src/sbin/ping6
Module Name:src Committed By: msaitoh Date: Mon Sep 10 04:32:24 UTC 2012 Modified Files: src/sbin/ping6: ping6.c Log Message: Accept -s 0 To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.80 src/sbin/ping6/ping6.c:1.81 --- src/sbin/ping6/ping6.c:1.80 Wed Jan 4 16:09:42 2012 +++ src/sbin/ping6/ping6.c Mon Sep 10 04:32:24 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.80 2012/01/04 16:09:42 drochner Exp $ */ +/* $NetBSD: ping6.c,v 1.81 2012/09/10 04:32:24 msaitoh Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ static char sccsid[] = @(#)ping.c 8.1 ( #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.80 2012/01/04 16:09:42 drochner Exp $); +__RCSID($NetBSD: ping6.c,v 1.81 2012/09/10 04:32:24 msaitoh Exp $); #endif #endif @@ -504,7 +504,7 @@ main(int argc, char *argv[]) break; case 's': /* size of packet to send */ datalen = strtol(optarg, e, 10); - if (datalen = 0 || *optarg == '\0' || *e != '\0') + if (datalen 0 || *optarg == '\0' || *e != '\0') errx(1, illegal datalen value -- %s, optarg); if (datalen MAXDATALEN) { errx(1,
CVS commit: src/sbin/ping6
Module Name:src Committed By: riz Date: Wed Aug 31 22:05:57 UTC 2011 Modified Files: src/sbin/ping6: ping6.c Log Message: Remove erroneous seq=ntohs(seq) introduced in rev. 1.74, which caused icmp_seq numbers to increment by 256 instead of 1 on LE platforms. To generate a diff of this commit: cvs rdiff -u -r1.75 -r1.76 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.75 src/sbin/ping6/ping6.c:1.76 --- src/sbin/ping6/ping6.c:1.75 Sat Aug 27 18:43:24 2011 +++ src/sbin/ping6/ping6.c Wed Aug 31 22:05:57 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.75 2011/08/27 18:43:24 joerg Exp $ */ +/* $NetBSD: ping6.c,v 1.76 2011/08/31 22:05:57 riz Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.75 2011/08/27 18:43:24 joerg Exp $); +__RCSID($NetBSD: ping6.c,v 1.76 2011/08/31 22:05:57 riz Exp $); #endif #endif @@ -1201,7 +1201,6 @@ memset(icp, 0, sizeof(*icp)); icp-icmp6_cksum = 0; seq = ntransmitted++; - seq = ntohs(seq); CLR(seq % mx_dup_ck); if (options F_FQDN) {
CVS commit: src/sbin/ping6
Module Name:src Committed By: christos Date: Wed Aug 31 22:27:27 UTC 2011 Modified Files: src/sbin/ping6: ping6.c Log Message: put back the byte swapping code, and remove the double byte swapping. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.76 src/sbin/ping6/ping6.c:1.77 --- src/sbin/ping6/ping6.c:1.76 Wed Aug 31 18:05:57 2011 +++ src/sbin/ping6/ping6.c Wed Aug 31 18:27:26 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.76 2011/08/31 22:05:57 riz Exp $ */ +/* $NetBSD: ping6.c,v 1.77 2011/08/31 22:27:26 christos Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.76 2011/08/31 22:05:57 riz Exp $); +__RCSID($NetBSD: ping6.c,v 1.77 2011/08/31 22:27:26 christos Exp $); #endif #endif @@ -1202,6 +1202,7 @@ icp-icmp6_cksum = 0; seq = ntransmitted++; CLR(seq % mx_dup_ck); + seq = ntohs(seq); if (options F_FQDN) { icp-icmp6_code = ICMP6_NI_SUBJ_IPV6; @@ -1246,7 +1247,7 @@ icp-icmp6_type = ICMP6_ECHO_REQUEST; icp-icmp6_code = 0; icp-icmp6_id = htons(ident); - icp-icmp6_seq = ntohs(seq); + icp-icmp6_seq = seq; if (timing) { struct timeval tv; struct tv32 *tv32;
CVS commit: src/sbin/ping6
Module Name:src Committed By: joerg Date: Sat Aug 27 18:43:27 UTC 2011 Modified Files: src/sbin/ping6: ping6.c Log Message: static + __dead + G/C pathmtu To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.74 src/sbin/ping6/ping6.c:1.75 --- src/sbin/ping6/ping6.c:1.74 Sun Aug 14 12:09:35 2011 +++ src/sbin/ping6/ping6.c Sat Aug 27 18:43:24 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.74 2011/08/14 12:09:35 christos Exp $ */ +/* $NetBSD: ping6.c,v 1.75 2011/08/27 18:43:24 joerg Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.74 2011/08/14 12:09:35 christos Exp $); +__RCSID($NetBSD: ping6.c,v 1.75 2011/08/27 18:43:24 joerg Exp $); #endif #endif @@ -189,7 +189,7 @@ #define F_SUPTYPES 0x8 #define F_NOMINMTU 0x10 #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) -u_int options; +static u_int options; #define IN6LEN sizeof(struct in6_addr) #define SA6LEN sizeof(struct sockaddr_in6) @@ -203,81 +203,80 @@ * to 8192 for complete accuracy... */ #define MAX_DUP_CHK (8 * 8192) -int mx_dup_ck = MAX_DUP_CHK; -char rcvd_tbl[MAX_DUP_CHK / 8]; +static int mx_dup_ck = MAX_DUP_CHK; +static char rcvd_tbl[MAX_DUP_CHK / 8]; -struct addrinfo *res; -struct sockaddr_in6 dst; /* who to ping6 */ -struct sockaddr_in6 src; /* src addr of this packet */ -socklen_t srclen; -int datalen = DEFDATALEN; -int s;/* socket file descriptor */ -u_char outpack[MAXPACKETLEN]; -char BSPACE = '\b'; /* characters written for flood */ -char DOT = '.'; -char *hostname; -int ident; /* process id to identify our packets */ -u_int8_t nonce[8]; /* nonce field for node information */ -int hoplimit = -1; /* hoplimit */ -int pathmtu = 0; /* path MTU for the destination. 0 = unspec. */ +static struct addrinfo *res; +static struct sockaddr_in6 dst; /* who to ping6 */ +static struct sockaddr_in6 src; /* src addr of this packet */ +static socklen_t srclen; +static int datalen = DEFDATALEN; +static int s;/* socket file descriptor */ +static u_char outpack[MAXPACKETLEN]; +static char BSPACE = '\b'; /* characters written for flood */ +static char DOT = '.'; +static char *hostname; +static int ident; /* process id to identify our packets */ +static u_int8_t nonce[8]; /* nonce field for node information */ +static int hoplimit = -1; /* hoplimit */ /* counters */ -long npackets; /* max packets to transmit */ -long nreceived; /* # of packets we got back */ -long nrepeats; /* number of duplicates */ -long ntransmitted; /* sequence # for outbound packets = #sent */ -struct timeval interval = {1, 0}; /* interval between packets */ +static long npackets; /* max packets to transmit */ +static long nreceived; /* # of packets we got back */ +static long nrepeats; /* number of duplicates */ +static long ntransmitted; /* sequence # for outbound packets = #sent */ +static struct timeval interval = {1, 0}; /* interval between packets */ /* timing */ -int timing; /* flag to do timing */ -double tmin = 9.0; /* minimum round trip time */ -double tmax = 0.0; /* maximum round trip time */ -double tsum = 0.0; /* sum of all times, for doing average */ -double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ +static int timing; /* flag to do timing */ +static double tmin = 9.0; /* minimum round trip time */ +static double tmax = 0.0; /* maximum round trip time */ +static double tsum = 0.0; /* sum of all times, for doing average */ +static double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ /* for node addresses */ -u_short naflags; +static u_short naflags; /* for ancillary data(advanced API) */ -struct msghdr smsghdr; -struct iovec smsgiov; -char *scmsg = 0; +static struct msghdr smsghdr; +static struct iovec smsgiov; +static char *scmsg = 0; -volatile sig_atomic_t seenalrm; -volatile sig_atomic_t seenint; +static volatile sig_atomic_t seenalrm; +static volatile sig_atomic_t seenint; #ifdef SIGINFO -volatile sig_atomic_t seeninfo; +static volatile sig_atomic_t seeninfo; #endif -void fill(char *, char *); -int get_hoplim(struct msghdr *); -int get_pathmtu(struct msghdr *); -struct in6_pktinfo *get_rcvpktinfo(struct msghdr *); -void onsignal(int); -void retransmit(void); -void onint(int); -size_t pingerlen(void); -int pinger(void); -const char *pr_addr(struct sockaddr *, int); -void pr_icmph(struct icmp6_hdr *, u_char *); -void pr_iph(struct ip6_hdr *); -void pr_suptypes(struct icmp6_nodeinfo *, size_t); -void pr_nodeaddr(struct icmp6_nodeinfo *, int); -int myechoreply(const struct icmp6_hdr *); -int mynireply(const struct icmp6_nodeinfo *); -char
CVS commit: src/sbin/ping6
Module Name:src Committed By: christos Date: Sun Aug 14 12:09:35 UTC 2011 Modified Files: src/sbin/ping6: Makefile ping6.c Log Message: fix gcc warnings and eliminate duplicate code. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sbin/ping6/Makefile cvs rdiff -u -r1.73 -r1.74 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/Makefile diff -u src/sbin/ping6/Makefile:1.13 src/sbin/ping6/Makefile:1.14 --- src/sbin/ping6/Makefile:1.13 Tue Jun 21 22:49:44 2011 +++ src/sbin/ping6/Makefile Sun Aug 14 08:09:35 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.13 2011/06/22 02:49:44 mrg Exp $ +# $NetBSD: Makefile,v 1.14 2011/08/14 12:09:35 christos Exp $ USE_FORT?= yes # setuid PROG= ping6 @@ -14,8 +14,3 @@ DPADD+= ${LIBIPSEC} ${LIBM} .include bsd.prog.mk - -# XXX -.if ${HAVE_GCC} == 45 -COPTS.ping6.c+= -fno-strict-aliasing -Wno-error -.endif Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.73 src/sbin/ping6/ping6.c:1.74 --- src/sbin/ping6/ping6.c:1.73 Mon Sep 20 07:49:48 2010 +++ src/sbin/ping6/ping6.c Sun Aug 14 08:09:35 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.73 2010/09/20 11:49:48 ahoka Exp $ */ +/* $NetBSD: ping6.c,v 1.74 2011/08/14 12:09:35 christos Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.73 2010/09/20 11:49:48 ahoka Exp $); +__RCSID($NetBSD: ping6.c,v 1.74 2011/08/14 12:09:35 christos Exp $); #endif #endif @@ -1192,7 +1192,7 @@ struct iovec iov[2]; int i, cc; struct icmp6_nodeinfo *nip; - int seq; + uint16_t seq; if (npackets ntransmitted = npackets) return(-1); /* no more transmission */ @@ -1202,60 +1202,47 @@ memset(icp, 0, sizeof(*icp)); icp-icmp6_cksum = 0; seq = ntransmitted++; + seq = ntohs(seq); CLR(seq % mx_dup_ck); if (options F_FQDN) { - icp-icmp6_type = ICMP6_NI_QUERY; icp-icmp6_code = ICMP6_NI_SUBJ_IPV6; nip-ni_qtype = htons(NI_QTYPE_FQDN); nip-ni_flags = htons(0); - memcpy(nip-icmp6_ni_nonce, nonce, - sizeof(nip-icmp6_ni_nonce)); - *(u_int16_t *)nip-icmp6_ni_nonce = ntohs(seq); - memcpy(outpack[ICMP6_NIQLEN], dst.sin6_addr, sizeof(dst.sin6_addr)); cc = ICMP6_NIQLEN + sizeof(dst.sin6_addr); - datalen = 0; } else if (options F_FQDNOLD) { /* packet format in 03 draft - no Subject data on queries */ - icp-icmp6_type = ICMP6_NI_QUERY; icp-icmp6_code = 0; /* code field is always 0 */ nip-ni_qtype = htons(NI_QTYPE_FQDN); nip-ni_flags = htons(0); - memcpy(nip-icmp6_ni_nonce, nonce, - sizeof(nip-icmp6_ni_nonce)); - *(u_int16_t *)nip-icmp6_ni_nonce = ntohs(seq); - cc = ICMP6_NIQLEN; - datalen = 0; } else if (options F_NODEADDR) { - icp-icmp6_type = ICMP6_NI_QUERY; icp-icmp6_code = ICMP6_NI_SUBJ_IPV6; nip-ni_qtype = htons(NI_QTYPE_NODEADDR); nip-ni_flags = naflags; - memcpy(nip-icmp6_ni_nonce, nonce, - sizeof(nip-icmp6_ni_nonce)); - *(u_int16_t *)nip-icmp6_ni_nonce = ntohs(seq); - memcpy(outpack[ICMP6_NIQLEN], dst.sin6_addr, sizeof(dst.sin6_addr)); cc = ICMP6_NIQLEN + sizeof(dst.sin6_addr); - datalen = 0; } else if (options F_SUPTYPES) { - icp-icmp6_type = ICMP6_NI_QUERY; icp-icmp6_code = ICMP6_NI_SUBJ_FQDN; /*empty*/ nip-ni_qtype = htons(NI_QTYPE_SUPTYPES); /* we support compressed bitmap */ nip-ni_flags = NI_SUPTYPE_FLAG_COMPRESS; + cc = ICMP6_NIQLEN; + } else + cc = 0; /* XXX: gcc */ + + if (options (F_FQDN|F_FQDNOLD|F_NODEADDR|F_SUPTYPES)) { + icp-icmp6_type = ICMP6_NI_QUERY; memcpy(nip-icmp6_ni_nonce, nonce, sizeof(nip-icmp6_ni_nonce)); - *(u_int16_t *)nip-icmp6_ni_nonce = ntohs(seq); - cc = ICMP6_NIQLEN; + memcpy(nip-icmp6_ni_nonce, seq, sizeof(seq)); datalen = 0; } else { icp-icmp6_type = ICMP6_ECHO_REQUEST; @@ -1504,7 +1491,8 @@ } } } else if (icp-icmp6_type == ICMP6_NI_REPLY mynireply(ni)) { - seq = ntohs(*(u_int16_t *)ni-icmp6_ni_nonce); + memcpy(seq, ni-icmp6_ni_nonce, sizeof(seq)); + seq = ntohs(seq); ++nreceived; if (TST(seq % mx_dup_ck)) { ++nrepeats; @@ -1562,7 +1550,7 @@ } else { i = 0; while (cp end) { - if (dnsdecode((const u_char **)cp, end, + if (dnsdecode((void *)cp, end, (const u_char *)(ni + 1), dnsname, sizeof(dnsname)) == NULL) { printf(???);
CVS commit: src/sbin/ping6
Module Name:src Committed By: ahoka Date: Mon Sep 20 11:49:48 UTC 2010 Modified Files: src/sbin/ping6: ping6.c Log Message: Avoid NaN when calculating std-dev, which fixes a crash on VAX. To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 src/sbin/ping6/ping6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/ping6/ping6.c diff -u src/sbin/ping6/ping6.c:1.72 src/sbin/ping6/ping6.c:1.73 --- src/sbin/ping6/ping6.c:1.72 Sat Apr 11 07:45:48 2009 +++ src/sbin/ping6/ping6.c Mon Sep 20 11:49:48 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ping6.c,v 1.72 2009/04/11 07:45:48 lukem Exp $ */ +/* $NetBSD: ping6.c,v 1.73 2010/09/20 11:49:48 ahoka Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* @@ -77,7 +77,7 @@ #else #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: ping6.c,v 1.72 2009/04/11 07:45:48 lukem Exp $); +__RCSID($NetBSD: ping6.c,v 1.73 2010/09/20 11:49:48 ahoka Exp $); #endif #endif @@ -2109,8 +2109,14 @@ if (nreceived timing) { /* Only display average to microseconds */ double num = nreceived + nrepeats; - double avg = tsum / num; - double dev = sqrt((tsumsq - num * avg * avg) / (num - 1)); + double dev, avg; + if (num 1) { + avg = tsum / num; + dev = sqrt((tsumsq - num * avg * avg) / (num - 1)); + } else { + avg = tsum; + dev = 0.0; + } (void)printf( round-trip min/avg/max/std-dev = %.3f/%.3f/%.3f/%.3f ms\n, tmin, avg, tmax, dev);