From: Sevan Janiyan Date: Sat, 12 Jul 2025 18:13:51 +0000 (+0100) Subject: packet/construct_unix.c: Only set IPV6_TCLASS if defined. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F540%2Fhead;p=thirdparty%2Fmtr.git packet/construct_unix.c: Only set IPV6_TCLASS if defined. Resolves build on legacy systems with IPv6 stacks which lack RFC 3542 support e.g Mac OS X, before 10.6. --- diff --git a/packet/construct_unix.c b/packet/construct_unix.c index 5983933..51894a1 100644 --- a/packet/construct_unix.c +++ b/packet/construct_unix.c @@ -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, - ¶m->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, + ¶m->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, ¶m->type_of_service, sizeof(int))) { return -1; } +#endif /* Set the time-to-live */ if (setsockopt(send_socket, IPPROTO_IPV6,