bug-gnulib
[Top][All Lists]
Advanced

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

Re: sys_socket: sockaddr_storage, new module alignof


From: Simon Josefsson
Subject: Re: sys_socket: sockaddr_storage, new module alignof
Date: Fri, 08 May 2009 16:22:34 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.93 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Simon Josefsson wrote:
>> Looks fine to me.  If you push it, I can make sys_socket depend on it.
>
> Pushed.

Thanks.  I have pushed the patch below.

/Simon

>From 014f60069ce88c16683c533813b2463771ac2d0b Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Fri, 8 May 2009 16:21:34 +0200
Subject: [PATCH] sys_socket: Define sockaddr_storage.

---
 ChangeLog               |    8 ++++++++
 lib/sys_socket.in.h     |   18 ++++++++++++++++++
 m4/sys_socket_h.m4      |   19 ++++++++++++++++++-
 modules/sys_socket      |    2 ++
 tests/test-sys_socket.c |    6 +++++-
 5 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 92c696a..aef3402 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-05-07  Simon Josefsson  <address@hidden>
+
+       * modules/sys_socket (Makefile.am): Substitute
+       HAVE_STRUCT_SOCKADDR_STORAGE.  Depend on alignof.
+       * m4/sys_socket_h.m4: Check for sockaddr_storage.
+       * lib/sys_socket.in.h (sockaddr_storage): Define when needed.
+       * tests/test-sys_socket.c: Check sockaddr_storage.
+
 2009-05-08  Bruno Haible  <address@hidden>
 
        Use module 'alignof'.
diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h
index 6508bf7..50d9d3d 100644
--- a/lib/sys_socket.in.h
+++ b/lib/sys_socket.in.h
@@ -43,6 +43,24 @@
 #ifndef _GL_SYS_SOCKET_H
 #define _GL_SYS_SOCKET_H
 
+#if address@hidden@
+#include <alignof.h>
+/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
+   2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */
+#define __ss_aligntype  unsigned long int
+#define _SS_SIZE       256
+#define _SS_PADSIZE    (_SS_SIZE - (max (sizeof (sa_family_t),         \
+                                         alignof (__ss_aligntype))     \
+                                    + sizeof (__ss_aligntype)))
+
+struct sockaddr_storage
+{
+  sa_family_t ss_family;      /* Address family, etc.  */
+  __ss_aligntype __ss_align;  /* Force desired alignment.  */
+  char __ss_padding[_SS_PADSIZE];
+};
+#endif
+
 #if @HAVE_SYS_SOCKET_H@
 
 /* A platform that has <sys/socket.h>.  */
diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4
index 85a0ace..5bbaad8 100644
--- a/m4/sys_socket_h.m4
+++ b/m4/sys_socket_h.m4
@@ -1,5 +1,5 @@
 # sys_socket_h.m4 serial 12
-dnl Copyright (C) 2005-2008 Free Software Foundation, Inc.
+dnl Copyright (C) 2005-2009 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.
@@ -40,6 +40,22 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
   else
     SYS_SOCKET_H='sys/socket.h'
   fi
+  AC_CHECK_TYPES([struct sockaddr_storage],,,[
+  /* sys/types.h is not needed according to POSIX, but the
+     sys/socket.h in i386-unknown-freebsd4.10 and
+     powerpc-apple-darwin5.5 required it. */
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+])
+  if test $ac_cv_type_struct_sockaddr_storage = no; then
+    HAVE_STRUCT_SOCKADDR_STORAGE=0
+    SYS_SOCKET_H='sys/socket.h'
+  fi
   if test -n "$SYS_SOCKET_H"; then
     dnl Check prerequisites of the <sys/socket.h> replacement.
     gl_CHECK_NEXT_HEADERS([sys/socket.h])
@@ -114,4 +130,5 @@ AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
   GNULIB_SENDTO=0;      AC_SUBST([GNULIB_SENDTO])
   GNULIB_SETSOCKOPT=0;  AC_SUBST([GNULIB_SETSOCKOPT])
   GNULIB_SHUTDOWN=0;    AC_SUBST([GNULIB_SHUTDOWN])
+  HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
 ])
diff --git a/modules/sys_socket b/modules/sys_socket
index 011fe69..27bbbcc 100644
--- a/modules/sys_socket
+++ b/modules/sys_socket
@@ -10,6 +10,7 @@ Depends-on:
 include_next
 link-warning
 errno
+alignof
 
 configure.ac:
 gl_HEADER_SYS_SOCKET
@@ -44,6 +45,7 @@ sys/socket.h: sys_socket.in.h
              -e 's|@''GNULIB_SHUTDOWN''@|$(GNULIB_SHUTDOWN)|g' \
              -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
              -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
+             -e 
's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/sys_socket.in.h; \
        } > address@hidden
diff --git a/tests/test-sys_socket.c b/tests/test-sys_socket.c
index b7395b3..fe7688e 100644
--- a/tests/test-sys_socket.c
+++ b/tests/test-sys_socket.c
@@ -1,5 +1,5 @@
 /* Test of <sys/socket.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -30,6 +30,8 @@ int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };
 int
 main ()
 {
+  struct sockaddr_storage x;
+
   /* Check some errno values.  */
   switch (0)
     {
@@ -43,5 +45,7 @@ main ()
       break;
     }
 
+  x.ss_family = 42;
+
   return 0;
 }
-- 
1.6.2.4




reply via email to

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