bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3] Add AF_UNIX test of socket familly


From: Bastien ROUCARIES
Subject: [PATCH 1/3] Add AF_UNIX test of socket familly
Date: Tue, 1 Mar 2011 14:53:04 +0100

Test availability of AF_UNIX socket familly. It will be used by 
sendfd/receivefd.
---
 m4/afunix.m4   |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 m4/sockpfaf.m4 |   23 +++++++++++++-
 2 files changed, 119 insertions(+), 1 deletions(-)
 create mode 100644 m4/afunix.m4

diff --git a/m4/afunix.m4 b/m4/afunix.m4
new file mode 100644
index 0000000..4b8145c
--- /dev/null
+++ b/m4/afunix.m4
@@ -0,0 +1,97 @@
+# atoll.m4 serial 1
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_SOCKET_AFUNIX],
+[
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  AC_REQUIRE([gl_SOCKET_FAMILIES])
+
+  AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHT])
+  AC_CACHE_VAL([gl_cv_socket_unix_scm_rights],
+  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+]],
+[[struct cmsghdr cmh;
+  cmh.cmsg_level = SOL_SOCKET;
+  cmh.cmsg_type = SCM_RIGHTS;
+  if (&cmh) return 0;]])],
+  gl_cv_socket_unix_scm_rights=yes, gl_cv_socket_unix_scm_rights=no)])
+  AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights])
+  if test $gl_cv_socket_unix_scm_rights = yes; then
+    AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS], [1], [Define to 1 if 
<sys/socket.h> defines SCM_RIGHTS.])
+  fi   
+
+  AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHT behave in BSD4.4 way])
+  AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd44],
+  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+]],
+[[struct msghdr msg = {0};
+  struct cmsghdr *cmsg;
+  int myfds[1] = {0};
+  char buf[CMSG_SPACE(sizeof(myfds))];
+  int *fdptr;
+
+  msg.msg_control = buf;
+  msg.msg_controllen = sizeof buf;
+  cmsg = CMSG_FIRSTHDR(&msg);
+  cmsg->cmsg_level = SOL_SOCKET;
+  cmsg->cmsg_type = SCM_RIGHTS;
+  cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+  /* Initialize the payload: */
+  fdptr = (int *) CMSG_DATA(cmsg);
+  *fdptr = myfds[0];
+  /* Sum of the length of all control messages in the buffer: */
+  msg.msg_controllen = cmsg->cmsg_len;
+  return 0;
+]])],
+  gl_cv_socket_unix_scm_rights_bsd44=yes, 
gl_cv_socket_unix_scm_rights_bsd44=no)])
+  AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd44])
+  if test $gl_cv_socket_unix_scm_rights_bsd44 = yes; then
+    AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44], [1], [Define to 1 if fd 
could be send/received in the BSD4.4 way.])
+  fi
+
+  AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHT behave in BSD4.3 way])
+  AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd43],
+  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+]],
+[[struct msghdr msg;
+  int fd = 0;
+  msg.msg_accrights = &fd;
+  msg.msg_accrightslen = sizeof(fd);
+  if (&msg) return 0;]])],
+  gl_cv_socket_unix_scm_rights_bsd43=yes, 
gl_cv_socket_unix_scm_rights_bsd43=no)])
+  AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd43])
+  if test $gl_cv_socket_unix_scm_rights = yes; then
+    AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43], [1], [Define to 1 if fd 
could be send/received in the BSD4.3 way.])
+  fi
+])
+
diff --git a/m4/sockpfaf.m4 b/m4/sockpfaf.m4
index 27899aa..b8a64ad 100644
--- a/m4/sockpfaf.m4
+++ b/m4/sockpfaf.m4
@@ -1,4 +1,4 @@
-# sockpfaf.m4 serial 7
+# sockpfaf.m4 serial 8
 dnl Copyright (C) 2004, 2006, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -58,4 +58,25 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
   if test $gl_cv_socket_ipv6 = yes; then
     AC_DEFINE([HAVE_IPV6], [1], [Define to 1 if <sys/socket.h> defines 
AF_INET6.])
   fi
+
+  AC_CHECK_HEADERS_ONCE([sys/un.h])
+  AC_MSG_CHECKING([for UNIX domain sockets])
+  AC_CACHE_VAL([gl_cv_socket_unix],
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif]],
+[[int x = AF_UNIX; struct sockaddr_un y;
+ if (&x && &y) return 0;]])],
+       gl_cv_socket_unix=yes, gl_cv_socket_unix=no)])
+  AC_MSG_RESULT([$gl_cv_socket_unix])
+  if test $gl_cv_socket_unix = yes; then
+    AC_DEFINE([HAVE_UNIXSOCKET], [1], [Define to 1 if <sys/socket.h> defines 
AF_UNIX.])
+  fi
 ])
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]