From 3277497915724efd040272cd7362561edb757328 Mon Sep 17 00:00:00 2001 From: Sevan Janiyan Date: Sat, 12 Jul 2025 19:13:51 +0100 Subject: [PATCH] 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. --- packet/construct_unix.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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, -- 2.47.2