about summary refs log tree commit diff
path: root/sysdeps/unix/bsd/bits/sockaddr.h
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2019-06-06 09:49:54 -0400
committerZack Weinberg <zackw@panix.com>2020-01-08 14:15:42 -0500
commit94ab7b6b7f5b7f424554e325c20f60f706efc207 (patch)
treeedfbeab9619c7ecdc74f25326c8b4fcc428b53bb /sysdeps/unix/bsd/bits/sockaddr.h
parent0e8caaf081a844893aa5bbf67010c3e34ca47f34 (diff)
downloadglibc-94ab7b6b7f5b7f424554e325c20f60f706efc207.tar.gz
glibc-94ab7b6b7f5b7f424554e325c20f60f706efc207.tar.xz
glibc-94ab7b6b7f5b7f424554e325c20f60f706efc207.zip
Don’t include sys/socket.h from public headers.
No standard public header is required to include sys/socket.h,
although some are allowed to.  Several public headers need the
definitions of socklen_t, struct sockaddr, and/or struct
sockaddr_storage, but nothing else from sys/socket.h.  We already have
a single-type header for socklen_t, so this patch adds single-type
headers for struct sockaddr and struct sockaddr_storage.

The definition of struct sockaddr_storage is subtly different on Linux
than on the Hurd; in order to not need two copies of
bits/types/struct_sockaddr_storage.h, bits/sockaddr.h is now
responsible for defining __ss_aligntype if ‘unsigned long int’ is not
the correct definition.

I also added a single-type header for struct linger, even though only
sys/socket.h is expected to define that, just because all three copies
of bits/socket.h were defining it exactly the same way.  There would
also be a case for defining it directly in sys/socket.h but this
seemed tidier.

I did *not* create single-type headers for struct msghdr and struct
cmsghdr, because those and their helper macros are not consistent
among the three copies of bits/socket.h, and, again, only sys/socket.h
is expected to define them.

The large number of .c files that add an `#include <sys/socket.h>`
might make this look like it’s not worth doing.  However, after this
change, only half of the files in the glibc source tree that include
netinet/in.h also need to include sys/socket.h, and only a third of
the files that include netdb.h need to include sys/socket.h.  Before,
all of the files in both groups were getting sys/socket.h.  That seems
like enough justification to me.

