From: Amos Jeffries Date: Sun, 14 Sep 2014 14:15:01 +0000 (-0700) Subject: Windows: Various fixes for CMSG API emulation X-Git-Tag: SQUID_3_5_0_1~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ff9dfaa0f752bd304deb2b67df8a2c1c101c9b9;p=thirdparty%2Fsquid.git Windows: Various fixes for CMSG API emulation * Windows defines CMSG_DATA macro name for uses unrelated to the BSD socket CMSG mechanism. Define SQUID_CMSG_DATA as a generic replacement. * MinGW provides a wrapper layer emulating the BSD socket CMSG mechanism in the form of WSA_CMG_* macros for the BSD struct types. Detect and use those wrapper macros when available. --- diff --git a/compat/cmsg.h b/compat/cmsg.h index befa932d82..b2bb7ce2b8 100644 --- a/compat/cmsg.h +++ b/compat/cmsg.h @@ -18,7 +18,10 @@ #include #endif -// WinSock2.h defines these for Windows +// mswsock.h defines WSA_CMSG definitions +#if HAVE_MSWSOCK_H +#include +#endif #if HAVE_WINSOCK2_H #include #endif @@ -39,12 +42,17 @@ struct cmsghdr { #endif /* lifted off https://metacpan.org/source/SAMPO/Socket-PassAccessRights-0.03/passfd.c */ -#ifndef CMSG_DATA -# define CMSG_DATA(cmsg) ((cmsg)->cmsg_data) +// check for WSA_CMSG first because Windows defines CMSG_DATA for other uses +#if defined(WSA_CMSG_DATA) +# define SQUID_CMSG_DATA(cmsg) WSA_CMSG_DATA(cmsg) +#elif defined(CMSG_DATA) +# define SQUID_CMSG_DATA(cmsg) CMSG_DATA(cmsg) +#else +# define SQUID_CMSG_DATA(cmsg) ((cmsg)->cmsg_data) #endif #ifndef CMSG_NXTHDR -# define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg) +# define CMSG_NXTHDR(mhdr, X) __cmsg_nxthdr (mhdr, X) #endif #ifndef CMSG_FIRSTHDR diff --git a/configure.ac b/configure.ac index 6b3d767d1c..8144e5f071 100644 --- a/configure.ac +++ b/configure.ac @@ -3034,12 +3034,16 @@ if test "x$squid_host_os" = "xmingw" ; then windows.h \ ws2tcpip.h \ iphlpapi.h ,,,[ +#if HAVE_WINSOCK2_H +#include +#endif #if HAVE_WINDOWS_H #include #endif -#if HAVE_WINSOCK2_H -#include -#endif]) +#if HAVE_WS2TCPIP_H +#include +#endif +]) fi # check that we have unix sockets @@ -3425,11 +3429,15 @@ if test "x$squid_cv_resuid_works" = "xyes" ; then AC_DEFINE(HAVE_SETRESUID,1,[Yay! Another Linux brokenness. Knowing that setresuid() exists is not enough, because RedHat 5.0 declares setresuid() but does not implement it.]) fi +AC_CHECK_HEADERS(mswsock.h) AC_MSG_CHECKING([for constant CMSG_SPACE]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #if HAVE_SYS_SOCKET_H #include #endif + #if HAVE_MSWSOCK_H + #include + #endif int a[CMSG_SPACE(int)]; ]])], [ @@ -3443,6 +3451,9 @@ AC_CHECK_TYPE(struct cmsghdr,AC_DEFINE(HAVE_CMSGHDR,1,[The system provides struc #if HAVE_SYS_SOCKET_H #include #endif + #if HAVE_MSWSOCK_H + #include + #endif #if HAVE_WINSOCK2_H #include #endif @@ -3464,6 +3475,9 @@ AC_CHECK_TYPE(struct msghdr,AC_DEFINE(HAVE_MSGHDR,1,[The system provides struct #if HAVE_SYS_SOCKET_H #include #endif + #if HAVE_MSWSOCK_H + #include + #endif #if HAVE_WINSOCK2_H #include #endif diff --git a/src/ip/QosConfig.cc b/src/ip/QosConfig.cc index 9f4781a91c..d389d4a2fd 100644 --- a/src/ip/QosConfig.cc +++ b/src/ip/QosConfig.cc @@ -44,7 +44,7 @@ Ip::Qos::getTosFromServer(const Comm::ConnectionPointer &server, fde *clientFde) break; if (o->cmsg_level == SOL_IP && o->cmsg_type == IP_TOS) { - int *tmp = (int*)CMSG_DATA(o); + int *tmp = (int*)SQUID_CMSG_DATA(o); clientFde->tosFromServer = (tos_t)*tmp; break; } diff --git a/src/ipc/TypedMsgHdr.cc b/src/ipc/TypedMsgHdr.cc index d029368283..3198cf4195 100644 --- a/src/ipc/TypedMsgHdr.cc +++ b/src/ipc/TypedMsgHdr.cc @@ -195,7 +195,7 @@ Ipc::TypedMsgHdr::putFd(int fd) cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fdCount); - int *fdStore = reinterpret_cast(CMSG_DATA(cmsg)); + int *fdStore = reinterpret_cast(SQUID_CMSG_DATA(cmsg)); memcpy(fdStore, &fd, fdCount * sizeof(int)); msg_controllen = cmsg->cmsg_len; @@ -213,7 +213,7 @@ Ipc::TypedMsgHdr::getFd() const Must(cmsg->cmsg_type == SCM_RIGHTS); const int fdCount = 1; - const int *fdStore = reinterpret_cast(CMSG_DATA(cmsg)); + const int *fdStore = reinterpret_cast(SQUID_CMSG_DATA(cmsg)); int fd = -1; memcpy(&fd, fdStore, fdCount * sizeof(int)); return fd;