[23/25] Don’t include sys/socket.h from public headers.

Message ID 20190626175029.4699-14-zackw@panix.com
State New
Headers show
Series
  • Public header file hygiene improvements for 2.30
Related show

Commit Message

Zack Weinberg June 26, 2019, 5:50 p.m.
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.
---
 bits/socket.h                                |  39 ----
 include/bits/types/struct_linger.h           |   1 +
 include/bits/types/struct_sockaddr.h         |   1 +
 include/bits/types/struct_sockaddr_storage.h |   1 +
 include/ifaddrs.h                            |   1 +
 include/netdb.h                              |   8 +-
 include/sys/socketvar.h                      |   1 +
 inet/arpa/inet.h                             |   1 +
 inet/check_pf.c                              |   1 +
 inet/gethstbynm.c                            |   1 +
 inet/gethstbynm_r.c                          |   1 +
 inet/getsourcefilter.c                       |   1 +
 inet/ifaddrs.h                               |   2 +-
 inet/inet6_opt.c                             |   1 +
 inet/inet6_option.c                          |   1 +
 inet/inet6_rth.c                             |   1 +
 inet/netinet/in.h                            |  35 ++--
 inet/netinet/tcp.h                           | 180 +++++++++----------
 inet/protocols/routed.h                      |   4 +-
 inet/setsourcefilter.c                       |   2 +-
 inet/test-ifaddrs.c                          |   1 +
 inet/test-inet6_opt.c                        |   1 +
 inet/tst-inet6_rth.c                         |   1 +
 inet/tst-inet6_scopeid_pton.c                |   1 +
 nis/nss_nis/nis-hosts.c                      |   1 +
 nis/nss_nisplus/nisplus-hosts.c              |   1 +
 nscd/aicache.c                               |   1 +
 nscd/cache.c                                 |   1 +
 nscd/hstcache.c                              |   1 +
 nscd/initgrcache.c                           |   1 +
 nscd/netgroupcache.c                         |   1 +
 nscd/nscd_gethst_r.c                         |   1 +
 nscd/servicescache.c                         |   1 +
 nss/digits_dots.c                            |   1 +
 nss/nss_files/files-hosts.c                  |   1 +
 nss/nss_files/files-network.c                |   1 +
 nss/tst-nss-files-hosts-erange.c             |   1 +
 nss/tst-nss-files-hosts-getent.c             |   1 +
 nss/tst-nss-files-hosts-multi.c              |   1 +
 posix/tst-getaddrinfo3.c                     |   1 +
 resolv/netdb.h                               |   1 +
 resolv/nss_dns/dns-network.c                 |   1 +
 resolv/resolv_conf.c                         |   1 +
 resolv/tst-bug18665-tcp.c                    |   1 +
 resolv/tst-bug18665.c                        |   1 +
 resolv/tst-inet_ntop.c                       |   1 +
 resolv/tst-inet_pton.c                       |   1 +
 resolv/tst-resolv-ai_idn-common.c            |   1 +
 resolv/tst-resolv-basic.c                    |   1 +
 resolv/tst-resolv-binary.c                   |   1 +
 resolv/tst-resolv-edns.c                     |   1 +
 resolv/tst-resolv-network.c                  |   1 +
 resolv/tst-resolv-nondecimal.c               |   1 +
 resolv/tst-resolv-search.c                   |   1 +
 resolv/tst-resolv-threads.c                  |   1 +
 resolv/tst-resolv-trailing.c                 |   1 +
 scripts/check-obsolete-constructs.py         |  12 +-
 socket/Makefile                              |   8 +-
 socket/bits/types/struct_linger.h            |  11 ++
 socket/bits/types/struct_sockaddr.h          |  15 ++
 socket/bits/types/struct_sockaddr_storage.h  |  21 +++
 socket/net/if.h                              |   2 +-
 socket/sys/socket.h                          |  13 +-
 {sysdeps/generic => socket}/sys/socketvar.h  |   0
 sunrpc/rpc_gethostbyname.c                   |   1 +
 support/support_format_address_family.c      |   1 +
 support/support_format_addrinfo.c            |   1 +
 support/support_format_dns_packet.c          |   1 +
 support/support_format_hostent.c             |   1 +
 support/support_format_netent.c              |   1 +
 sysdeps/mach/hurd/bits/socket.h              |  40 -----
 sysdeps/mach/hurd/if_index.c                 |   1 +
 sysdeps/mach/hurd/net/if_arp.h               |   3 +-
 sysdeps/mach/hurd/net/route.h                |   2 +-
 sysdeps/unix/bsd/bits/sockaddr.h             |   9 +
 sysdeps/unix/sysv/linux/bits/socket.h        |  35 ----
 sysdeps/unix/sysv/linux/check_native.c       |   1 +
 sysdeps/unix/sysv/linux/errqueue.h           |  19 +-
 sysdeps/unix/sysv/linux/net/if_arp.h         |   3 +-
 sysdeps/unix/sysv/linux/net/route.h          |  17 +-
 sysdeps/unix/sysv/linux/netatalk/at.h        |   3 +-
 81 files changed, 273 insertions(+), 267 deletions(-)
 create mode 100644 include/bits/types/struct_linger.h
 create mode 100644 include/bits/types/struct_sockaddr.h
 create mode 100644 include/bits/types/struct_sockaddr_storage.h
 create mode 100644 include/sys/socketvar.h
 create mode 100644 socket/bits/types/struct_linger.h
 create mode 100644 socket/bits/types/struct_sockaddr.h
 create mode 100644 socket/bits/types/struct_sockaddr_storage.h
 rename {sysdeps/generic => socket}/sys/socketvar.h (100%)