While I was at it I noticed that sys/socketvar.h is yet another
backward compatibility header that does nothing but include some other
header (sys/socket.h, in this case) and also doesn’t need to be
system-dependent.

	* socket/bits/types/struct_linger.h
	* socket/bits/types/struct_sockaddr.h
	* socket/bits/types/struct_sockaddr_storage.h:
	New single-type headers, factored out of the various bits/socket.h
	headers.

	* include/bits/types/struct_linger.h
	* include/bits/types/struct_sockaddr.h
	* include/bits/types/struct_sockaddr_storage.h:
	New wrappers.

	* socket/Makefile (headers): Add bits/types/struct_linger.h,
	bits/types/struct_sockaddr.h, and bits/types/struct_sockaddr_storage.h.
	Alphabetize the list.

	* bits/socket.h, sysdeps/mach/hurd/bits/socket.h
	* sysdeps/unix/sysv/linux/bits/socket.h:
	Don’t define struct sockaddr, struct sockaddr_storage,
	__ss_aligntype, or struct linger here.  Minimize inclusions.
	* sysdeps/unix/bsd/bits/sockaddr.h: Define __ss_aligntype here.

	* socket/sys/socket.h: Include bits/types/struct_linger.h,
	bits/sockaddr.h, bits/types/struct_sockaddr.h, and
	bits/types/struct_sockaddr_storage.h.  Move inclusion of
	bits/socket.h below forward declaration of struct timespec,
	and update commentary.

	* inet/ifaddrs.h, socket/net/if.h
	* sysdeps/mach/hurd/net/if_arp.h
	* sysdeps/mach/hurd/net/route.h
	* sysdeps/unix/sysv/linux/errqueue.h
	* sysdeps/unix/sysv/linux/net/if_arp.h
	* sysdeps/unix/sysv/linux/net/route.h:
	Include bits/types/struct_sockaddr.h and possibly also bits/types.h,
	not sys/socket.h or sys/types.h.

	* sysdeps/unix/sysv/linux/errqueue.h:
	* sysdeps/unix/sysv/linux/net/route.h:
	Use __uint8_t and __uint32_t instead of uint8_t and uint32_t.

	* inet/arpa/inet.h: Include bits/types/size_t.h.
	* inet/netinet/in.h: Include bits/sockaddr.h,
	bits/types/struct_sockaddr.h, and
	bits/types/struct_sockaddr_storage.h,
	not sys/socket.h.  Use __socklen_t instead of socklen_t.
	* inet/netinet/tcp.h: Include bits/types.h and
	bits/types/struct_sockaddr_storage.h, not sys/socket.h or
	bits/stdint-uintn.h.  Use __uint8_t, __uint16_t, and __uint32_t
	instead of uint8_t, uint16_t and uint32_t.
	* inet/protocols/routed.h: Include features.h and
	bits/types/struct_sockaddr.h, not sys/socket.h.
	* resolv/netdb.h: Include bits/types/socklen_t.h.
	* sysdeps/unix/sysv/linux/netatalk/at.h: Don’t include sys/socket.h.

	* include/ifaddrs.h: Include stddef.h for size_t.
	* include/netdb.h: Use __socklen_t instead of socklen_t.

	* inet/check_pf.c, inet/gethstbynm.c, inet/gethstbynm_r.c
	* inet/getsourcefilter.c, inet/inet6_opt.c, inet/inet6_option.c
        * inet/inet6_rth.c, inet/setsourcefilter.c, inet/test-ifaddrs.c
	* inet/test-inet6_opt.c, inet/tst-inet6_rth.c
	* inet/tst-inet6_scopeid_pton.c, nis/nss_nis/nis-hosts.c
	* nis/nss_nisplus/nisplus-hosts.c, nscd/aicache.c, nscd/cache.c
	* nscd/hstcache.c, nscd/initgrcache.c, nscd/netgroupcache.c
	* nscd/nscd_gethst_r.c, nscd/servicescache.c, nss/digits_dots.c
	* nss/nss_files/files-hosts.c, nss/nss_files/files-network.c
	* nss/tst-nss-files-hosts-erange.c, nss/tst-nss-files-hosts-getent.c
	* nss/tst-nss-files-hosts-multi.c, posix/tst-getaddrinfo3.c
	* resolv/nss_dns/dns-network.c, resolv/resolv_conf.c
	* resolv/tst-bug18665-tcp.c, resolv/tst-bug18665.c
	* resolv/tst-inet_ntop.c, resolv/tst-inet_pton.c
	* resolv/tst-resolv-ai_idn-common.c, resolv/tst-resolv-basic.c
	* resolv/tst-resolv-edns.c, resolv/tst-resolv-network.c
	* resolv/tst-resolv-nondecimal.c, resolv/tst-resolv-search.c
	* resolv/tst-resolv-threads.c, resolv/tst-resolv-trailing.c
	* sunrpc/rpc_gethostbyname.c
	* support/support_format_address_family.c
	* support/support_format_addrinfo.c
	* support/support_format_dns_packet.c
	* support/support_format_hostent.c, support/support_format_netent.c
	* sysdeps/mach/hurd/if_index.c
	* sysdeps/unix/sysv/linux/check_native.c: Include sys/socket.h.

	* resolv/tst-resolv-binary.c: Include sys/types.h.

	* sysdeps/generic/sys/socketvar.h: Move to socket/sys/socketvar.h.
	* include/sys/socketvar.h: New wrapper.

	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
	Update.
Diffstat (limited to 'sysdeps/unix/bsd/bits/sockaddr.h')
-rw-r--r--sysdeps/unix/bsd/bits/sockaddr.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/sysdeps/unix/bsd/bits/sockaddr.h b/sysdeps/unix/bsd/bits/sockaddr.h
index e2719bbc9c..bb7ecffd1b 100644
--- a/sysdeps/unix/bsd/bits/sockaddr.h
+++ b/sysdeps/unix/bsd/bits/sockaddr.h
@@ -42,4 +42,13 @@ typedef unsigned char sa_family_t;
 /* Size of struct sockaddr_storage.  */
 #define _SS_SIZE 128
 
+/* Desired alignment for struct sockaddr_storage.  */
+#include <bits/types.h>
+#include <bits/wordsize.h>
+#if __WORDSIZE == 64
+# define __ss_aligntype __uint64_t
+#else
+# define __ss_aligntype __uint32_t
+#endif
+
 #endif	/* bits/sockaddr.h */