Hi,
based on Theo's recent comment I thought I could take a shot at it, but
it seems that my tree is currently broken as I can't compile it:
/usr/src/sbin/ping6/ping6.c:745: error: implicit declaration of function
'pledge'
But I thought it might still be worthwhile to share the diff.
Basically I did the following:
- renamed ping6 option -m to -D
- renamed ping6 option -t to -o (as I would otherwise have a naming conflict)
- renamed ping6 option -h to -t
- renamed ping6 option -w to -O (-w is used by ping for a different matter)
I also wanted to change hoplimit to be ttl so it matches ping's code but ttl
is already in use within ping6.
If this would be ok I will gladly to the ping.8 diff.
Frank.
Index: sbin/ping6/ping6.c
===================================================================
RCS file: /cvs/src/sbin/ping6/ping6.c,v
retrieving revision 1.121
diff -u -p -u -r1.121 ping6.c
--- sbin/ping6/ping6.c 12 Oct 2015 18:32:18 -0000 1.121
+++ sbin/ping6/ping6.c 13 Oct 2015 11:19:41 -0000
@@ -177,7 +177,7 @@ 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 maxttl = -1; /* maxttl */
/* counters */
long npackets; /* max packets to transmit */
@@ -255,7 +255,7 @@ main(int argc, char *argv[])
int usepktinfo = 0;
struct in6_pktinfo *pktinfo = NULL;
double intval;
- int mflag = 0;
+ int Dflag = 0;
uid_t uid;
u_int rtableid = 0;
@@ -270,7 +270,7 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
while ((ch = getopt(argc, argv,
- "a:b:c:dEefHg:h:I:i:l:mnNp:qS:s:tvV:w")) != -1) {
+ "a:b:c:DdEefg:H:I:i:l:NnOp:qS:s:tV:v")) != -1) {
switch (ch) {
case 'a':
{
@@ -325,6 +325,9 @@ main(int argc, char *argv[])
"number of packets to transmit is %s: %s",
errstr, optarg);
break;
+ case 'D':
+ Dflag++;
+ break;
case 'd':
options |= F_SO_DEBUG;
break;
@@ -348,11 +351,6 @@ main(int argc, char *argv[])
case 'H':
options |= F_HOSTNAME;
break;
- case 'h': /* hoplimit */
- hoplimit = strtonum(optarg, 0, IPV6_MAXHLIM, &errstr);
- if (errstr)
- errx(1, "hoplimit is %s: %s", errstr, optarg);
- break;
case 'I':
ifname = optarg;
options |= F_INTERFACE;
@@ -388,15 +386,20 @@ main(int argc, char *argv[])
errx(1, "preload value is %s: %s", errstr,
optarg);
break;
- case 'm':
- mflag++;
- break;
case 'n':
options &= ~F_HOSTNAME;
break;
case 'N':
options |= F_NIGROUP;
break;
+ case 'O':
+ options &= ~F_NOUSERDATA;
+ options |= F_FQDN;
+ break;
+ case 'o':
+ options &= ~F_NOUSERDATA;
+ options |= F_SUPTYPES;
+ break;
case 'p': /* fill buffer with user pattern */
options |= F_PINGFILLED;
fill((char *)datap, optarg);
@@ -429,9 +432,10 @@ main(int argc, char *argv[])
errx(1, "datalen value is %s: %s", errstr,
optarg);
break;
- case 't':
- options &= ~F_NOUSERDATA;
- options |= F_SUPTYPES;
+ case 't': /* maxttl */
+ maxttl = strtonum(optarg, 0, IPV6_MAXHLIM, &errstr);
+ if (errstr)
+ errx(1, "maxttl is %s: %s", errstr, optarg);
break;
case 'v':
options |= F_VERBOSE;
@@ -446,10 +450,6 @@ main(int argc, char *argv[])
sizeof(rtableid)) == -1)
err(1, "setsockopt SO_RTABLE");
break;
- case 'w':
- options &= ~F_NOUSERDATA;
- options |= F_FQDN;
- break;
default:
usage();
/*NOTREACHED*/
@@ -585,8 +585,8 @@ main(int argc, char *argv[])
if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
&optval, (socklen_t)sizeof(optval)) == -1)
err(1, "IPV6_MULTICAST_HOPS");
- if (mflag != 1) {
- optval = mflag > 1 ? 0 : 1;
+ if (Dflag != 1) {
+ optval = Dflag > 1 ? 0 : 1;
if (setsockopt(s, IPPROTO_IPV6, IPV6_USE_MIN_MTU,
&optval, (socklen_t)sizeof(optval)) == -1)
@@ -629,7 +629,7 @@ main(int argc, char *argv[])
if (usepktinfo)
ip6optlen += CMSG_SPACE(sizeof(struct in6_pktinfo));
- if (hoplimit != -1)
+ if (maxttl != -1)
ip6optlen += CMSG_SPACE(sizeof(int));
@@ -656,11 +656,11 @@ main(int argc, char *argv[])
if ((pktinfo->ipi6_ifindex = if_nametoindex(ifname)) == 0)
errx(1, "%s: invalid interface name", ifname);
}
- if (hoplimit != -1) {
+ if (maxttl != -1) {
scmsgp->cmsg_len = CMSG_LEN(sizeof(int));
scmsgp->cmsg_level = IPPROTO_IPV6;
scmsgp->cmsg_type = IPV6_HOPLIMIT;
- *(int *)(CMSG_DATA(scmsgp)) = hoplimit;
+ *(int *)(CMSG_DATA(scmsgp)) = maxttl;
scmsgp = CMSG_NXTHDR(&smsghdr, scmsgp);
}
@@ -686,14 +686,14 @@ main(int argc, char *argv[])
(void *)pktinfo, sizeof(*pktinfo)))
err(1, "UDP setsockopt(IPV6_PKTINFO)");
- if (hoplimit != -1 &&
+ if (maxttl != -1 &&
setsockopt(dummy, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
- (void *)&hoplimit, sizeof(hoplimit)))
+ (void *)&maxttl, sizeof(maxttl)))
err(1, "UDP setsockopt(IPV6_UNICAST_HOPS)");
- if (hoplimit != -1 &&
+ if (maxttl != -1 &&
setsockopt(dummy, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
- (void *)&hoplimit, sizeof(hoplimit)))
+ (void *)&maxttl, sizeof(maxttl)))
err(1, "UDP setsockopt(IPV6_MULTICAST_HOPS)");
if (rtableid > 0 &&
@@ -2352,11 +2352,10 @@ void
usage(void)
{
(void)fprintf(stderr,
- "usage: ping6 [-dEefH"
- "m"
- "Nnqtvw"
+ "usage: ping6 [-DdEefH"
+ "NnOoqv"
"] [-a addrtype] [-b bufsiz] [-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");
+ "[-I interface] [-i wait] [-l preload] [-p pattern]"
+ "\n\t[-S sourceaddr] [-s packetsize] [-t maxttl] [-V rtable]
host\n");
exit(1);
}