about summary refs log tree commit diff
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
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.
-rw-r--r--bits/socket.h39
-rw-r--r--include/bits/types/struct_linger.h1
-rw-r--r--include/bits/types/struct_sockaddr.h1
-rw-r--r--include/bits/types/struct_sockaddr_storage.h1
-rw-r--r--include/ifaddrs.h1
-rw-r--r--include/netdb.h8
-rw-r--r--include/sys/socketvar.h1
-rw-r--r--inet/arpa/inet.h1
-rw-r--r--inet/check_pf.c1
-rw-r--r--inet/gethstbynm.c1
-rw-r--r--inet/gethstbynm_r.c1
-rw-r--r--inet/getsourcefilter.c1
-rw-r--r--inet/ifaddrs.h2
-rw-r--r--inet/inet6_opt.c1
-rw-r--r--inet/inet6_option.c1
-rw-r--r--inet/inet6_rth.c1
-rw-r--r--inet/netinet/in.h35
-rw-r--r--inet/netinet/tcp.h188
-rw-r--r--inet/protocols/routed.h4
-rw-r--r--inet/setsourcefilter.c2
-rw-r--r--inet/test-ifaddrs.c1
-rw-r--r--inet/test-inet6_opt.c1
-rw-r--r--inet/tst-inet6_rth.c1
-rw-r--r--inet/tst-inet6_scopeid_pton.c1
-rw-r--r--nis/nss_nis/nis-hosts.c1
-rw-r--r--nis/nss_nisplus/nisplus-hosts.c1
-rw-r--r--nscd/aicache.c1
-rw-r--r--nscd/cache.c1
-rw-r--r--nscd/hstcache.c1
-rw-r--r--nscd/initgrcache.c1
-rw-r--r--nscd/netgroupcache.c1
-rw-r--r--nscd/nscd_gethst_r.c1
-rw-r--r--nscd/servicescache.c1
-rw-r--r--nss/digits_dots.c1
-rw-r--r--nss/nss_files/files-hosts.c1
-rw-r--r--nss/nss_files/files-network.c1
-rw-r--r--nss/tst-nss-files-hosts-erange.c1
-rw-r--r--nss/tst-nss-files-hosts-getent.c1
-rw-r--r--nss/tst-nss-files-hosts-multi.c1
-rw-r--r--posix/tst-getaddrinfo3.c1
-rw-r--r--resolv/netdb.h1
-rw-r--r--resolv/nss_dns/dns-network.c1
-rw-r--r--resolv/resolv_conf.c1
-rw-r--r--resolv/tst-bug18665-tcp.c1
-rw-r--r--resolv/tst-bug18665.c1
-rw-r--r--resolv/tst-inet_ntop.c1
-rw-r--r--resolv/tst-inet_pton.c1
-rw-r--r--resolv/tst-resolv-ai_idn-common.c1
-rw-r--r--resolv/tst-resolv-basic.c1
-rw-r--r--resolv/tst-resolv-binary.c1
-rw-r--r--resolv/tst-resolv-edns.c1
-rw-r--r--resolv/tst-resolv-network.c1
-rw-r--r--resolv/tst-resolv-nondecimal.c1
-rw-r--r--resolv/tst-resolv-search.c1
-rw-r--r--resolv/tst-resolv-threads.c1
-rw-r--r--resolv/tst-resolv-trailing.c1
-rwxr-xr-xscripts/check-obsolete-constructs.py12
-rw-r--r--socket/Makefile8
-rw-r--r--socket/bits/types/struct_linger.h11
-rw-r--r--socket/bits/types/struct_sockaddr.h15
-rw-r--r--socket/bits/types/struct_sockaddr_storage.h21
-rw-r--r--socket/net/if.h2
-rw-r--r--socket/sys/socket.h13
-rw-r--r--socket/sys/socketvar.h (renamed from sysdeps/generic/sys/socketvar.h)0
-rw-r--r--sunrpc/rpc_gethostbyname.c1
-rw-r--r--support/support_format_address_family.c1
-rw-r--r--support/support_format_addrinfo.c1
-rw-r--r--support/support_format_dns_packet.c1
-rw-r--r--support/support_format_hostent.c1
-rw-r--r--support/support_format_netent.c1
-rw-r--r--sysdeps/mach/hurd/bits/socket.h40
-rw-r--r--sysdeps/mach/hurd/if_index.c1
-rw-r--r--sysdeps/mach/hurd/net/if_arp.h3
-rw-r--r--sysdeps/mach/hurd/net/route.h2
-rw-r--r--sysdeps/unix/bsd/bits/sockaddr.h9
-rw-r--r--sysdeps/unix/sysv/linux/bits/socket.h35
-rw-r--r--sysdeps/unix/sysv/linux/check_native.c1
-rw-r--r--sysdeps/unix/sysv/linux/errqueue.h19
-rw-r--r--sysdeps/unix/sysv/linux/net/if_arp.h3
-rw-r--r--sysdeps/unix/sysv/linux/net/route.h17
-rw-r--r--sysdeps/unix/sysv/linux/netatalk/at.h3
81 files changed, 277 insertions, 271 deletions
diff --git a/bits/socket.h b/bits/socket.h
index c844429ab8..fb30f9dac4 100644
--- a/bits/socket.h
+++ b/bits/socket.h
@@ -23,10 +23,6 @@
 # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
 #endif
 
-#include <bits/wordsize.h>
-#include <bits/types.h>
-#include <bits/types/size_t.h>
-#include <bits/types/socklen_t.h>
 
 /* Types of sockets.  */
 enum __socket_type
@@ -137,34 +133,6 @@ enum __socket_type
 /* Maximum queue length specifiable by listen.  */
 #define SOMAXCONN	128	/* 5 on the origional 4.4 BSD.  */
 
-/* Get the definition of the macro to define the common sockaddr members.  */
-#include <bits/sockaddr.h>
-
-/* Structure describing a generic socket address.  */
-struct sockaddr
-  {
-    __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).  */
-#if __WORDSIZE == 64
-# define __ss_aligntype	__uint64_t
-#else
-# define __ss_aligntype	__uint32_t
-#endif
-#define _SS_PADSIZE \
-  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
-
-struct sockaddr_storage
-  {
-    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
-    char __ss_padding[_SS_PADSIZE];
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
-  };
-
 
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
@@ -347,11 +315,4 @@ enum
 #define SO_TYPE SO_TYPE
   };
 
-/* Structure used to manipulate the SO_LINGER option.  */
-struct linger
-  {
-    int l_onoff;		/* Nonzero to linger on close.  */
-    int l_linger;		/* Time to linger.  */
-  };
-
 #endif	/* bits/socket.h */