-- 
2.20.1

Patch

diff --git a/bits/socket.h b/bits/socket.h
index 8f5b85fa98..347b900e51 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 facee279a8..616ac1d8fa 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 24183d45fc..ce2545a657 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 d05799e4d0..ec0b26ab4c 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 5508a66c17..d1248db681 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 e4b1647e0c..32dd94d18c 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 dd48ff2fdf..57de5a1f68 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 ed5114e2fb..ac29eb5a8d 100644
--- a/inet/inet6_opt.c
+++ b/inet/inet6_opt.c
@@ -17,6 +17,7 @@ 
    <http://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 762149a8b6..49d5a7fc18 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 e79be7ad29..d1a11c33b1 100644
--- a/inet/inet6_rth.c
+++ b/inet/inet6_rth.c
@@ -17,6 +17,7 @@ 
    <http://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 b411ba939c..b7a1d6a2e8 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 7b07accce7..8fc9c8f641 100644
--- a/inet/netinet/tcp.h
+++ b/inet/netinet/tcp.h
@@ -85,11 +85,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.
@@ -100,61 +100,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;
       };
     };
 };
@@ -224,45 +224,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;
+  __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_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;
+  __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_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_rcv_rtt;
+  __uint32_t	tcpi_rcv_space;
 
-  uint32_t	tcpi_total_retrans;
+  __uint32_t	tcpi_total_retrans;
 };
 
 
@@ -275,18 +275,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.  */
@@ -317,30 +317,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 6aa18f48be..6d41e23e5b 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 e96e7c854e..738c05981a 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 b09e7712f4..6a1b859a13 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
    <http://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 d70973dcee..2851726376 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 81ebd9f0d6..d7a9f3c5ea 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 5d8222e3b7..8b883b6c56 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 85090a1641..c59b734210 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 94a2f6e9af..7dd74f2af3 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 678666563d..d25a478d07 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 8fcb092657..b86010684b 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 f4c5849862..909608c213 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 5ffc846e98..356e36ef68 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 440d9955d2..2b3624760b 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 da5967a87d..efcd6b4d4b 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -17,6 +17,7 @@ 
    <http://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 b63b5bfb79..61ace046b5 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
    <http://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 9417957c78..bf77e23639 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 dfa6e8d57f..001f6f1ede 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 6d6ddc6f56..4862e84257 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 6c1af6aee1..1158864312 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 21688c19b2..668cb502b2 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 c204625f4a..211a17dfd6 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 4595bc34ba..090ae0a86b 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 e477777548..2417d67dda 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 87f13d51f5..c137e50c13 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 61cc81b71f..f560ccf5cd 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 3046be24e1..fcc9fc8a84 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 eecdb7e0a3..153ce4d9cc 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 0aaba73b05..e88463ddff 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 4f68ce19e0..c4609a4db5 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 a0df6f332a..61888eadd9 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 d49d2f8459..bca1e1312d 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 7e87e641cc..c06dd62642 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 7504bdae57..a513e56544 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 db367e61ae..2ca83b90c7 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 cac527221c..cd31c3b875 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 b2fdbf7be0..f7fb0666cb 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 9770d90d2a..c8042036e5 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
similarity index 100%
rename from sysdeps/generic/sys/socketvar.h
rename to socket/sys/socketvar.h
diff --git a/sunrpc/rpc_gethostbyname.c b/sunrpc/rpc_gethostbyname.c
index c44e2a38a0..eaf96a42df 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 8f439d5fc4..b629655ec1 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 6bccb36a48..e7316a6f24 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 7ada6a8acc..02e705da25 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 604d1c2fed..e07d20d926 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 d5ab83f2ac..3f524bd0d6 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 77498ca43e..43e3cdc8c5 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 c8ddabb872..b5778f6270 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 38665feab4..6f0d1bc94d 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 fcb79bb33d..d288475426 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 d85f72b868..723aaf3e3d 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 ef3d6f9fc5..1fb3cbfb90 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	128
 
-/* 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
@@ -437,11 +409,4 @@  struct ucred
 # undef IOC_OUT
 #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 6521c9132c..4e346e9a6e 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 6698d94ead..58f24ae6cc 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 5013d085a2..767e5b4db3 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 a0d9a74af4..edd4afd3b2 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 f78d6b8a07..1c6fe6391e 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.  */