]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Portability: define CMSG related structures individually
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 5 Mar 2014 06:32:34 +0000 (19:32 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 5 Mar 2014 06:32:34 +0000 (19:32 +1300)
Some OS provide the CMSG related definitions and others only partially
define them. Sometimes (Windows particularly) this varies between build
environments.

Checking for each symbol separately and providing only those needed
avoids problems we have been having with missing or redefined symbols
on Windows and elsewhere.

acinclude/squid-util.m4
compat/cmsg.h
configure.ac

index b41f67b6ef491a566c7266b97aa12acaa54a6f9d..b82f696ed68b74c93a7dd1be2f1d6afb86facb5e 100644 (file)
@@ -248,6 +248,23 @@ AS_IF([test "$ac_res" != no],
 AS_VAR_POPDEF([ac_Search])dnl
 ])
 
+dnl checks that the system provides a given struct type
+dnl defines HAVE_FOO if the type struct FOO exists.
+AC_DEFUN([SQUID_CHECK_STRUCT],[
+  squid_chk_struct="HAVE_$1"
+  AC_MSG_CHECKING([for struct $1])
+  SQUID_TOUPPER_VAR_CONTENTS([squid_chk_struct])
+  AC_COMPILE_IFELSE([
+    AC_LANG_SOURCE([[$2]],[[struct $1 a;]])
+  ],[
+    AC_MSG_RESULT(yes)
+    AC_DEFINE_UNQUOTED([$squid_chk_struct],1,[Define to 1 if struct $1 is provided by the system])
+  ],[
+    AC_MSG_RESULT(no)
+  ])
+  unset squid_chk_struct
+])
+
 dnl Check for Cyrus SASL
 AC_DEFUN([SQUID_CHECK_SASL],[
   squid_cv_check_sasl="auto"
index dc340e3703ea4627ff39ee0993d4159a013572a4..9f68d91abffa8801b92e6385b0ce4541c876d9a8 100644 (file)
 // WinSock2.h defines these for Windows
 #if HAVE_WINSOCK2_H
 #include <winsock2.h>
-#define CMSG_H_ // prevent re-definition
 #endif
 
-#ifndef CMSG_H_
-#define CMSG_H_
+// sockaddr_un might be in sys/un.h if not pulled in already
+#if HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
 
-/* mostly windows-specific */
-#ifndef CMSG_SPACE
+#if !HAVE_CMSGHDR
 struct cmsghdr {
-    unsigned int    cmsg_len;
-    int  cmsg_level;
-    int     cmsg_type;
+    unsigned int cmsg_len;
+    int cmsg_level;
+    int cmsg_type;
     unsigned char cmsg_data[16]; /* dummy */
     /* followed by UCHAR cmsg_data[]; */
-} ;
+};
+#endif
 
 /* lifted off https://metacpan.org/source/SAMPO/Socket-PassAccessRights-0.03/passfd.c */
 #ifndef CMSG_DATA
@@ -48,15 +49,25 @@ struct cmsghdr {
              & ~(sizeof (size_t) - 1))
 #endif
 
+#ifndef CMSG_SPACE
 # define CMSG_SPACE(len) (CMSG_ALIGN (len) \
              + CMSG_ALIGN (sizeof (struct cmsghdr)))
 #undef HAVE_CONSTANT_CMSG_SPACE
 #define HAVE_CONSTANT_CMSG_SPACE 1
+#endif
 
 #ifndef CMSG_LEN
 # define CMSG_LEN(len)   (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
 #endif
 
+#if !HAVE_IOVEC
+struct iovec {
+    void *iov_base;
+    size_t iov_len;
+};
+#endif
+
+#if !HAVE_MSGHDR
 struct msghdr {
     void *msg_name;             /* Address to send to/receive from.  */
     socklen_t msg_namelen;      /* Length of address data.  */
@@ -72,19 +83,19 @@ struct msghdr {
 
     int msg_flags;              /* Flags on received message.  */
 };
+#endif
 
-struct iovec {
-    void *iov_base;
-    size_t iov_len;
-};
+#if !HAVE_SOCKADDR_UN
 struct sockaddr_un {
     char sun_family;
     char sun_path[256];   /* pathname */
 };
+#endif
+
+#ifndef SUN_LEN
 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)        \
         + strlen ((ptr)->sun_path))
-
-#endif /* CMSG_SPACE */
+#endif
 
 #ifndef SCM_RIGHTS
 #define SCM_RIGHTS 1
@@ -100,8 +111,6 @@ struct sockaddr_un {
 #define AF_LOCAL 1
 #endif
 
-#endif /* CMSG_H_ */
-
 // CMSG_SPACE is not constant on some systems (in particular Max OS X),
 // provide a replacement that can be used at build time in that case
 // NP: this must go below our replacement definitions.
index 33180cb9808f5db9a9bf815d454b2681dc2bd9de..2d708d3ce96b1fdb3c85109cb3c7c5f83585ab32 100644 (file)
@@ -3131,6 +3131,45 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   AC_MSG_RESULT(no)
 ])
 
+SQUID_CHECK_STRUCT([cmsghdr],[
+  #if HAVE_SYS_SOCKET_H
+  #include <sys/socket.h>
+  #endif
+  #if HAVE_WINSOCK2_H
+  #include <winsock2.h>
+  #endif
+])
+
+SQUID_CHECK_STRUCT([iovec],[
+  #if HAVE_SYS_SOCKET_H
+  #include <sys/socket.h>
+  #endif
+  #if HAVE_WINSOCK2_H
+  #include <winsock2.h>
+  #endif
+])
+
+SQUID_CHECK_STRUCT([msghdr],[
+  #if HAVE_SYS_SOCKET_H
+  #include <sys/socket.h>
+  #endif
+  #if HAVE_WINSOCK2_H
+  #include <winsock2.h>
+  #endif
+])
+
+SQUID_CHECK_STRUCT([sockaddr_un],[
+  #if HAVE_SYS_UN_H
+  #include <sys/un.h>
+  #endif
+  #if HAVE_SYS_SOCKET_H
+  #include <sys/socket.h>
+  #endif
+  #if HAVE_WINSOCK2_H
+  #include <winsock2.h>
+  #endif
+])
+
 SQUID_CHECK_FUNC_STRNSTR
 SQUID_CHECK_FUNC_VACOPY
 SQUID_CHECK_FUNC___VACOPY