# HG changeset patch # User Simon Josefsson # Date 1241792494 -7200 # Node ID 054e549de00c918a83eb6ac09de75d4271e702e8 # Parent 49088322adb6cfaf47fcfa8586525b929c72ef1a sys_socket: Define sockaddr_storage. diff -r 49088322adb6 -r 054e549de00c ChangeLog --- a/ChangeLog Fri May 08 13:21:34 2009 +0200 +++ b/ChangeLog Fri May 08 16:21:34 2009 +0200 @@ -1,3 +1,11 @@ +2009-05-07 Simon Josefsson + + * 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 Use module 'alignof'. diff -r 49088322adb6 -r 054e549de00c lib/sys_socket.in.h --- a/lib/sys_socket.in.h Fri May 08 13:21:34 2009 +0200 +++ b/lib/sys_socket.in.h Fri May 08 16:21:34 2009 +0200 @@ -43,6 +43,24 @@ #ifndef _GL_SYS_SOCKET_H #define _GL_SYS_SOCKET_H +#if !@HAVE_STRUCT_SOCKADDR_STORAGE@ +#include +/* 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 . */ diff -r 49088322adb6 -r 054e549de00c m4/sys_socket_h.m4 --- a/m4/sys_socket_h.m4 Fri May 08 13:21:34 2009 +0200 +++ b/m4/sys_socket_h.m4 Fri May 08 16:21:34 2009 +0200 @@ -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 @@ 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 +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#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 replacement. gl_CHECK_NEXT_HEADERS([sys/socket.h]) @@ -114,4 +130,5 @@ 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 -r 49088322adb6 -r 054e549de00c modules/sys_socket --- a/modules/sys_socket Fri May 08 13:21:34 2009 +0200 +++ b/modules/sys_socket Fri May 08 16:21:34 2009 +0200 @@ -10,6 +10,7 @@ include_next link-warning errno +alignof configure.ac: gl_HEADER_SYS_SOCKET @@ -44,6 +45,7 @@ -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; \ } > $@-t diff -r 49088322adb6 -r 054e549de00c tests/test-sys_socket.c --- a/tests/test-sys_socket.c Fri May 08 13:21:34 2009 +0200 +++ b/tests/test-sys_socket.c Fri May 08 16:21:34 2009 +0200 @@ -1,5 +1,5 @@ /* Test of 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 main () { + struct sockaddr_storage x; + /* Check some errno values. */ switch (0) { @@ -43,5 +45,7 @@ break; } + x.ss_family = 42; + return 0; }