]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Windows: Various fixes for CMSG API emulation
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 14 Sep 2014 14:15:01 +0000 (07:15 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 14 Sep 2014 14:15:01 +0000 (07:15 -0700)
* 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.

compat/cmsg.h
configure.ac
src/ip/QosConfig.cc
src/ipc/TypedMsgHdr.cc

index befa932d828aab377309e07a9f72678bcd500c59..b2bb7ce2b8ed911b9a9f1bf497ce387ec9fd2205 100644 (file)
 #include <sys/socket.h>
 #endif
 
-// WinSock2.h defines these for Windows
+// mswsock.h defines WSA_CMSG definitions
+#if HAVE_MSWSOCK_H
+#include <mswsock.h>
+#endif
 #if HAVE_WINSOCK2_H
 #include <winsock2.h>
 #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
index 6b3d767d1cfb0ccfc123a9b55f5bccd539aa1d3c..8144e5f071ba39b5def1d5df07e875a0c16f2a50 100644 (file)
@@ -3034,12 +3034,16 @@ if test "x$squid_host_os" = "xmingw" ; then
     windows.h \
     ws2tcpip.h \
     iphlpapi.h ,,,[
+#if HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
 #if HAVE_WINDOWS_H
 #include <windows.h>
 #endif
-#if HAVE_WINSOCK2_H
-#include <winsock2.h>
-#endif])
+#if HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#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 <sys/socket.h>
   #endif
+  #if HAVE_MSWSOCK_H
+  #include <mswsock.h>
+  #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 <sys/socket.h>
   #endif
+  #if HAVE_MSWSOCK_H
+  #include <mswsock.h>
+  #endif
   #if HAVE_WINSOCK2_H
   #include <winsock2.h>
   #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 <sys/socket.h>
   #endif
+  #if HAVE_MSWSOCK_H
+  #include <mswsock.h>
+  #endif
   #if HAVE_WINSOCK2_H
   #include <winsock2.h>
   #endif
index 9f4781a91c0212e1271cf749646b6b3ff3c7e4f1..d389d4a2fd09bfbc9bc750c06e60032fc4b26bfe 100644 (file)
@@ -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;
                 }
index d0293682839815131ff38479fe7bce7803b17f39..3198cf4195503975b5d3988878b9c32c1a2852f0 100644 (file)
@@ -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<int*>(CMSG_DATA(cmsg));
+    int *fdStore = reinterpret_cast<int*>(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<const int*>(CMSG_DATA(cmsg));
+    const int *fdStore = reinterpret_cast<const int*>(SQUID_CMSG_DATA(cmsg));
     int fd = -1;
     memcpy(&fd, fdStore, fdCount * sizeof(int));
     return fd;