]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
packet/construct_unix.c: Only set IPV6_TCLASS if defined. 540/head
authorSevan Janiyan <venture37@geeklan.co.uk>
Sat, 12 Jul 2025 18:13:51 +0000 (19:13 +0100)
committerSevan Janiyan <venture37@geeklan.co.uk>
Sun, 13 Jul 2025 14:24:28 +0000 (15:24 +0100)
Resolves build on legacy systems with IPv6 stacks which lack RFC 3542
support e.g Mac OS X, before 10.6.

packet/construct_unix.c

index 5983933ec37a16e3a99625a3126615ec75ba2a74..51894a1ffb3a0fe7d63bddc7c26c8951cc0a3a6a 100644 (file)
@@ -427,19 +427,28 @@ int set_stream_socket_options(
     }
 
     /*  Set the "type of service" field of the IP header  */
+#ifdef IPV6_TCLASS
     if (param->ip_version == 6) {
         level = IPPROTO_IPV6;
         opt = IPV6_TCLASS;
     } else {
+#else
+    opt = 0;
+    if (param->ip_version == 4) {
+#endif
         level = IPPROTO_IP;
         opt = IP_TOS;
     }
 
-    if (setsockopt(stream_socket, level, opt,
-                   &param->type_of_service, sizeof(int)) == -1) {
+    /* Avoid trying to set on IPv6 stacks which lack RFC 3542 support (IPV6_TCLASS) */
+    if (opt != 0) {
+        if (setsockopt(stream_socket, level, opt,
+                       &param->type_of_service, sizeof(int)) == -1) {
 
-        return -1;
+            return -1;
+        }
     }
+
 #ifdef SO_MARK
     if (param->routing_mark) {
         if (set_socket_mark(stream_socket, param->routing_mark)) {
@@ -835,11 +844,13 @@ int construct_ip6_packet(
         }
     }
 
+#ifdef IPV6_TCLASS
     /*  The traffic class in IPv6 is analogous to ToS in IPv4  */
     if (setsockopt(send_socket, IPPROTO_IPV6,
                    IPV6_TCLASS, &param->type_of_service, sizeof(int))) {
         return -1;
     }
+#endif
 
     /*  Set the time-to-live  */
     if (setsockopt(send_socket, IPPROTO_IPV6,