if -t is used, display a notice when the TOS changes en-route.
ok?

Index: traceroute.8
===================================================================
RCS file: /cvs/src/usr.sbin/traceroute/traceroute.8,v
retrieving revision 1.44
diff -u -p -r1.44 traceroute.8
--- traceroute.8        8 Jul 2010 20:23:03 -0000       1.44
+++ traceroute.8        5 Apr 2011 15:50:38 -0000
@@ -177,6 +177,8 @@ in probe packets to the following value 
 The value must be a decimal integer in the range 0 to 255.
 This option can be used to
 see if different types-of-service result in different paths.
+If this option is used, changes to the type-of-service in the
+returned packets are displayed.
 (If you are not running a
 .Bx 4.3 tahoe
 or later system, this may be academic since the normal network
@@ -384,6 +386,8 @@ ever occur and the associated gateway is
 (destination network or host unreachable for TOS),
 .Sy !<code>
 (other ICMP unreachable code).
+.Sy TOS=xxx
+(TOS bit in returned packet differs from last hop).
 If almost all the probes result in some kind of unreachable,
 .Nm
 will give up and exit.
Index: traceroute.c
===================================================================
RCS file: /cvs/src/usr.sbin/traceroute/traceroute.c,v
retrieving revision 1.74
diff -u -p -r1.74 traceroute.c
--- traceroute.c        22 Mar 2011 10:16:23 -0000      1.74
+++ traceroute.c        5 Apr 2011 15:50:38 -0000
@@ -293,11 +293,13 @@ main(int argc, char *argv[])
        int mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_DEFTTL };
        int ttl_flag = 0, incflag = 1, protoset = 0, sump = 0;
        int ch, i, lsrr = 0, on = 1, probe, seq = 0, tos = 0;
+       int last_tos, tos_returned;
        size_t size = sizeof(max_ttl);
        struct sockaddr_in from, to;
        struct hostent *hp;
        u_int32_t tmprnd;
-       struct ip *ip;
+       struct ip *ip, *inner_ip;
+       struct icmp *icp;
        u_int8_t ttl;
        char *ep;
        const char *errstr;
@@ -427,7 +429,7 @@ main(int argc, char *argv[])
                        l = strtol(optarg, &ep, 10);
                        if (errno || !*optarg || *ep || l < 0 || l > 255)
                                errx(1, "tos must be 0 to 255.");
-                       tos = (int)l;
+                       last_tos = tos = (int)l;
                        break;
                case 'v':
                        verbose++;
@@ -636,9 +638,21 @@ main(int argc, char *argv[])
                                        ++got_there;
                                        break;
                                }
+
+                               icp = (struct icmp *) (((u_char 
*)ip)+(ip->ip_hl<<2));
+                               inner_ip = (struct ip *) (((u_char *)icp)+8);
+
+                               tos_returned = inner_ip->ip_tos;
+
+                               if (tos_returned != last_tos)
+                                       printf (" (TOS=%d!)", tos_returned);
+
+                               last_tos = tos_returned;
+
                                /* time exceeded in transit */
                                if (i == -1)
                                        break;
+
                                code = i - 1;
                                switch (code) {
                                case ICMP_UNREACH_PORT:

Reply via email to