diff --git a/include/bits/types/struct_linger.h b/include/bits/types/struct_linger.h
new file mode 100644
index 0000000000..55b2f20dd7
--- /dev/null
+++ b/include/bits/types/struct_linger.h
@@ -0,0 +1 @@
+#include <socket/bits/types/struct_linger.h>
diff --git a/include/bits/types/struct_sockaddr.h b/include/bits/types/struct_sockaddr.h
new file mode 100644
index 0000000000..641fbcd56d
--- /dev/null
+++ b/include/bits/types/struct_sockaddr.h
@@ -0,0 +1 @@
+#include <socket/bits/types/struct_sockaddr.h>
diff --git a/include/bits/types/struct_sockaddr_storage.h b/include/bits/types/struct_sockaddr_storage.h
new file mode 100644
index 0000000000..68f3171f0c
--- /dev/null
+++ b/include/bits/types/struct_sockaddr_storage.h
@@ -0,0 +1 @@
+#include <socket/bits/types/struct_sockaddr_storage.h>
diff --git a/include/ifaddrs.h b/include/ifaddrs.h
index 416118f1b3..bea810b161 100644
--- a/include/ifaddrs.h
+++ b/include/ifaddrs.h
@@ -3,6 +3,7 @@
 
 # ifndef _ISOMAC
 
+#include <stddef.h>
 #include <stdbool.h>
 #include <stdint.h>
 
