From 9470fea0f8df48a345b178ebe143e09805e701b3 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Tue, 23 May 2023 04:18:48 +1200 Subject: [PATCH] Use a Windows-specific cast from integer pointer --- src/ip/QosConfig.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ip/QosConfig.cc b/src/ip/QosConfig.cc index 065d2623ebd..77b16b7f4d0 100644 --- a/src/ip/QosConfig.cc +++ b/src/ip/QosConfig.cc @@ -529,22 +529,24 @@ Ip::Qos::Config::dumpConfigLine(char *entry, const char *name) const int Ip::Qos::setSockTos(const int fd, tos_t tos, int type) { -#if _SQUID_MINGW_ - const char bTos = tos; -#else // Bug 3731: FreeBSD produces 'invalid option' // unless we pass it a 32-bit variable storing 8-bits of data. - // NP: it is documented as 'int' for all non-Windows systems, - // even those like Linux which accept 8-bit char - // so we convert to a int before setting. + // NOTE: setsockopt(.., IP_TOS, ...) 'optval' parameter + // is documented as 'int' for all systems + // despite what the function parameter type is. + // So we convert to int before setting. int bTos = tos; +#if _SQUID_MINGW_ +#define MAKE_SOCKOPT(x) static_cast((x)) +#else +#define MAKE_SOCKOPT(x) (x) #endif debugs(50, 3, "for FD " << fd << " to " << bTos); if (type == AF_INET) { #if defined(IP_TOS) - const int x = setsockopt(fd, IPPROTO_IP, IP_TOS, &bTos, sizeof(bTos)); + const int x = setsockopt(fd, IPPROTO_IP, IP_TOS, MAKE_SOCKOPT(&bTos), sizeof(bTos)); if (x < 0) { int xerrno = errno; debugs(50, 2, "setsockopt(IP_TOS) on " << fd << ": " << xstrerr(xerrno)); @@ -556,7 +558,7 @@ Ip::Qos::setSockTos(const int fd, tos_t tos, int type) #endif } else { // type == AF_INET6 #if defined(IPV6_TCLASS) - const int x = setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &bTos, sizeof(bTos)); + const int x = setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, MAKE_SOCKOPT(&bTos), sizeof(bTos)); if (x < 0) { int xerrno = errno; debugs(50, 2, "setsockopt(IPV6_TCLASS) on " << fd << ": " << xstrerr(xerrno));