This is the mail archive of the
libc-hacker@cygnus.com
mailing list for the glibc project.
Re: struct sockaddr_storage
- To: libc-hacker@cygnus.com
- Subject: Re: struct sockaddr_storage
- From: Philip Blundell <pb@nexus.co.uk>
- Date: Tue, 11 May 1999 13:11:54 +0100
In message <vyzu2tkm39z.fsf@issan.cs.uni-dortmund.de>, Andreas Schwab writes:
>This is wrong. The preprocessor must use the widest type for evaluation,
>which is intmax_t in C9x, so that ~0U is _always_ bigger than 0xffffffff
Here's an updated patch.
1999-05-11 Philip Blundell <pb@nexus.co.uk>
* sysdeps/generic/bits/socket.h (struct sockaddr_storage): New
structure; storage suitable for any socket address.
* sysdeps/unix/sysv/linux/bits/socket.h (struct sockaddr_storage):
Likewise.
* sysdeps/unix/sysv/linux/mips/bits/socket.h (struct
sockaddr_storage): Likewise.
* inet/netinet/in.h: Use ULONG_MAX not ~0 to test for a 64-bit
platform.
--- libc/inet/netinet/in.h Tue May 11 10:25:37 1999
+++ libc/inet/netinet/in.h Tue May 11 10:26:16 1999
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -20,6 +20,7 @@
#define _NETINET_IN_H 1
#include <features.h>
+#include <limits.h>
#include <stdint.h>
#include <sys/types.h>
@@ -164,7 +165,7 @@
uint8_t u6_addr8[16];
uint16_t u6_addr16[8];
uint32_t u6_addr32[4];
-#if (~0UL) > 0xffffffff
+#if ULONG_MAX > 0xffffffff
uint64_t u6_addr64[2];
#endif
} in6_u;
--- libc/sysdeps/generic/bits/socket.h Fri Apr 24 14:55:07 1998
+++ libc/sysdeps/generic/bits/socket.h Tue May 11 10:24:13 1999
@@ -1,5 +1,5 @@
/* System-specific socket constants and types. Generic/4.3 BSD version.
- Copyright (C) 1991, 92, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+ Copyright (C) 1991, 92, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -27,6 +27,9 @@
#define __need_size_t
#include <stddef.h>
+#include <limits.h>
+#include <sys/types.h>
+
/* Type for length arguments in socket calls. */
typedef unsigned int socklen_t;
@@ -124,6 +127,24 @@
{
__SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
char sa_data[14]; /* Address data. */
+ };
+
+
+/* Structure large enough to hold any socket address (with the historical
+ exception of AF_UNIX). We reserve 128 bytes. */
+#if ULONG_MAX > 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];
};
--- libc/sysdeps/unix/sysv/linux/bits/socket.h Mon Apr 19 10:10:35 1999
+++ libc/sysdeps/unix/sysv/linux/bits/socket.h Tue May 11 10:23:29 1999
@@ -28,6 +28,7 @@
#define __need_NULL
#include <stddef.h>
+#include <limits.h>
#include <sys/types.h>
/* Type for length arguments in socket calls. */
@@ -136,6 +137,24 @@
{
__SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
char sa_data[14]; /* Address data. */
+ };
+
+
+/* Structure large enough to hold any socket address (with the historical
+ exception of AF_UNIX). We reserve 128 bytes. */
+#if ULONG_MAX > 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];
};
--- libc/sysdeps/unix/sysv/linux/mips/bits/socket.h Sat Nov 28 21:04:24 1998
+++ libc/sysdeps/unix/sysv/linux/mips/bits/socket.h Tue May 11 10:24:03 1999
@@ -1,5 +1,5 @@
/* System-specific socket constants and types. Linux/MIPS version.
- Copyright (C) 1991, 92, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+ Copyright (C) 1991, 92, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -28,6 +28,7 @@
#define __need_NULL
#include <stddef.h>
+#include <limits.h>
#include <sys/types.h>
/* Type for length arguments in socket calls. */
@@ -130,6 +131,24 @@
{
__SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
char sa_data[14]; /* Address data. */
+ };
+
+
+/* Structure large enough to hold any socket address (with the historical
+ exception of AF_UNIX). We reserve 128 bytes. */
+#if ULONG_MAX > 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];
};