This is the mail archive of the libc-hacker@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

struct sockaddr_storage


Here's a patch to add a definition for `struct sockaddr_storage', which was 
introduced by the IPv6 API.  The intention is that it provides a block of 
memory with sufficient size and alignment that you can cast it to any `struct 
sockaddr_xxx *' and get sensible behaviour.

Please check that it doesn't cause any breakage, especially on Hurd and MIPS.

p.

1999-05-10  Philip Blundell  <philb@gnu.org>

	* sysdeps/generic/bits/socket.h (struct sockaddr_storage): New
 	structure; storage suitable for any socket address.
	* sysdeps/unix/sysv/linux/bits/socket.h: Likewise.
	* sysdeps/unix/sysv/linux/mips/bits/socket.h: Likewise.

--- libc/sysdeps/generic/bits/socket.h	Fri Apr 24 21:52:30 1998
+++ libc/sysdeps/generic/bits/socket.h	Mon May 10 20:03:52 1999
@@ -127,6 +127,25 @@
   };
 
 
+/* Structure large enough to hold any socket address (with the historical
+   exception of AF_UNIX).  We reserve 128 bytes.  */
+#include <sys/types.h>
+#if (~0UL) > 0xffffffff
+#define __ss_align	uint64_t
+#else
+#define __ss_align	uint32_t
+#endif
+#define _SS_SIZE	128
+#define _SS_PADSIZE	(_SS_SIZE - (2 * sizeof(__ss_align)))
+
+struct sockaddr_storage 
+  {
+    __SOCKADDR_COMMON (__ss_);	/* Address family, etc.  */
+    __ss_align __ss_align;	/* Force desired alignment.  */
+    char __ss_padding[_SS_PADSIZE];
+  };
+
+
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
   {
--- libc/sysdeps/unix/sysv/linux/bits/socket.h	Mon May 10 21:26:03 1999
+++ libc/sysdeps/unix/sysv/linux/bits/socket.h	Mon May 10 20:31:54 1999
@@ -139,6 +139,25 @@
   };
 
 
+/* Structure large enough to hold any socket address (with the historical
+   exception of AF_UNIX).  We reserve 128 bytes.  */
+#include <sys/types.h>
+#if (~0UL) > 0xffffffff
+#define __ss_aligntype	__uint64_t
+#else
+#define __ss_aligntype	__uint32_t
+#endif
+#define _SS_SIZE	128
+#define _SS_PADSIZE	(_SS_SIZE - (2 * sizeof(__ss_aligntype)))
+
+struct sockaddr_storage 
+  {
+    __SOCKADDR_COMMON (__ss_);	/* Address family, etc.  */
+    __ss_aligntype __ss_align;	/* Force desired alignment.  */
+    char __ss_padding[_SS_PADSIZE];
+  };
+
+
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
   {
--- libc/sysdeps/unix/sysv/linux/mips/bits/socket.h	Thu Dec 31 12:44:46 1998
+++ libc/sysdeps/unix/sysv/linux/mips/bits/socket.h	Mon May 10 20:04:06 1999
@@ -133,6 +133,25 @@
   };
 
 
+/* Structure large enough to hold any socket address (with the historical
+   exception of AF_UNIX).  We reserve 128 bytes.  */
+#include <sys/types.h>
+#if (~0UL) > 0xffffffff
+#define __ss_align	uint64_t
+#else
+#define __ss_align	uint32_t
+#endif
+#define _SS_SIZE	128
+#define _SS_PADSIZE	(_SS_SIZE - (2 * sizeof(__ss_align)))
+
+struct sockaddr_storage 
+  {
+    __SOCKADDR_COMMON (__ss_);	/* Address family, etc.  */
+    __ss_align __ss_align;	/* Force desired alignment.  */
+    char __ss_padding[_SS_PADSIZE];
+  };
+
+
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
   {




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]