From 1a44e357a3aad38a57087f63ec5aaa93f8832408 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 14 Oct 2015 17:26:01 +0000 Subject: [PATCH] To specify a source address ping uses -I while ping6 uses -S. Switch ping6 -I to the ping-alike semantics. sthen@ thinks this is OK --- sbin/ping6/ping6.8 | 19 +++++-------- sbin/ping6/ping6.c | 67 +++++++++++++++------------------------------- 2 files changed, 28 insertions(+), 58 deletions(-) diff --git a/sbin/ping6/ping6.8 b/sbin/ping6/ping6.8 index 0bd6703442b..7a3ec388b5b 100644 --- a/sbin/ping6/ping6.8 +++ b/sbin/ping6/ping6.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ping6.8,v 1.51 2015/10/13 16:26:54 florian Exp $ +.\" $OpenBSD: ping6.8,v 1.52 2015/10/14 17:26:01 florian 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 $Mdocdate: October 13 2015 $ +.Dd $Mdocdate: October 14 2015 $ .Dt PING6 8 .Os .Sh NAME @@ -41,11 +41,10 @@ .Op Fl c Ar count .Op Fl g Ar gateway .Op Fl h Ar hoplimit -.Op Fl I Ar interface +.Op Fl I Ar sourceaddr .Op Fl i Ar wait .Op Fl l Ar preload .Op Fl p Ar pattern -.Op Fl S Ar sourceaddr .Op Fl s Ar packetsize .Op Fl V Ar rtable .Ar host @@ -148,10 +147,10 @@ The command does not try reverse-lookup unless the option is specified. .It Fl h Ar hoplimit Set the IPv6 hoplimit. -.It Fl I Ar interface -Source packets with the given interface address. -This flag applies if the ping destination is a multicast address, -or link-local/site-local unicast address. +.It Fl I Ar sourceaddr +Specifies the source address of request packets. +The source address must be one of the unicast addresses of the sending node, +and must be numeric. .It Fl i Ar wait Wait .Ar wait @@ -226,10 +225,6 @@ when finished. .\".Ar host .\".Pq or the first hop .\"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, -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 diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index fcb028a34fd..c855950b066 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.122 2015/10/13 16:26:54 florian Exp $ */ +/* $OpenBSD: ping6.c,v 1.123 2015/10/14 17:26:01 florian Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -146,7 +146,6 @@ struct payload { #define F_VERBOSE 0x0100 #define F_NODEADDR 0x0800 #define F_FQDN 0x1000 -#define F_INTERFACE 0x2000 #define F_SRCADDR 0x4000 #define F_HOSTNAME 0x10000 #define F_NIGROUP 0x40000 @@ -247,11 +246,10 @@ main(int argc, char *argv[]) int ch, i, maxsize, packlen, preload, optval, error; socklen_t maxsizelen; u_char *datap, *packet; - char *e, *target, *ifname = NULL, *gateway = NULL; + char *e, *target, *gateway = NULL; const char *errstr; int ip6optlen = 0; struct cmsghdr *scmsgp = NULL; - int usepktinfo = 0; struct in6_pktinfo *pktinfo = NULL; double intval; int mflag = 0; @@ -344,9 +342,23 @@ main(int argc, char *argv[]) errx(1, "hoplimit is %s: %s", errstr, optarg); break; case 'I': - ifname = optarg; - options |= F_INTERFACE; - usepktinfo++; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_flags = AI_NUMERICHOST; /* allow hostname? */ + hints.ai_family = AF_INET6; + hints.ai_socktype = SOCK_RAW; + hints.ai_protocol = IPPROTO_ICMPV6; + + error = getaddrinfo(optarg, NULL, &hints, &res0); + if (error) + errx(1, "invalid source address: %s", + gai_strerror(error)); + + if (res0->ai_family != AF_INET6 || res0->ai_addrlen != + sizeof(src)) + errx(1, "invalid source address"); + memcpy(&src, res0->ai_addr, sizeof(src)); + freeaddrinfo(res0); + options |= F_SRCADDR; break; case 'i': /* wait between sending packets */ intval = strtod(optarg, &e); @@ -394,25 +406,6 @@ main(int argc, char *argv[]) case 'q': options |= F_QUIET; break; - case 'S': - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_flags = AI_NUMERICHOST; /* allow hostname? */ - hints.ai_family = AF_INET6; - hints.ai_socktype = SOCK_RAW; - hints.ai_protocol = IPPROTO_ICMPV6; - - error = getaddrinfo(optarg, NULL, &hints, &res0); - if (error) - errx(1, "invalid source address: %s", - gai_strerror(error)); - - if (res0->ai_family != AF_INET6 || res0->ai_addrlen != - sizeof(src)) - errx(1, "invalid source address"); - memcpy(&src, res0->ai_addr, sizeof(src)); - freeaddrinfo(res0); - options |= F_SRCADDR; - break; case 's': /* size of packet to send */ datalen = strtonum(optarg, 1, MAXDATALEN, &errstr); if (errstr) @@ -633,10 +626,6 @@ main(int argc, char *argv[]) err(1, "setsockopt(IPV6_RECVRTHDR)"); } - /* Specify the outgoing interface and/or the source address */ - if (usepktinfo) - ip6optlen += CMSG_SPACE(sizeof(struct in6_pktinfo)); - if (hoplimit != -1) ip6optlen += CMSG_SPACE(sizeof(int)); @@ -649,21 +638,7 @@ main(int argc, char *argv[]) smsghdr.msg_controllen = ip6optlen; scmsgp = (struct cmsghdr *)scmsg; } - if (usepktinfo) { - pktinfo = (struct in6_pktinfo *)(CMSG_DATA(scmsgp)); - memset(pktinfo, 0, sizeof(*pktinfo)); - scmsgp->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); - scmsgp->cmsg_level = IPPROTO_IPV6; - scmsgp->cmsg_type = IPV6_PKTINFO; - scmsgp = CMSG_NXTHDR(&smsghdr, scmsgp); - } - /* set the outgoing interface */ - if (ifname) { - /* pktinfo must have already been allocated */ - if ((pktinfo->ipi6_ifindex = if_nametoindex(ifname)) == 0) - errx(1, "%s: invalid interface name", ifname); - } if (hoplimit != -1) { scmsgp->cmsg_len = CMSG_LEN(sizeof(int)); scmsgp->cmsg_level = IPPROTO_IPV6; @@ -2341,7 +2316,7 @@ usage(void) "m" "Nnqtvw" "] [-a addrtype] [-c count] [-g gateway]\n\t" - "[-h hoplimit] [-I interface] [-i wait] [-l preload] [-p pattern]" - "\n\t[-S sourceaddr] [-s packetsize] [-V rtable] host\n"); + "[-h hoplimit] [-I sourceaddr] [-i wait] [-l preload] [-p pattern]" + "\n\t[-s packetsize] [-V rtable] host\n"); exit(1); } -- 2.20.1