Skip to content

Commit

Permalink
Use a Windows-specific cast from integer pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
yadij committed May 22, 2023
1 parent 509db39 commit 9470fea
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/ip/QosConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>((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));
Expand All @@ -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));
Expand Down

0 comments on commit 9470fea

Please sign in to comment.