This sets ping6 up to specify the traffic class field for the IPv6
traffic class field. The v6 traffic class is equivalent to the IPv6
TOS/DSCP field, so this uses the same getopt param and parsing to get
the value.
ok?
Index: ping.8
===================================================================
RCS file: /cvs/src/sbin/ping/ping.8,v
retrieving revision 1.59
diff -u -p -r1.59 ping.8
--- ping.8 26 Oct 2016 16:18:45 -0000 1.59
+++ ping.8 9 Nov 2018 05:05:35 -0000
@@ -87,6 +87,7 @@
.Op Fl l Ar preload
.Op Fl p Ar pattern
.Op Fl s Ar packetsize
+.Op Fl T Ar toskeyword
.Op Fl V Ar rtable
.Op Fl w Ar maxwait
.Ar host
@@ -221,8 +222,7 @@ which translates into 64 ICMP data bytes
when combined with the 8 bytes of ICMP header data.
The maximum packet size is 65467 for IPv4 and 65527 for IPv6.
.It Fl T Ar toskeyword
-.Pq IPv4 only
-Change the TOS value.
+Change the IPv4 TOS or IPv6 Traffic Class value.
.Ar toskeyword
may be one of
.Cm critical ,
Index: ping.c
===================================================================
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.230
diff -u -p -r1.230 ping.c
--- ping.c 14 Oct 2018 19:47:53 -0000 1.230
+++ ping.c 9 Nov 2018 05:05:35 -0000
@@ -150,7 +150,7 @@ int options;
/* 0x0200 */
#define F_HDRINCL 0x0400
#define F_TTL 0x0800
-/* 0x1000 */
+#define F_TOS 0x1000
#define F_AUD_RECV 0x2000
#define F_AUD_MISS 0x4000
@@ -291,7 +291,7 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ECHOLEN + ECHOTMLEN];
while ((ch = getopt(argc, argv, v6flag ?
- "c:dEefHh:I:i:Ll:mNnp:qS:s:V:vw:" :
+ "c:dEefHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
"DEI:LRS:c:defHi:l:np:qs:T:t:V:vw:")) != -1) {
switch(ch) {
case 'c':
@@ -386,6 +386,7 @@ main(int argc, char *argv[])
#ifndef SMALL
case 'T':
options |= F_HDRINCL;
+ options |= F_TOS;
errno = 0;
errstr = NULL;
if (map_tos(optarg, &tos))
@@ -671,6 +672,13 @@ main(int argc, char *argv[])
scmsg->cmsg_level = IPPROTO_IPV6;
scmsg->cmsg_type = IPV6_HOPLIMIT;
*(int *)(CMSG_DATA(scmsg)) = hoplimit;
+ }
+
+ if (options & F_TOS) {
+ optval = tos;
+ if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &optval,
+ (socklen_t)sizeof(optval)) < 0)
+ warn("setsockopt(IPV6_TVAL)"); /* XXX err? */
}
optval = 1;