diff --git a/include/netdb.h b/include/netdb.h
index e230b1f4fc..7853769ebe 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -39,21 +39,21 @@ extern int __old_gethostent_r (struct hostent *__restrict __result_buf,
 			       int *__restrict __h_errnop);
 
 extern int __gethostbyaddr_r (const void *__restrict __addr,
-			      socklen_t __len, int __type,
+			      __socklen_t __len, int __type,
 			      struct hostent *__restrict __result_buf,
 			      char *__restrict __buf, size_t __buflen,
 			      struct hostent **__restrict __result,
 			      int *__restrict __h_errnop)
      attribute_hidden;
 extern int __old_gethostbyaddr_r (const void *__restrict __addr,
-				  socklen_t __len, int __type,
+				  __socklen_t __len, int __type,
 				  struct hostent *__restrict __result_buf,
 				  char *__restrict __buf, size_t __buflen,
 				  struct hostent **__restrict __result,
 				  int *__restrict __h_errnop);
 
 extern int __gethostbyaddr2_r (const void *__restrict __addr,
-			       socklen_t __len, int __type,
+			       __socklen_t __len, int __type,
 			       struct hostent *__restrict __result_buf,
 			       char *__restrict __buf, size_t __buflen,
 			       struct hostent **__restrict __result,
@@ -246,7 +246,7 @@ extern enum nss_status _nss_ ## service ## _gethostbyname_r		      \
 		       (const char *name, struct hostent *host, char *buffer, \
 			size_t buflen, int *errnop, int *h_errnop);	      \
 extern enum nss_status _nss_ ## service ## _gethostbyaddr_r		      \
-		       (const void *addr, socklen_t addrlen, int af,	      \
+		       (const void *addr, __socklen_t addrlen, int af,	      \
 			struct hostent *host, char *buffer, size_t buflen,    \
 			int *errnop, int *h_errnop);			      \
 extern enum nss_status _nss_ ## service ## _setservent (int);		      \
diff --git a/include/sys/socketvar.h b/include/sys/socketvar.h
new file mode 100644
index 0000000000..658fd10b85
--- /dev/null
+++ b/include/sys/socketvar.h
@@ -0,0 +1 @@
+#include <socket/sys/socketvar.h>
diff --git a/inet/arpa/inet.h b/inet/arpa/inet.h
index 08837249fa..2625d2f2e6 100644
--- a/inet/arpa/inet.h
+++ b/inet/arpa/inet.h
@@ -20,6 +20,7 @@
 
 #include <features.h>
 #include <netinet/in.h>		/* To define `struct in_addr'.  */
+#include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 
 __BEGIN_DECLS
diff --git a/inet/check_pf.c b/inet/check_pf.c
index 323bd842f4..8c3438eef3 100644
--- a/inet/check_pf.c
+++ b/inet/check_pf.c
@@ -19,6 +19,7 @@
 #include <ifaddrs.h>
 #include <netdb.h>
 #include <stdint.h>
+#include <sys/socket.h>
 
 void
 attribute_hidden
diff --git a/inet/gethstbynm.c b/inet/gethstbynm.c
index e5eb4c9ceb..2cbd31974d 100644
--- a/inet/gethstbynm.c
+++ b/inet/gethstbynm.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <netdb.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 
diff --git a/inet/gethstbynm_r.c b/inet/gethstbynm_r.c
index 9e4b9e2e96..3c3d4cda59 100644
--- a/inet/gethstbynm_r.c
+++ b/inet/gethstbynm_r.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <netdb.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <resolv/res_hconf.h>
diff --git a/inet/getsourcefilter.c b/inet/getsourcefilter.c
index c2e67b0fa5..5b1beaf00a 100644
--- a/inet/getsourcefilter.c
+++ b/inet/getsourcefilter.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <netinet/in.h>
 #include <stdint.h>
+#include <sys/socket.h>
 
 int
 getsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
diff --git a/inet/ifaddrs.h b/inet/ifaddrs.h
index ffcd66d97c..4868942dcd 100644
--- a/inet/ifaddrs.h
+++ b/inet/ifaddrs.h
@@ -20,7 +20,7 @@
 #define _IFADDRS_H	1
 
 #include <features.h>
-#include <sys/socket.h>
+#include <bits/types/struct_sockaddr.h>
 
 __BEGIN_DECLS
 
diff --git a/inet/inet6_opt.c b/inet/inet6_opt.c
index 715f6f8301..bc55dc8da9 100644
--- a/inet/inet6_opt.c
+++ b/inet/inet6_opt.c
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
 
diff --git a/inet/inet6_option.c b/inet/inet6_option.c
index 48b2aed1ce..bdbce502de 100644
--- a/inet/inet6_option.c
+++ b/inet/inet6_option.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
 #include <sys/param.h>
diff --git a/inet/inet6_rth.c b/inet/inet6_rth.c
index 09ac6b5cfb..d53c5a5751 100644
--- a/inet/inet6_rth.c
+++ b/inet/inet6_rth.c
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip6.h>
 
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
index 993cfe6ae8..81568819a4 100644
--- a/inet/netinet/in.h
+++ b/inet/netinet/in.h
@@ -19,10 +19,11 @@
 #define	_NETINET_IN_H	1
 
 #include <features.h>
-#include <bits/stdint-uintn.h>
-#include <sys/socket.h>
 #include <bits/types.h>
-
+#include <bits/stdint-uintn.h>
+#include <bits/sockaddr.h>
+#include <bits/types/struct_sockaddr.h>
+#include <bits/types/struct_sockaddr_storage.h>
 
 __BEGIN_DECLS
 
@@ -568,27 +569,27 @@ extern int inet6_option_find (const struct cmsghdr *__cmsg,
 
 
 /* Hop-by-Hop and Destination Options Processing (RFC 3542).  */
-extern int inet6_opt_init (void *__extbuf, socklen_t __extlen) __THROW;
-extern int inet6_opt_append (void *__extbuf, socklen_t __extlen, int __offset,
-			     uint8_t __type, socklen_t __len, uint8_t __align,
+extern int inet6_opt_init (void *__extbuf, __socklen_t __extlen) __THROW;
+extern int inet6_opt_append (void *__extbuf, __socklen_t __extlen, int __offset,
+			     uint8_t __type, __socklen_t __len, uint8_t __align,
 			     void **__databufp) __THROW;
-extern int inet6_opt_finish (void *__extbuf, socklen_t __extlen, int __offset)
+extern int inet6_opt_finish (void *__extbuf, __socklen_t __extlen, int __offset)
      __THROW;
 extern int inet6_opt_set_val (void *__databuf, int __offset, void *__val,
-			      socklen_t __vallen) __THROW;
-extern int inet6_opt_next (void *__extbuf, socklen_t __extlen, int __offset,
-			   uint8_t *__typep, socklen_t *__lenp,
+			      __socklen_t __vallen) __THROW;
+extern int inet6_opt_next (void *__extbuf, __socklen_t __extlen, int __offset,
+			   uint8_t *__typep, __socklen_t *__lenp,
 			   void **__databufp) __THROW;
-extern int inet6_opt_find (void *__extbuf, socklen_t __extlen, int __offset,
-			   uint8_t __type, socklen_t *__lenp,
+extern int inet6_opt_find (void *__extbuf, __socklen_t __extlen, int __offset,
+			   uint8_t __type, __socklen_t *__lenp,
 			   void **__databufp) __THROW;
 extern int inet6_opt_get_val (void *__databuf, int __offset, void *__val,
-			      socklen_t __vallen) __THROW;
+			      __socklen_t __vallen) __THROW;
 
 
 /* Routing Header Option (RFC 3542).  */
-extern socklen_t inet6_rth_space (int __type, int __segments) __THROW;
-extern void *inet6_rth_init (void *__bp, socklen_t __bp_len, int __type,
+extern __socklen_t inet6_rth_space (int __type, int __segments) __THROW;
+extern void *inet6_rth_init (void *__bp, __socklen_t __bp_len, int __type,
 			     int __segments) __THROW;
 extern int inet6_rth_add (void *__bp, const struct in6_addr *__addr) __THROW;
 extern int inet6_rth_reverse (const void *__in, void *__out) __THROW;
@@ -616,14 +617,14 @@ extern int setipv4sourcefilter (int __s, struct in_addr __interface_addr,
 /* Get source filter.  */
 extern int getsourcefilter (int __s, uint32_t __interface_addr,
 			    const struct sockaddr *__group,
-			    socklen_t __grouplen, uint32_t *__fmode,
+			    __socklen_t __grouplen, uint32_t *__fmode,
 			    uint32_t *__numsrc,
 			    struct sockaddr_storage *__slist) __THROW;
 
 /* Set source filter.  */
 extern int setsourcefilter (int __s, uint32_t __interface_addr,
 			    const struct sockaddr *__group,
-			    socklen_t __grouplen, uint32_t __fmode,
+			    __socklen_t __grouplen, uint32_t __fmode,
 			    uint32_t __numsrc,
 			    const struct sockaddr_storage *__slist) __THROW;
 #endif	/* use GNU */
diff --git a/inet/netinet/tcp.h b/inet/netinet/tcp.h
index 243b55a24c..f6aa166c5a 100644
--- a/inet/netinet/tcp.h
+++ b/inet/netinet/tcp.h
@@ -86,11 +86,11 @@
 #define TCP_REPAIR_OFF_NO_WP	 -1
 
 #ifdef __USE_MISC
-# include <bits/stdint-uintn.h>
 # include <bits/endian.h>
-# include <sys/socket.h>
+# include <bits/types.h>
+# include <bits/types/struct_sockaddr_storage.h>
 
-typedef	uint32_t tcp_seq;
+typedef	__uint32_t tcp_seq;
 /*
  * TCP header.
  * Per RFC 793, September, 1981.
@@ -101,61 +101,61 @@ struct tcphdr
     {
       struct
       {
-	uint16_t th_sport;	/* source port */
-	uint16_t th_dport;	/* destination port */
+	__uint16_t th_sport;	/* source port */
+	__uint16_t th_dport;	/* destination port */
 	tcp_seq th_seq;		/* sequence number */
 	tcp_seq th_ack;		/* acknowledgement number */
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-	uint8_t th_x2:4;	/* (unused) */
-	uint8_t th_off:4;	/* data offset */
+	__uint8_t th_x2:4;	/* (unused) */
+	__uint8_t th_off:4;	/* data offset */
 # endif
 # if __BYTE_ORDER == __BIG_ENDIAN
-	uint8_t th_off:4;	/* data offset */
-	uint8_t th_x2:4;	/* (unused) */
+	__uint8_t th_off:4;	/* data offset */
+	__uint8_t th_x2:4;	/* (unused) */
 # endif
-	uint8_t th_flags;
+	__uint8_t th_flags;
 # define TH_FIN	0x01
 # define TH_SYN	0x02
 # define TH_RST	0x04
 # define TH_PUSH	0x08
 # define TH_ACK	0x10
 # define TH_URG	0x20
-	uint16_t th_win;	/* window */
-	uint16_t th_sum;	/* checksum */
-	uint16_t th_urp;	/* urgent pointer */
+	__uint16_t th_win;	/* window */
+	__uint16_t th_sum;	/* checksum */
+	__uint16_t th_urp;	/* urgent pointer */
       };
       struct
       {
-	uint16_t source;
-	uint16_t dest;
-	uint32_t seq;
-	uint32_t ack_seq;
+	__uint16_t source;
+	__uint16_t dest;
+	__uint32_t seq;
+	__uint32_t ack_seq;
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-	uint16_t res1:4;
-	uint16_t doff:4;
-	uint16_t fin:1;
-	uint16_t syn:1;
-	uint16_t rst:1;
-	uint16_t psh:1;
-	uint16_t ack:1;
-	uint16_t urg:1;
-	uint16_t res2:2;
+	__uint16_t res1:4;
+	__uint16_t doff:4;
+	__uint16_t fin:1;
+	__uint16_t syn:1;
+	__uint16_t rst:1;
+	__uint16_t psh:1;
+	__uint16_t ack:1;
+	__uint16_t urg:1;
+	__uint16_t res2:2;
 # elif __BYTE_ORDER == __BIG_ENDIAN
-	uint16_t doff:4;
-	uint16_t res1:4;
-	uint16_t res2:2;
-	uint16_t urg:1;
-	uint16_t ack:1;
-	uint16_t psh:1;
-	uint16_t rst:1;
-	uint16_t syn:1;
-	uint16_t fin:1;
+	__uint16_t doff:4;
+	__uint16_t res1:4;
+	__uint16_t res2:2;
+	__uint16_t urg:1;
+	__uint16_t ack:1;
+	__uint16_t psh:1;
+	__uint16_t rst:1;
+	__uint16_t syn:1;
+	__uint16_t fin:1;
 # else
 #  error "Adjust your <bits/endian.h> defines"
 # endif
-	uint16_t window;
-	uint16_t check;
-	uint16_t urg_ptr;
+	__uint16_t window;
+	__uint16_t check;
+	__uint16_t urg_ptr;
       };
     };
 };
@@ -225,45 +225,45 @@ enum tcp_ca_state
 
 struct tcp_info
 {
-  uint8_t	tcpi_state;
-  uint8_t	tcpi_ca_state;
-  uint8_t	tcpi_retransmits;
-  uint8_t	tcpi_probes;
-  uint8_t	tcpi_backoff;
-  uint8_t	tcpi_options;
-  uint8_t	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
-
-  uint32_t	tcpi_rto;
-  uint32_t	tcpi_ato;
-  uint32_t	tcpi_snd_mss;
-  uint32_t	tcpi_rcv_mss;
-
-  uint32_t	tcpi_unacked;
-  uint32_t	tcpi_sacked;
-  uint32_t	tcpi_lost;
-  uint32_t	tcpi_retrans;
-  uint32_t	tcpi_fackets;
+  __uint8_t	tcpi_state;
+  __uint8_t	tcpi_ca_state;
+  __uint8_t	tcpi_retransmits;
+  __uint8_t	tcpi_probes;
+  __uint8_t	tcpi_backoff;
+  __uint8_t	tcpi_options;
+  __uint8_t	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
+
+  __uint32_t	tcpi_rto;
+  __uint32_t	tcpi_ato;
+  __uint32_t	tcpi_snd_mss;
+  __uint32_t	tcpi_rcv_mss;
+
+  __uint32_t	tcpi_unacked;
+  __uint32_t	tcpi_sacked;
+  __uint32_t	tcpi_lost;
+  __uint32_t	tcpi_retrans;
+  __uint32_t	tcpi_fackets;
 
   /* Times. */
-  uint32_t	tcpi_last_data_sent;
-  uint32_t	tcpi_last_ack_sent;	/* Not remembered, sorry.  */
-  uint32_t	tcpi_last_data_recv;
-  uint32_t	tcpi_last_ack_recv;
+  __uint32_t	tcpi_last_data_sent;
+  __uint32_t	tcpi_last_ack_sent;	/* Not remembered, sorry.  */
+  __uint32_t	tcpi_last_data_recv;
+  __uint32_t	tcpi_last_ack_recv;
 
   /* Metrics. */
-  uint32_t	tcpi_pmtu;
-  uint32_t	tcpi_rcv_ssthresh;
-  uint32_t	tcpi_rtt;
-  uint32_t	tcpi_rttvar;
-  uint32_t	tcpi_snd_ssthresh;
-  uint32_t	tcpi_snd_cwnd;
-  uint32_t	tcpi_advmss;
-  uint32_t	tcpi_reordering;
-
-  uint32_t	tcpi_rcv_rtt;
-  uint32_t	tcpi_rcv_space;
-
-  uint32_t	tcpi_total_retrans;
+  __uint32_t	tcpi_pmtu;
+  __uint32_t	tcpi_rcv_ssthresh;
+  __uint32_t	tcpi_rtt;
+  __uint32_t	tcpi_rttvar;
+  __uint32_t	tcpi_snd_ssthresh;
+  __uint32_t	tcpi_snd_cwnd;
+  __uint32_t	tcpi_advmss;
+  __uint32_t	tcpi_reordering;
+
+  __uint32_t	tcpi_rcv_rtt;
+  __uint32_t	tcpi_rcv_space;
+
+  __uint32_t	tcpi_total_retrans;
 };
 
 
@@ -276,18 +276,18 @@ struct tcp_info
 struct tcp_md5sig
 {
   struct sockaddr_storage tcpm_addr;		/* Address associated.  */
-  uint8_t	tcpm_flags;			/* Extension flags.  */
-  uint8_t	tcpm_prefixlen;			/* Address prefix.  */
-  uint16_t	tcpm_keylen;			/* Key length.  */
-  uint32_t	__tcpm_pad;			/* Zero.  */
-  uint8_t	tcpm_key[TCP_MD5SIG_MAXKEYLEN];	/* Key (binary).  */
+  __uint8_t	tcpm_flags;			/* Extension flags.  */
+  __uint8_t	tcpm_prefixlen;			/* Address prefix.  */
+  __uint16_t	tcpm_keylen;			/* Key length.  */
+  __uint32_t	__tcpm_pad;			/* Zero.  */
+  __uint8_t	tcpm_key[TCP_MD5SIG_MAXKEYLEN];	/* Key (binary).  */
 };
 
 /* For socket repair options.  */
 struct tcp_repair_opt
 {
-  uint32_t	opt_code;
-  uint32_t	opt_val;
+  __uint32_t	opt_code;
+  __uint32_t	opt_val;
 };
 
 /* Queue to repair, for TCP_REPAIR_QUEUE.  */
@@ -318,30 +318,30 @@ enum
 
 struct tcp_cookie_transactions
 {
-  uint16_t	tcpct_flags;
-  uint8_t	__tcpct_pad1;
-  uint8_t	tcpct_cookie_desired;
-  uint16_t	tcpct_s_data_desired;
-  uint16_t	tcpct_used;
-  uint8_t	tcpct_value[TCP_MSS_DEFAULT];
+  __uint16_t	tcpct_flags;
+  __uint8_t	__tcpct_pad1;
+  __uint8_t	tcpct_cookie_desired;
+  __uint16_t	tcpct_s_data_desired;
+  __uint16_t	tcpct_used;
+  __uint8_t	tcpct_value[TCP_MSS_DEFAULT];
 };
 
 /* For use with TCP_REPAIR_WINDOW.  */
 struct tcp_repair_window
 {
-  uint32_t snd_wl1;
-  uint32_t snd_wnd;
-  uint32_t max_window;
-  uint32_t rcv_wnd;
-  uint32_t rcv_wup;
+  __uint32_t snd_wl1;
+  __uint32_t snd_wnd;
+  __uint32_t max_window;
+  __uint32_t rcv_wnd;
+  __uint32_t rcv_wup;
 };
 
 /* For use with TCP_ZEROCOPY_RECEIVE.  */
 struct tcp_zerocopy_receive
 {
-  uint64_t address; /* In: address of mapping.  */
-  uint32_t length; /* In/out: number of bytes to map/mapped.  */
-  uint32_t recv_skip_hint; /* Out: amount of bytes to skip.  */
+  __uint64_t address; /* In: address of mapping.  */
+  __uint32_t length; /* In/out: number of bytes to map/mapped.  */
+  __uint32_t recv_skip_hint; /* Out: amount of bytes to skip.  */
 };
 
 #endif /* Misc.  */
diff --git a/inet/protocols/routed.h b/inet/protocols/routed.h
index adb1767dca..694c436445 100644
--- a/inet/protocols/routed.h
+++ b/inet/protocols/routed.h
@@ -32,7 +32,9 @@
 #ifndef _PROTOCOLS_ROUTED_H
 #define	_PROTOCOLS_ROUTED_H 1
 
-#include <sys/socket.h>
+#include <features.h>
+#include <bits/types/struct_sockaddr.h>
+
 /*
  * Routing Information Protocol
  *
diff --git a/inet/setsourcefilter.c b/inet/setsourcefilter.c
index f0975de724..9ffd42a9e7 100644
--- a/inet/setsourcefilter.c
+++ b/inet/setsourcefilter.c
@@ -20,7 +20,7 @@
 #include <errno.h>
 #include <stdint.h>
 #include <netinet/in.h>
-
+#include <sys/socket.h>
 
 int
 setsourcefilter (int s, uint32_t interface, const struct sockaddr *group,
diff --git a/inet/test-ifaddrs.c b/inet/test-ifaddrs.c
index b7027c2b10..751efc55b0 100644
--- a/inet/test-ifaddrs.c
+++ b/inet/test-ifaddrs.c
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ifaddrs.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
diff --git a/inet/test-inet6_opt.c b/inet/test-inet6_opt.c
index a7ebf006c6..e10680c498 100644
--- a/inet/test-inet6_opt.c
+++ b/inet/test-inet6_opt.c
@@ -1,3 +1,4 @@
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/inet/tst-inet6_rth.c b/inet/tst-inet6_rth.c
index 549d717c7d..abb85cdf26 100644
--- a/inet/tst-inet6_rth.c
+++ b/inet/tst-inet6_rth.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/ip6.h>
 
diff --git a/inet/tst-inet6_scopeid_pton.c b/inet/tst-inet6_scopeid_pton.c
index 37ec20b1e2..4c25d23cdd 100644
--- a/inet/tst-inet6_scopeid_pton.c
+++ b/inet/tst-inet6_scopeid_pton.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
 #include <net-internal.h>
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
index 2d08076382..6355663d49 100644
--- a/nis/nss_nis/nis-hosts.c
+++ b/nis/nss_nis/nis-hosts.c
@@ -25,6 +25,7 @@
 #include <netdb.h>
 #undef _nss_nis_endhostent
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <libc-lock.h>
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index 1e66e4ff92..b65c27f014 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -23,6 +23,7 @@
 #include <netdb.h>
 #include <nss.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <rpcsvc/nis.h>
diff --git a/nscd/aicache.c b/nscd/aicache.c
index 46db40fceb..8f7e72e65b 100644
--- a/nscd/aicache.c
+++ b/nscd/aicache.c
@@ -25,6 +25,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 #include <resolv/resolv-internal.h>
 #include <resolv/resolv_context.h>
 #include <scratch_buffer.h>
diff --git a/nscd/cache.c b/nscd/cache.c
index 0c4dfc0dcf..41403c990d 100644
--- a/nscd/cache.c
+++ b/nscd/cache.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <libintl.h>
 #include <arpa/inet.h>
+#include <sys/socket.h>
 #include <sys/mman.h>
 #include <sys/param.h>
 #include <sys/stat.h>
diff --git a/nscd/hstcache.c b/nscd/hstcache.c
index 9ade6c1582..d9020f76ab 100644
--- a/nscd/hstcache.c
+++ b/nscd/hstcache.c
@@ -33,6 +33,7 @@
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 #include <stackinfo.h>
 #include <scratch_buffer.h>
 
diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
index c37b920fae..ee5e1e2133 100644
--- a/nscd/initgrcache.c
+++ b/nscd/initgrcache.c
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/param.h>
+#include <sys/socket.h>
 #include <scratch_buffer.h>
 #include <config.h>
 
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index dacd52315a..63e903703a 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/param.h>
+#include <sys/socket.h>
 
 #include "../inet/netgroup.h"
 #include "nscd.h"
diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c
index f08d1d149a..33e5c7e619 100644
--- a/nscd/nscd_gethst_r.c
+++ b/nscd/nscd_gethst_r.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <sys/socket.h>
 #include <arpa/nameser.h>
 #include <not-cancel.h>
 
diff --git a/nscd/servicescache.c b/nscd/servicescache.c
index cb434ae1ec..1dbe57ba6c 100644
--- a/nscd/servicescache.c
+++ b/nscd/servicescache.c
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <stdint.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 #include <kernel-features.h>
 #include <scratch_buffer.h>
 
diff --git a/nss/digits_dots.c b/nss/digits_dots.c
index 91b587b516..3dff017b79 100644
--- a/nss/digits_dots.c
+++ b/nss/digits_dots.c
@@ -25,6 +25,7 @@
 #include <resolv/resolv-internal.h>
 #include <resolv/resolv_context.h>
 #include <netdb.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include "nsswitch.h"
 
diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index 92c5d9728d..cbd7f709da 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <assert.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
index 6530d51c3b..819d4aefbf 100644
--- a/nss/nss_files/files-network.c
+++ b/nss/nss_files/files-network.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
diff --git a/nss/tst-nss-files-hosts-erange.c b/nss/tst-nss-files-hosts-erange.c
index 9491fdf24d..d5db1df737 100644
--- a/nss/tst-nss-files-hosts-erange.c
+++ b/nss/tst-nss-files-hosts-erange.c
@@ -22,6 +22,7 @@
 #include <gnu/lib-names.h>
 #include <netdb.h>
 #include <nss.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/nss/tst-nss-files-hosts-getent.c b/nss/tst-nss-files-hosts-getent.c
index 02723d9cc0..4860d31ee7 100644
--- a/nss/tst-nss-files-hosts-getent.c
+++ b/nss/tst-nss-files-hosts-getent.c
@@ -24,6 +24,7 @@
 #include <nss.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/nss/tst-nss-files-hosts-multi.c b/nss/tst-nss-files-hosts-multi.c
index 1863fff7ce..10f6228349 100644
--- a/nss/tst-nss-files-hosts-multi.c
+++ b/nss/tst-nss-files-hosts-multi.c
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/namespace.h>
diff --git a/posix/tst-getaddrinfo3.c b/posix/tst-getaddrinfo3.c
index 5077f311fc..1d1919971a 100644
--- a/posix/tst-getaddrinfo3.c
+++ b/posix/tst-getaddrinfo3.c
@@ -2,6 +2,7 @@
 #include <netdb.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 
diff --git a/resolv/netdb.h b/resolv/netdb.h
index 575e416dac..91277fcb86 100644
--- a/resolv/netdb.h
+++ b/resolv/netdb.h
@@ -25,6 +25,7 @@
 #include <features.h>
 
 #include <netinet/in.h>
+#include <bits/types/socklen_t.h>
 #include <bits/stdint-uintn.h>
 #ifdef __USE_MISC
 /* This is necessary to make this include file properly replace the
diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 906a3a6b06..06f187f5ff 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -65,6 +65,7 @@
 #include <stddef.h>
 
 #include "nsswitch.h"
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <resolv/resolv-internal.h>
diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c
index 08c50ef19e..316d27fc96 100644
--- a/resolv/resolv_conf.c
+++ b/resolv/resolv_conf.c
@@ -23,6 +23,7 @@
 #include <libc-lock.h>
 #include <resolv-internal.h>
 #include <sys/stat.h>
+#include <sys/socket.h>
 #include <libc-symbols.h>
 
 /* _res._u._ext.__glibc_extension_index is used as an index into a
diff --git a/resolv/tst-bug18665-tcp.c b/resolv/tst-bug18665-tcp.c
index 37170675c2..539b5eb0d4 100644
--- a/resolv/tst-bug18665-tcp.c
+++ b/resolv/tst-bug18665-tcp.c
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-bug18665.c b/resolv/tst-bug18665.c
index 37e2828465..c1e29cfec8 100644
--- a/resolv/tst-bug18665.c
+++ b/resolv/tst-bug18665.c
@@ -21,6 +21,7 @@
 #include <resolv.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/resolv_test.h>
 #include <support/xthread.h>
diff --git a/resolv/tst-inet_ntop.c b/resolv/tst-inet_ntop.c
index f0de06306c..728fd25d7f 100644
--- a/resolv/tst-inet_ntop.c
+++ b/resolv/tst-inet_ntop.c
@@ -3,6 +3,7 @@
 #include <netinet/in.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 
 static int
 do_test (void)
diff --git a/resolv/tst-inet_pton.c b/resolv/tst-inet_pton.c
index 71c679458a..7092143b07 100644
--- a/resolv/tst-inet_pton.c
+++ b/resolv/tst-inet_pton.c
@@ -21,6 +21,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/next_to_fault.h>
 #include <support/xunistd.h>
diff --git a/resolv/tst-resolv-ai_idn-common.c b/resolv/tst-resolv-ai_idn-common.c
index 9e8ed7611c..ff6ff13bac 100644
--- a/resolv/tst-resolv-ai_idn-common.c
+++ b/resolv/tst-resolv-ai_idn-common.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-basic.c b/resolv/tst-resolv-basic.c
index 2ad9ee382a..deb1e3c584 100644
--- a/resolv/tst-resolv-basic.c
+++ b/resolv/tst-resolv-basic.c
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/format_nss.h>
diff --git a/resolv/tst-resolv-binary.c b/resolv/tst-resolv-binary.c
index 90a94a50fe..c7ad3bd57d 100644
--- a/resolv/tst-resolv-binary.c
+++ b/resolv/tst-resolv-binary.c
@@ -18,6 +18,7 @@
 
 #include <resolv.h>
 #include <string.h>
+#include <sys/types.h>
 #include <support/check.h>
 #include <support/resolv_test.h>
 
diff --git a/resolv/tst-resolv-edns.c b/resolv/tst-resolv-edns.c
index 4fbb3a056c..597520398c 100644
--- a/resolv/tst-resolv-edns.c
+++ b/resolv/tst-resolv-edns.c
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/resolv_test.h>
 #include <support/support.h>
diff --git a/resolv/tst-resolv-network.c b/resolv/tst-resolv-network.c
index a91699c711..2bb5266829 100644
--- a/resolv/tst-resolv-network.c
+++ b/resolv/tst-resolv-network.c
@@ -19,6 +19,7 @@
 #include <netdb.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-nondecimal.c b/resolv/tst-resolv-nondecimal.c
index 5d161a452e..8b1b162d1b 100644
--- a/resolv/tst-resolv-nondecimal.c
+++ b/resolv/tst-resolv-nondecimal.c
@@ -18,6 +18,7 @@
 
 #include <netdb.h>
 #include <stdlib.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-search.c b/resolv/tst-resolv-search.c
index 6379147a27..545a0a2545 100644
--- a/resolv/tst-resolv-search.c
+++ b/resolv/tst-resolv-search.c
@@ -19,6 +19,7 @@
 #include <resolv.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-threads.c b/resolv/tst-resolv-threads.c
index a3a874ef4b..0b4c198cc7 100644
--- a/resolv/tst-resolv-threads.c
+++ b/resolv/tst-resolv-threads.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/namespace.h>
 #include <support/resolv_test.h>
diff --git a/resolv/tst-resolv-trailing.c b/resolv/tst-resolv-trailing.c
index f27e110afb..b2ec1dffa0 100644
--- a/resolv/tst-resolv-trailing.c
+++ b/resolv/tst-resolv-trailing.c
@@ -18,6 +18,7 @@
 
 #include <array_length.h>
 #include <netdb.h>
+#include <sys/socket.h>
 #include <support/check.h>
 #include <support/check_nss.h>
 #include <support/resolv_test.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 5e528bcc1a..6004cede75 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -542,9 +542,6 @@ HEADER_ALLOWED_INCLUDES = {
     #          arpa/inet.h -> netinet/in.h
     "netdb.h":                     [ "netinet/in.h", "rpc/netdb.h" ],
     "arpa/inet.h":                 [ "netinet/in.h" ],
-    "net/if.h":                    [ "sys/socket.h" ],
-    "netinet/in.h":                [ "sys/socket.h" ],
-    "netinet/tcp.h":               [ "sys/socket.h" ],
 
     # Nonstandardized top-level headers
     "argp.h":                      [ "ctype.h", "errno.h", "getopt.h",
@@ -580,7 +577,6 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/procfs.h":                [ "sys/ucontext.h", "sys/user.h" ],
     "sys/ptrace.h":                [ "sys/ucontext.h" ],
     "sys/raw.h":                   [ "sys/ioctl.h" ],
-    "sys/socketvar.h":             [ "sys/socket.h" ],
     "sys/timerfd.h":               [ "time.h" ],
     "sys/ttychars.h":              [ "sys/ttydefaults.h" ],
     "sys/ucontext.h":              [ "sys/procfs.h" ],
@@ -598,6 +594,7 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/fcntl.h":                 [ "fcntl.h" ],
     "sys/poll.h":                  [ "poll.h" ],
     "sys/signal.h":                [ "signal.h" ],
+    "sys/socketvar.h":             [ "sys/socket.h" ],
     "sys/syslog.h":                [ "syslog.h" ],
     "sys/termios.h":               [ "termios.h" ],
     "sys/unistd.h":                [ "unistd.h" ],
@@ -606,18 +603,16 @@ HEADER_ALLOWED_INCLUDES = {
     "wait.h":                      [ "sys/wait.h" ],
 
     # Nonstandardized networking headers
-    "ifaddrs.h":                   [ "sys/socket.h" ],
 
     "resolv.h":                    [ "arpa/nameser.h", "netinet/in.h" ],
     "arpa/nameser.h":              [ "arpa/nameser_compat.h" ],
 
     "net/ethernet.h":              [ "net/if_ether.h" ],
-    "net/if_arp.h":                [ "sys/socket.h" ],
     "net/if_ppp.h":                [ "net/if.h", "net/ppp_defs.h",
                                      "sys/ioctl.h" ],
     "net/if_shaper.h":             [ "net/if.h", "sys/ioctl.h" ],
-    "net/route.h":                 [ "netinet/in.h", "sys/socket.h" ],
-    "netatalk/at.h":               [ "sys/socket.h", "sys/ioctl.h" ],
+    "net/route.h":                 [ "netinet/in.h" ],
+    "netatalk/at.h":               [ "sys/ioctl.h" ],
 
     "netinet/ether.h":             [ "netinet/if_ether.h" ],
     "netinet/icmp6.h":             [ "netinet/in.h" ],
@@ -629,7 +624,6 @@ HEADER_ALLOWED_INCLUDES = {
 
     "netrom/netrom.h":             [ "netax25/ax25.h" ],
     "netrose/rose.h":              [ "netax25/ax25.h" ],
-    "protocols/routed.h":          [ "sys/socket.h" ],
     "protocols/rwhod.h":           [ "paths.h" ],
 
     # Internal headers
diff --git a/socket/Makefile b/socket/Makefile
index 125c042cab..c63754812c 100644
--- a/socket/Makefile
+++ b/socket/Makefile
@@ -22,9 +22,11 @@ subdir	:= socket
 
 include ../Makeconfig
 
-headers	:= sys/socket.h sys/un.h bits/sockaddr.h bits/socket.h \
-	   bits/socket2.h bits/types/struct_osockaddr.h \
-	   sys/socketvar.h net/if.h
+headers := net/if.h sys/socket.h sys/socketvar.h sys/un.h		\
+	   bits/sockaddr.h bits/socket.h bits/socket2.h			\
+	   bits/types/struct_linger.h bits/types/struct_osockaddr.h	\
+	   bits/types/struct_sockaddr.h					\
+	   bits/types/struct_sockaddr_storage.h
 
 routines := accept bind connect getpeername getsockname getsockopt	\
 	    listen recv recvfrom recvmsg send sendmsg sendto		\
diff --git a/socket/bits/types/struct_linger.h b/socket/bits/types/struct_linger.h
new file mode 100644
index 0000000000..58708e0204
--- /dev/null
+++ b/socket/bits/types/struct_linger.h
@@ -0,0 +1,11 @@
+#ifndef _BITS_TYPES_STRUCT_LINGER_H
+#define _BITS_TYPES_STRUCT_LINGER_H 1
+
+/* Structure used to manipulate the SO_LINGER option.  */
+struct linger
+  {
+    int l_onoff;		/* Nonzero to linger on close.  */
+    int l_linger;		/* Time to linger.  */
+  };
+
+#endif
diff --git a/socket/bits/types/struct_sockaddr.h b/socket/bits/types/struct_sockaddr.h
new file mode 100644
index 0000000000..86100142ca
--- /dev/null
+++ b/socket/bits/types/struct_sockaddr.h
@@ -0,0 +1,15 @@
+#ifndef __struct_sockaddr_defined
+#define __struct_sockaddr_defined 1
+
+#include <bits/sockaddr.h>
+
+/* Structure describing a generic socket address.  For historical
+   reasons this type is smaller than many address families' concrete
+   socket addresses.  You may want struct sockaddr_storage instead.  */
+struct sockaddr
+  {
+    __SOCKADDR_COMMON (sa_);	/* Common data: family and perhaps length.  */
+    char sa_data[14];		/* Address data.  */
+  };
+
+#endif
diff --git a/socket/bits/types/struct_sockaddr_storage.h b/socket/bits/types/struct_sockaddr_storage.h
new file mode 100644
index 0000000000..47e0513939
--- /dev/null
+++ b/socket/bits/types/struct_sockaddr_storage.h
@@ -0,0 +1,21 @@
+#ifndef __struct_sockaddr_storage_defined
+#define __struct_sockaddr_storage_defined 1
+
+#include <bits/sockaddr.h>
+
+/* Structure large enough to hold any socket address (with the historical
+   exception of AF_UNIX).  */
+#ifndef __ss_aligntype
+# define __ss_aligntype	unsigned long int
+#endif
+#define _SS_PADSIZE \
+  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
+
+struct sockaddr_storage
+  {
+    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
+    char __ss_padding[_SS_PADSIZE];
+    __ss_aligntype __ss_align;	/* Force desired alignment.  */
+  };
+
+#endif /* bits/types/struct_sockaddr_storage.h */
diff --git a/socket/net/if.h b/socket/net/if.h
index 8431e000a2..852fb8b04b 100644
--- a/socket/net/if.h
+++ b/socket/net/if.h
@@ -32,7 +32,7 @@ struct if_nameindex
 
 
 #ifdef __USE_MISC
-# include <sys/socket.h>  /* for struct sockaddr */
+# include <bits/types/struct_sockaddr.h>
 
 /* Standard interface flags. */
 enum
diff --git a/socket/sys/socket.h b/socket/sys/socket.h
index 6a68164e39..0725fcb6d9 100644
--- a/socket/sys/socket.h
+++ b/socket/sys/socket.h
@@ -28,11 +28,11 @@ __BEGIN_DECLS
 #include <bits/types/ssize_t.h>
 #include <bits/types/socklen_t.h>
 #include <bits/types/struct_iovec.h>
+#include <bits/types/struct_linger.h>
 
-/* This operating system-specific header file defines the SOCK_*, PF_*,
-   AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
-   `struct msghdr', and `struct linger' types.  */
-#include <bits/socket.h>
+#include <bits/sockaddr.h>
+#include <bits/types/struct_sockaddr.h>
+#include <bits/types/struct_sockaddr_storage.h>
 
 #ifdef __USE_MISC
 # include <bits/types/struct_osockaddr.h>
@@ -42,6 +42,11 @@ __BEGIN_DECLS
 struct timespec;
 #endif
 
+/* This operating system-specific header file defines the SOCK_*, PF_*,
+   AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct msghdr' and
+   `struct cmsghdr' types.  */
+#include <bits/socket.h>
+
 /* The following constants should be used for the second parameter of
    `shutdown'.  */
 enum
diff --git a/sysdeps/generic/sys/socketvar.h b/socket/sys/socketvar.h
index b177158d0b..b177158d0b 100644
--- a/sysdeps/generic/sys/socketvar.h
+++ b/socket/sys/socketvar.h
diff --git a/sunrpc/rpc_gethostbyname.c b/sunrpc/rpc_gethostbyname.c
index e838d25341..24bbaa5d0c 100644
--- a/sunrpc/rpc_gethostbyname.c
+++ b/sunrpc/rpc_gethostbyname.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <netdb.h>
+#include <sys/socket.h>
 #include <rpc/rpc.h>
 #include <scratch_buffer.h>
 #include <string.h>
diff --git a/support/support_format_address_family.c b/support/support_format_address_family.c
index 29c7834ebe..9ab206669a 100644
--- a/support/support_format_address_family.c
+++ b/support/support_format_address_family.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <support/support.h>
 
 char *
diff --git a/support/support_format_addrinfo.c b/support/support_format_addrinfo.c
index fa7d6acefc..c74aa53e7e 100644
--- a/support/support_format_addrinfo.c
+++ b/support/support_format_addrinfo.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/socket.h>
 #include <support/support.h>
 #include <support/xmemstream.h>
 
diff --git a/support/support_format_dns_packet.c b/support/support_format_dns_packet.c
index 918e70808e..8f59906883 100644
--- a/support/support_format_dns_packet.c
+++ b/support/support_format_dns_packet.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <resolv.h>
 #include <stdbool.h>
diff --git a/support/support_format_hostent.c b/support/support_format_hostent.c
index 108cd35de6..5c90692caf 100644
--- a/support/support_format_hostent.c
+++ b/support/support_format_hostent.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <errno.h>
 #include <stdio.h>
diff --git a/support/support_format_netent.c b/support/support_format_netent.c
index 9eea21a4ac..388f8c0006 100644
--- a/support/support_format_netent.c
+++ b/support/support_format_netent.c
@@ -18,6 +18,7 @@
 
 #include <support/format_nss.h>
 
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
index 828a8efbf2..56421de952 100644
--- a/sysdeps/mach/hurd/bits/socket.h
+++ b/sysdeps/mach/hurd/bits/socket.h
@@ -25,11 +25,6 @@
 #endif
 
 
-#include <bits/types.h>
-#include <bits/types/size_t.h>
-#include <bits/types/socklen_t.h>
-#include <bits/wordsize.h>
-
 /* Types of sockets.  */
 enum __socket_type
 {
@@ -142,34 +137,6 @@ enum __socket_type
 /* Maximum queue length specifiable by listen.  */
 #define SOMAXCONN	128	/* 5 on the origional 4.4 BSD.  */
 
-/* Get the definition of the macro to define the common sockaddr members.  */
-#include <bits/sockaddr.h>
-
-/* Structure describing a generic socket address.  */
-struct sockaddr
-  {
-    __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).  */
-#if __WORDSIZE == 64
-# define __ss_aligntype	__uint64_t
-#else
-# define __ss_aligntype	__uint32_t
-#endif
-#define _SS_PADSIZE \
-  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
-
-struct sockaddr_storage
-  {
-    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
-    char __ss_padding[_SS_PADSIZE];
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
-  };
-
 
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
@@ -352,11 +319,4 @@ enum
 #define SO_TYPE SO_TYPE
   };
 
-/* Structure used to manipulate the SO_LINGER option.  */
-struct linger
-  {
-    int l_onoff;		/* Nonzero to linger on close.  */
-    int l_linger;		/* Time to linger.  */
-  };
-
 #endif	/* bits/socket.h */
diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c
index 32dceccdbf..30b41ef396 100644
--- a/sysdeps/mach/hurd/if_index.c
+++ b/sysdeps/mach/hurd/if_index.c
@@ -19,6 +19,7 @@
 #include <error.h>
 #include <net/if.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 86dd2ffc37..a7e81a9b06 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -23,7 +23,8 @@
 #define _NET_IF_ARP_H 1
 
 #include <features.h>
-#include <sys/socket.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/mach/hurd/net/route.h b/sysdeps/mach/hurd/net/route.h
index 8772461da5..3e71e8915a 100644
--- a/sysdeps/mach/hurd/net/route.h
+++ b/sysdeps/mach/hurd/net/route.h
@@ -22,7 +22,7 @@
 
 #include <features.h>
 
-#include <sys/socket.h>
+#include <bits/types/struct_sockaddr.h>
 #include <netinet/in.h>
 
 
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 */
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index e85fb589ce..b7af054e41 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -24,10 +24,6 @@
 #endif
 
 
-#include <bits/types.h>
-#include <bits/types/size_t.h>
-#include <bits/types/socklen_t.h>
-
 /* Get the architecture-dependent definition of enum __socket_type.  */
 #include <bits/socket_type.h>
 
@@ -165,30 +161,6 @@
 /* Maximum queue length specifiable by listen.  */
 #define SOMAXCONN	4096
 
-/* Get the definition of the macro to define the common sockaddr members.  */
-#include <bits/sockaddr.h>
-
-/* Structure describing a generic socket address.  */
-struct sockaddr
-  {
-    __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).  */
-#define __ss_aligntype	unsigned long int
-#define _SS_PADSIZE \
-  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
-
-struct sockaddr_storage
-  {
-    __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
-    char __ss_padding[_SS_PADSIZE];
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
-  };
-
 
 /* Bits in the FLAGS argument to `send', `recv', et al.  */
 enum
@@ -351,11 +323,4 @@ struct ucred
 # include <bits/socket-constants.h>
 #endif
 
-/* Structure used to manipulate the SO_LINGER option.  */
-struct linger
-  {
-    int l_onoff;		/* Nonzero to linger on close.  */
-    int l_linger;		/* Time to linger.  */
-  };
-
 #endif	/* bits/socket.h */
diff --git a/sysdeps/unix/sysv/linux/check_native.c b/sysdeps/unix/sysv/linux/check_native.c
index a2ee2ed42e..1ffaaa07a4 100644
--- a/sysdeps/unix/sysv/linux/check_native.c
+++ b/sysdeps/unix/sysv/linux/check_native.c
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <net/if.h>
 #include <net/if_arp.h>
+#include <sys/socket.h>
 #include <sys/ioctl.h>
 
 #include <asm/types.h>
diff --git a/sysdeps/unix/sysv/linux/errqueue.h b/sysdeps/unix/sysv/linux/errqueue.h
index e99db3037d..f8cfb073d5 100644
--- a/sysdeps/unix/sysv/linux/errqueue.h
+++ b/sysdeps/unix/sysv/linux/errqueue.h
@@ -20,18 +20,19 @@
 #ifndef _BITS_ERRQUEUE_H
 #define _BITS_ERRQUEUE_H  1
 
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 
 struct sock_extended_err
   {
-    uint32_t ee_errno;
-    uint8_t ee_origin;
-    uint8_t ee_type;
-    uint8_t ee_code;
-    uint8_t ee_pad;
-    uint32_t ee_info;
-    uint32_t ee_data;
+    __uint32_t ee_errno;
+    __uint8_t ee_origin;
+    __uint8_t ee_type;
+    __uint8_t ee_code;
+    __uint8_t ee_pad;
+    __uint32_t ee_info;
+    __uint32_t ee_data;
+    /* A socket address immediately follows.  */
   };
 
 #define SO_EE_ORIGIN_NONE  0
diff --git a/sysdeps/unix/sysv/linux/net/if_arp.h b/sysdeps/unix/sysv/linux/net/if_arp.h
index bbaf956180..83eac3107c 100644
--- a/sysdeps/unix/sysv/linux/net/if_arp.h
+++ b/sysdeps/unix/sysv/linux/net/if_arp.h
@@ -23,7 +23,8 @@
 #define _NET_IF_ARP_H 1
 
 #include <features.h>
-#include <sys/socket.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/unix/sysv/linux/net/route.h b/sysdeps/unix/sysv/linux/net/route.h
index 09819c9cae..340d994f25 100644
--- a/sysdeps/unix/sysv/linux/net/route.h
+++ b/sysdeps/unix/sysv/linux/net/route.h
@@ -22,10 +22,11 @@
 
 #include <features.h>
 
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include <bits/types.h>
+#include <bits/types/struct_sockaddr.h>
 #include <bits/wordsize.h>
 
+#include <netinet/in.h>
 
 /* This structure gets passed by the SIOCADDRT and SIOCDELRT calls. */
 struct rtentry
@@ -59,12 +60,12 @@ struct in6_rtmsg
     struct in6_addr rtmsg_dst;
     struct in6_addr rtmsg_src;
     struct in6_addr rtmsg_gateway;
-    uint32_t rtmsg_type;
-    uint16_t rtmsg_dst_len;
-    uint16_t rtmsg_src_len;
-    uint32_t rtmsg_metric;
+    __uint32_t rtmsg_type;
+    __uint16_t rtmsg_dst_len;
+    __uint16_t rtmsg_src_len;
+    __uint32_t rtmsg_metric;
     unsigned long int rtmsg_info;
-    uint32_t rtmsg_flags;
+    __uint32_t rtmsg_flags;
     int rtmsg_ifindex;
   };
 
@@ -113,7 +114,7 @@ struct in6_rtmsg
 #define RTF_NAT		0x08000000
 
 #define RTF_ADDRCLASSMASK	0xF8000000
-#define RT_ADDRCLASS(flags)	((uint32_t) flags >> 23)
+#define RT_ADDRCLASS(flags)	((__uint32_t) flags >> 23)
 
 #define RT_TOS(tos)		((tos) & IPTOS_TOS_MASK)
 
diff --git a/sysdeps/unix/sysv/linux/netatalk/at.h b/sysdeps/unix/sysv/linux/netatalk/at.h
index c4e33a8e42..bb5451ec23 100644
--- a/sysdeps/unix/sysv/linux/netatalk/at.h
+++ b/sysdeps/unix/sysv/linux/netatalk/at.h
@@ -22,8 +22,7 @@
 #include <bits/types.h>
 #include <bits/sockaddr.h>
 
-#include <sys/socket.h>
-#include <sys/ioctl.h>
+#include <sys/ioctl.h> /* for SIOCPROTOPRIVATE */
 
 /* Constants from linux/atalk.h as of kernel version 5.0.  */