about summary refs log tree commit diff
path: root/REORG.TODO/socket
diff options
context:
space:
mode:
Diffstat (limited to 'REORG.TODO/socket')
-rw-r--r--REORG.TODO/socket/Makefile38
-rw-r--r--REORG.TODO/socket/Versions44
-rw-r--r--REORG.TODO/socket/accept.c35
-rw-r--r--REORG.TODO/socket/accept4.c36
-rw-r--r--REORG.TODO/socket/bind.c31
-rw-r--r--REORG.TODO/socket/bits/socket2.h77
-rw-r--r--REORG.TODO/socket/bits/types/struct_osockaddr.h12
-rw-r--r--REORG.TODO/socket/connect.c34
-rw-r--r--REORG.TODO/socket/getpeername.c31
-rw-r--r--REORG.TODO/socket/getsockname.c31
-rw-r--r--REORG.TODO/socket/getsockopt.c31
-rw-r--r--REORG.TODO/socket/isfdtype.c29
-rw-r--r--REORG.TODO/socket/listen.c33
-rw-r--r--REORG.TODO/socket/opensock.c70
-rw-r--r--REORG.TODO/socket/recv.c32
-rw-r--r--REORG.TODO/socket/recvfrom.c34
-rw-r--r--REORG.TODO/socket/recvmmsg.c31
-rw-r--r--REORG.TODO/socket/recvmsg.c32
-rw-r--r--REORG.TODO/socket/sa_len.c108
-rw-r--r--REORG.TODO/socket/send.c31
-rw-r--r--REORG.TODO/socket/sendmmsg.c32
-rw-r--r--REORG.TODO/socket/sendmsg.c32
-rw-r--r--REORG.TODO/socket/sendto.c33
-rw-r--r--REORG.TODO/socket/setsockopt.c34
-rw-r--r--REORG.TODO/socket/shutdown.c35
-rw-r--r--REORG.TODO/socket/sockatmark.c30
-rw-r--r--REORG.TODO/socket/socket.c34
-rw-r--r--REORG.TODO/socket/socketpair.c33
-rw-r--r--REORG.TODO/socket/sys/socket.h274
-rw-r--r--REORG.TODO/socket/sys/un.h46
-rw-r--r--REORG.TODO/socket/tst-accept4.c131
31 files changed, 1514 insertions, 0 deletions
diff --git a/REORG.TODO/socket/Makefile b/REORG.TODO/socket/Makefile
new file mode 100644
index 0000000000..1e2555d66d
--- /dev/null
+++ b/REORG.TODO/socket/Makefile
@@ -0,0 +1,38 @@
+# Copyright (C) 1991-2017 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+#
+#	Sub-makefile for socket portion of the library.
+#
+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
+
+routines := accept bind connect getpeername getsockname getsockopt	\
+	    listen recv recvfrom recvmsg send sendmsg sendto		\
+	    setsockopt shutdown socket socketpair isfdtype opensock	\
+	    sockatmark accept4 recvmmsg sendmmsg
+
+tests := tst-accept4
+
+aux	 := sa_len
+
+include ../Rules
diff --git a/REORG.TODO/socket/Versions b/REORG.TODO/socket/Versions
new file mode 100644
index 0000000000..7ce6f43841
--- /dev/null
+++ b/REORG.TODO/socket/Versions
@@ -0,0 +1,44 @@
+libc {
+  GLIBC_2.0 {
+    # functions used in other libraries
+    __connect; __send;
+
+    # a*
+    accept;
+
+    # b*
+    bind;
+
+    # c*
+    connect;
+
+    # g*
+    getpeername; getsockname; getsockopt;
+
+    # i*
+    isfdtype;
+
+    # l*
+    listen;
+
+    # r*
+    recv; recvfrom; recvmsg;
+
+    # s*
+    send; sendmsg; sendto; setsockopt; shutdown; socket; socketpair;
+  }
+  GLIBC_2.2.4 {
+    # Addition from P1003.1-200x
+    sockatmark;
+  }
+  GLIBC_2.10 {
+    accept4;
+  }
+  GLIBC_2.17 {
+    recvmmsg; sendmmsg;
+  }
+  GLIBC_PRIVATE {
+    __sendmmsg;
+    __recv; __socket;
+  }
+}
diff --git a/REORG.TODO/socket/accept.c b/REORG.TODO/socket/accept.c
new file mode 100644
index 0000000000..c706a95a9c
--- /dev/null
+++ b/REORG.TODO/socket/accept.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Await a connection on socket FD.
+   When a connection arrives, open a new socket to communicate with it,
+   set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
+   peer and *ADDR_LEN to the address's actual length, and return the
+   new socket's descriptor, or -1 for errors.  */
+int
+accept (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (accept)
+
+
+stub_warning (accept)
diff --git a/REORG.TODO/socket/accept4.c b/REORG.TODO/socket/accept4.c
new file mode 100644
index 0000000000..5f7a10ec62
--- /dev/null
+++ b/REORG.TODO/socket/accept4.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2008-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Await a connection on socket FD.
+   When a connection arrives, open a new socket to communicate with it,
+   set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
+   peer and *ADDR_LEN to the address's actual length, and return the
+   new socket's descriptor, or -1 for errors.  The operation can be influenced
+   by the FLAGS parameter.  */
+int
+__libc_accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+weak_alias (__libc_accept4, accept4)
+
+
+stub_warning (accept4)
diff --git a/REORG.TODO/socket/bind.c b/REORG.TODO/socket/bind.c
new file mode 100644
index 0000000000..3ebab66b71
--- /dev/null
+++ b/REORG.TODO/socket/bind.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Give the socket FD the local address ADDR (which is LEN bytes long).  */
+int
+__bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__bind, bind)
+
+stub_warning (bind)
diff --git a/REORG.TODO/socket/bits/socket2.h b/REORG.TODO/socket/bits/socket2.h
new file mode 100644
index 0000000000..4f520d727f
--- /dev/null
+++ b/REORG.TODO/socket/bits/socket2.h
@@ -0,0 +1,77 @@
+/* Checking macros for socket functions.
+   Copyright (C) 2005-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _SYS_SOCKET_H
+# error "Never include <bits/socket2.h> directly; use <sys/socket.h> instead."
+#endif
+
+extern ssize_t __recv_chk (int __fd, void *__buf, size_t __n, size_t __buflen,
+			   int __flags);
+extern ssize_t __REDIRECT (__recv_alias, (int __fd, void *__buf, size_t __n,
+					  int __flags), recv);
+extern ssize_t __REDIRECT (__recv_chk_warn,
+			   (int __fd, void *__buf, size_t __n, size_t __buflen,
+			    int __flags), __recv_chk)
+     __warnattr ("recv called with bigger length than size of destination "
+		 "buffer");
+
+__fortify_function ssize_t
+recv (int __fd, void *__buf, size_t __n, int __flags)
+{
+  if (__bos0 (__buf) != (size_t) -1)
+    {
+      if (!__builtin_constant_p (__n))
+	return __recv_chk (__fd, __buf, __n, __bos0 (__buf), __flags);
+
+      if (__n > __bos0 (__buf))
+	return __recv_chk_warn (__fd, __buf, __n, __bos0 (__buf), __flags);
+    }
+  return __recv_alias (__fd, __buf, __n, __flags);
+}
+
+extern ssize_t __recvfrom_chk (int __fd, void *__restrict __buf, size_t __n,
+			       size_t __buflen, int __flags,
+			       __SOCKADDR_ARG __addr,
+			       socklen_t *__restrict __addr_len);
+extern ssize_t __REDIRECT (__recvfrom_alias,
+			   (int __fd, void *__restrict __buf, size_t __n,
+			    int __flags, __SOCKADDR_ARG __addr,
+			    socklen_t *__restrict __addr_len), recvfrom);
+extern ssize_t __REDIRECT (__recvfrom_chk_warn,
+			   (int __fd, void *__restrict __buf, size_t __n,
+			    size_t __buflen, int __flags,
+			    __SOCKADDR_ARG __addr,
+			    socklen_t *__restrict __addr_len), __recvfrom_chk)
+     __warnattr ("recvfrom called with bigger length than size of "
+		 "destination buffer");
+
+__fortify_function ssize_t
+recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags,
+	  __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
+{
+  if (__bos0 (__buf) != (size_t) -1)
+    {
+      if (!__builtin_constant_p (__n))
+	return __recvfrom_chk (__fd, __buf, __n, __bos0 (__buf), __flags,
+			       __addr, __addr_len);
+      if (__n > __bos0 (__buf))
+	return __recvfrom_chk_warn (__fd, __buf, __n, __bos0 (__buf), __flags,
+				    __addr, __addr_len);
+    }
+  return __recvfrom_alias (__fd, __buf, __n, __flags, __addr, __addr_len);
+}
diff --git a/REORG.TODO/socket/bits/types/struct_osockaddr.h b/REORG.TODO/socket/bits/types/struct_osockaddr.h
new file mode 100644
index 0000000000..e0bf59d383
--- /dev/null
+++ b/REORG.TODO/socket/bits/types/struct_osockaddr.h
@@ -0,0 +1,12 @@
+#ifndef __osockaddr_defined
+#define __osockaddr_defined 1
+
+/* This is the 4.3 BSD `struct sockaddr' format, which is used as wire
+   format in the grotty old 4.3 `talk' protocol.  */
+struct osockaddr
+{
+  unsigned short int sa_family;
+  unsigned char sa_data[14];
+};
+
+#endif
diff --git a/REORG.TODO/socket/connect.c b/REORG.TODO/socket/connect.c
new file mode 100644
index 0000000000..24aae93a28
--- /dev/null
+++ b/REORG.TODO/socket/connect.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
+   For connectionless socket types, just set the default address to send to
+   and the only address from which to accept transmissions.
+   Return 0 on success, -1 for errors.  */
+int
+__connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+weak_alias (__connect, connect)
+libc_hidden_def (__connect)
+
+stub_warning (connect)
diff --git a/REORG.TODO/socket/getpeername.c b/REORG.TODO/socket/getpeername.c
new file mode 100644
index 0000000000..25212e80bf
--- /dev/null
+++ b/REORG.TODO/socket/getpeername.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Put the address of the peer connected to socket FD into *ADDR
+   (which is *LEN bytes long), and its actual length into *LEN.  */
+int
+getpeername (int fd, __SOCKADDR_ARG addr, socklen_t *len)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+
+stub_warning (getpeername)
diff --git a/REORG.TODO/socket/getsockname.c b/REORG.TODO/socket/getsockname.c
new file mode 100644
index 0000000000..177fde82dc
--- /dev/null
+++ b/REORG.TODO/socket/getsockname.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Put the local address of FD into *ADDR and its length in *LEN.  */
+int
+__getsockname (int fd, __SOCKADDR_ARG addr, socklen_t *len)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__getsockname, getsockname)
+
+stub_warning (getsockname)
diff --git a/REORG.TODO/socket/getsockopt.c b/REORG.TODO/socket/getsockopt.c
new file mode 100644
index 0000000000..3b0389da7c
--- /dev/null
+++ b/REORG.TODO/socket/getsockopt.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
+   into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
+   actual length.  Returns 0 on success, -1 for errors.  */
+int
+getsockopt (int fd, int level, int optname, void *optval, socklen_t *optlen)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (getsockopt)
diff --git a/REORG.TODO/socket/isfdtype.c b/REORG.TODO/socket/isfdtype.c
new file mode 100644
index 0000000000..053876fdbb
--- /dev/null
+++ b/REORG.TODO/socket/isfdtype.c
@@ -0,0 +1,29 @@
+/* isfdtype - Determine whether descriptor has given property.  Stub version.
+   Copyright (C) 1996-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/stat.h>
+
+
+int
+isfdtype (int fildes, int fdtype)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (isfdtype)
diff --git a/REORG.TODO/socket/listen.c b/REORG.TODO/socket/listen.c
new file mode 100644
index 0000000000..fe9e6b3b57
--- /dev/null
+++ b/REORG.TODO/socket/listen.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Prepare to accept connections on socket FD.
+   N connection requests will be queued before further requests are refused.
+   Returns 0 on success, -1 for errors.  */
+int
+__listen (int fd, int n)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__listen, listen)
+
+stub_warning (listen)
diff --git a/REORG.TODO/socket/opensock.c b/REORG.TODO/socket/opensock.c
new file mode 100644
index 0000000000..848cdd66b1
--- /dev/null
+++ b/REORG.TODO/socket/opensock.c
@@ -0,0 +1,70 @@
+/* Copyright (C) 1999-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <sys/socket.h>
+#include <libc-lock.h>
+
+/* Return a socket of any type.  The socket can be used in subsequent
+   ioctl calls to talk to the kernel.  */
+int internal_function
+__opensock (void)
+{
+  /* Cache the last AF that worked, to avoid many redundant calls to
+     socket().  */
+  static int sock_af = -1;
+  int fd = -1;
+  __libc_lock_define_initialized (static, lock);
+
+  if (sock_af != -1)
+    {
+      fd = __socket (sock_af, SOCK_DGRAM, 0);
+      if (fd != -1)
+        return fd;
+    }
+
+  __libc_lock_lock (lock);
+
+  if (sock_af != -1)
+    fd = __socket (sock_af, SOCK_DGRAM, 0);
+
+  if (fd == -1)
+    {
+#ifdef AF_INET
+      fd = __socket (sock_af = AF_INET, SOCK_DGRAM, 0);
+#endif
+#ifdef AF_INET6
+      if (fd < 0)
+	fd = __socket (sock_af = AF_INET6, SOCK_DGRAM, 0);
+#endif
+#ifdef AF_IPX
+      if (fd < 0)
+	fd = __socket (sock_af = AF_IPX, SOCK_DGRAM, 0);
+#endif
+#ifdef AF_AX25
+      if (fd < 0)
+	fd = __socket (sock_af = AF_AX25, SOCK_DGRAM, 0);
+#endif
+#ifdef AF_APPLETALK
+      if (fd < 0)
+	fd = __socket (sock_af = AF_APPLETALK, SOCK_DGRAM, 0);
+#endif
+    }
+
+  __libc_lock_unlock (lock);
+  return fd;
+}
diff --git a/REORG.TODO/socket/recv.c b/REORG.TODO/socket/recv.c
new file mode 100644
index 0000000000..445ba44cf5
--- /dev/null
+++ b/REORG.TODO/socket/recv.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Read N bytes into BUF from socket FD.
+   Returns the number read or -1 for errors.  */
+ssize_t
+__recv (int fd, void *buf, size_t n, int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__recv)
+weak_alias (__recv, recv)
+
+stub_warning (recv)
diff --git a/REORG.TODO/socket/recvfrom.c b/REORG.TODO/socket/recvfrom.c
new file mode 100644
index 0000000000..2641797b6b
--- /dev/null
+++ b/REORG.TODO/socket/recvfrom.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Read N bytes into BUF through socket FD from peer
+   at address ADDR (which is ADDR_LEN bytes long).
+   Returns the number read or -1 for errors.  */
+ssize_t
+__recvfrom (int fd, void *buf, size_t n, int flags, __SOCKADDR_ARG addr,
+	    socklen_t *addr_len)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__recvfrom, recvfrom)
+
+stub_warning (recvfrom)
diff --git a/REORG.TODO/socket/recvmmsg.c b/REORG.TODO/socket/recvmmsg.c
new file mode 100644
index 0000000000..18f7daf9f8
--- /dev/null
+++ b/REORG.TODO/socket/recvmmsg.c
@@ -0,0 +1,31 @@
+/* Receive multiple messages on a socket.  Stub version.
+   Copyright (C) 2010-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Receive up to VLEN messages as described by VMESSAGES from socket FD.
+   Returns the number of bytes read or -1 for errors.  */
+int
+recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
+	  struct timespec *tmo)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (recvmmsg)
diff --git a/REORG.TODO/socket/recvmsg.c b/REORG.TODO/socket/recvmsg.c
new file mode 100644
index 0000000000..d285f61543
--- /dev/null
+++ b/REORG.TODO/socket/recvmsg.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Receive a message as described by MESSAGE from socket FD.
+   Returns the number of bytes read or -1 for errors.  */
+ssize_t
+__recvmsg (int fd, struct msghdr *message, int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__recvmsg, recvmsg)
+
+stub_warning (recvmsg)
diff --git a/REORG.TODO/socket/sa_len.c b/REORG.TODO/socket/sa_len.c
new file mode 100644
index 0000000000..fcc4ed9cb9
--- /dev/null
+++ b/REORG.TODO/socket/sa_len.c
@@ -0,0 +1,108 @@
+/* Helper for SA_LEN macro.
+   Copyright (C) 2013-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/socket.h>
+
+/* If _HAVE_SA_LEN is defined, then SA_LEN just uses sockaddr.sa_len
+   and there is no need for a helper function.  */
+
+#ifndef _HAVE_SA_LEN
+
+/* All configurations have at least these two headers
+   and their associated address families.  */
+
+# include <netinet/in.h>
+# include <sys/un.h>
+
+/* More-specific sa_len.c files #define these various HAVE_*_H
+   macros and then #include this file.  */
+
+# ifdef HAVE_NETASH_ASH_H
+#  include <netash/ash.h>
+# endif
+# ifdef HAVE_NETATALK_AT_H
+#  include <netatalk/at.h>
+# endif
+# ifdef HAVE_NETAX25_AX25_H
+#  include <netax25/ax25.h>
+# endif
+# ifdef HAVE_NETECONET_EC_H
+#  include <neteconet/ec.h>
+# endif
+# ifdef HAVE_NETIPX_IPX_H
+#  include <netipx/ipx.h>
+# endif
+# ifdef HAVE_NETPACKET_PACKET_H
+#  include <netpacket/packet.h>
+# endif
+# ifdef HAVE_NETROSE_ROSE_H
+#  include <netrose/rose.h>
+# endif
+# ifdef HAVE_NETIUCV_IUCV_H
+#  include <netiucv/iucv.h>
+# endif
+
+int
+__libc_sa_len (sa_family_t af)
+{
+  switch (af)
+    {
+# ifdef HAVE_NETATALK_AT_H
+    case AF_APPLETALK:
+      return sizeof (struct sockaddr_at);
+# endif
+# ifdef HAVE_NETASH_ASH_H
+    case AF_ASH:
+      return sizeof (struct sockaddr_ash);
+# endif
+# ifdef HAVE_NETAX25_AX25_H
+    case AF_AX25:
+      return sizeof (struct sockaddr_ax25);
+# endif
+# ifdef HAVE_NETECONET_EC_H
+    case AF_ECONET:
+      return sizeof (struct sockaddr_ec);
+# endif
+    case AF_INET:
+      return sizeof (struct sockaddr_in);
+    case AF_INET6:
+      return sizeof (struct sockaddr_in6);
+# ifdef HAVE_NETIPX_IPX_H
+    case AF_IPX:
+      return sizeof (struct sockaddr_ipx);
+# endif
+# ifdef HAVE_NETIUCV_IUCV_H
+    case AF_IUCV:
+      return sizeof (struct sockaddr_iucv);
+# endif
+    case AF_LOCAL:
+      return sizeof (struct sockaddr_un);
+# ifdef HAVE_NETPACKET_PACKET_H
+    case AF_PACKET:
+      return sizeof (struct sockaddr_ll);
+# endif
+# ifdef HAVE_NETROSE_ROSE_H
+    case AF_ROSE:
+      return sizeof (struct sockaddr_rose);
+# endif
+    }
+  return 0;
+}
+libc_hidden_def (__libc_sa_len)
+
+#endif  /* Not _HAVE_SA_LEN.  */
diff --git a/REORG.TODO/socket/send.c b/REORG.TODO/socket/send.c
new file mode 100644
index 0000000000..7217ab8138
--- /dev/null
+++ b/REORG.TODO/socket/send.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Send N bytes of BUF to socket FD.  Returns the number sent or -1.  */
+ssize_t
+__send (int fd, const __ptr_t buf, size_t n, int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__send)
+weak_alias (__send, send)
+
+stub_warning (send)
diff --git a/REORG.TODO/socket/sendmmsg.c b/REORG.TODO/socket/sendmmsg.c
new file mode 100644
index 0000000000..d1827b3a4a
--- /dev/null
+++ b/REORG.TODO/socket/sendmmsg.c
@@ -0,0 +1,32 @@
+/* Send multiple messages on a socket.  Stub version.
+   Copyright (C) 2011-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Send a VLEN messages as described by VMESSAGES to socket FD.
+   Returns the number of datagrams successfully written or -1 for errors.  */
+int
+__sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__sendmmsg)
+weak_alias (__sendmmsg, sendmmsg)
+stub_warning (sendmmsg)
diff --git a/REORG.TODO/socket/sendmsg.c b/REORG.TODO/socket/sendmsg.c
new file mode 100644
index 0000000000..3d993e2a32
--- /dev/null
+++ b/REORG.TODO/socket/sendmsg.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Send a message described MESSAGE on socket FD.
+   Returns the number of bytes sent, or -1 for errors.  */
+ssize_t
+__sendmsg (int fd, const struct msghdr *message, int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__sendmsg, sendmsg)
+
+stub_warning (sendmsg)
diff --git a/REORG.TODO/socket/sendto.c b/REORG.TODO/socket/sendto.c
new file mode 100644
index 0000000000..9db72147f0
--- /dev/null
+++ b/REORG.TODO/socket/sendto.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Send N bytes of BUF on socket FD to peer at address ADDR (which is
+   ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.  */
+ssize_t
+__sendto (int fd, const __ptr_t buf, size_t n, int flags,
+	  __CONST_SOCKADDR_ARG addr, socklen_t addr_len)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__sendto, sendto)
+
+stub_warning (sendto)
diff --git a/REORG.TODO/socket/setsockopt.c b/REORG.TODO/socket/setsockopt.c
new file mode 100644
index 0000000000..4b09bead2e
--- /dev/null
+++ b/REORG.TODO/socket/setsockopt.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Set socket FD's option OPTNAME at protocol level LEVEL
+   to *OPTVAL (which is OPTLEN bytes long).
+   Returns 0 on success, -1 for errors.  */
+int
+__setsockopt (int fd, int level, int optname, const __ptr_t optval,
+	      socklen_t optlen)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__setsockopt, setsockopt)
+
+stub_warning (setsockopt)
diff --git a/REORG.TODO/socket/shutdown.c b/REORG.TODO/socket/shutdown.c
new file mode 100644
index 0000000000..bb3429bc27
--- /dev/null
+++ b/REORG.TODO/socket/shutdown.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Shut down all or part of the connection open on socket FD.
+   HOW determines what to shut down:
+     0 = No more receptions;
+     1 = No more transmissions;
+     2 = No more receptions or transmissions.
+   Returns 0 on success, -1 for errors.  */
+int
+shutdown (int fd, int how)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+
+stub_warning (shutdown)
diff --git a/REORG.TODO/socket/sockatmark.c b/REORG.TODO/socket/sockatmark.c
new file mode 100644
index 0000000000..3263f27cac
--- /dev/null
+++ b/REORG.TODO/socket/sockatmark.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2001-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Determine wheter socket is at a out-of-band mark.  */
+int
+sockatmark (int fd)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+
+stub_warning (sockatmark)
diff --git a/REORG.TODO/socket/socket.c b/REORG.TODO/socket/socket.c
new file mode 100644
index 0000000000..f44b8597b5
--- /dev/null
+++ b/REORG.TODO/socket/socket.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Create a new socket of type TYPE in domain DOMAIN, using
+   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
+   Returns a file descriptor for the new socket, or -1 for errors.  */
+int
+__socket (int domain, int type, int protocol)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+
+libc_hidden_def (__socket)
+weak_alias (__socket, socket)
+stub_warning (socket)
diff --git a/REORG.TODO/socket/socketpair.c b/REORG.TODO/socket/socketpair.c
new file mode 100644
index 0000000000..f07a038ef9
--- /dev/null
+++ b/REORG.TODO/socket/socketpair.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/socket.h>
+
+/* Create two new sockets, of type TYPE in domain DOMAIN and using
+   protocol PROTOCOL, which are connected to each other, and put file
+   descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
+   one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
+int
+socketpair (int domain, int type, int protocol, int fds[2])
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+
+stub_warning (socketpair)
diff --git a/REORG.TODO/socket/sys/socket.h b/REORG.TODO/socket/sys/socket.h
new file mode 100644
index 0000000000..bbfde8f602
--- /dev/null
+++ b/REORG.TODO/socket/sys/socket.h
@@ -0,0 +1,274 @@
+/* Declarations of socket constants, types, and functions.
+   Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef	_SYS_SOCKET_H
+#define	_SYS_SOCKET_H	1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+#include <bits/types/struct_iovec.h>
+#define	__need_size_t
+#include <stddef.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>
+
+#ifdef __USE_MISC
+# include <bits/types/struct_osockaddr.h>
+#endif
+
+/* The following constants should be used for the second parameter of
+   `shutdown'.  */
+enum
+{
+  SHUT_RD = 0,		/* No more receptions.  */
+#define SHUT_RD		SHUT_RD
+  SHUT_WR,		/* No more transmissions.  */
+#define SHUT_WR		SHUT_WR
+  SHUT_RDWR		/* No more receptions or transmissions.  */
+#define SHUT_RDWR	SHUT_RDWR
+};
+
+/* This is the type we use for generic socket address arguments.
+
+   With GCC 2.7 and later, the funky union causes redeclarations or
+   uses with any of the listed types to be allowed without complaint.
+   G++ 2.7 does not support transparent unions so there we want the
+   old-style declaration, too.  */
+#if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
+# define __SOCKADDR_ARG		struct sockaddr *__restrict
+# define __CONST_SOCKADDR_ARG	const struct sockaddr *
+#else
+/* Add more `struct sockaddr_AF' types here as necessary.
+   These are all the ones I found on NetBSD and Linux.  */
+# define __SOCKADDR_ALLTYPES \
+  __SOCKADDR_ONETYPE (sockaddr) \
+  __SOCKADDR_ONETYPE (sockaddr_at) \
+  __SOCKADDR_ONETYPE (sockaddr_ax25) \
+  __SOCKADDR_ONETYPE (sockaddr_dl) \
+  __SOCKADDR_ONETYPE (sockaddr_eon) \
+  __SOCKADDR_ONETYPE (sockaddr_in) \
+  __SOCKADDR_ONETYPE (sockaddr_in6) \
+  __SOCKADDR_ONETYPE (sockaddr_inarp) \
+  __SOCKADDR_ONETYPE (sockaddr_ipx) \
+  __SOCKADDR_ONETYPE (sockaddr_iso) \
+  __SOCKADDR_ONETYPE (sockaddr_ns) \
+  __SOCKADDR_ONETYPE (sockaddr_un) \
+  __SOCKADDR_ONETYPE (sockaddr_x25)
+
+# define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__;
+typedef union { __SOCKADDR_ALLTYPES
+	      } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
+# undef __SOCKADDR_ONETYPE
+# define __SOCKADDR_ONETYPE(type) const struct type *__restrict __##type##__;
+typedef union { __SOCKADDR_ALLTYPES
+	      } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
+# undef __SOCKADDR_ONETYPE
+#endif
+
+#ifdef __USE_GNU
+/* For `recvmmsg' and `sendmmsg'.  */
+struct mmsghdr
+  {
+    struct msghdr msg_hdr;	/* Actual message header.  */
+    unsigned int msg_len;	/* Number of received or sent bytes for the
+				   entry.  */
+  };
+#endif
+
+
+/* Create a new socket of type TYPE in domain DOMAIN, using
+   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
+   Returns a file descriptor for the new socket, or -1 for errors.  */
+extern int socket (int __domain, int __type, int __protocol) __THROW;
+
+/* Create two new sockets, of type TYPE in domain DOMAIN and using
+   protocol PROTOCOL, which are connected to each other, and put file
+   descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
+   one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
+extern int socketpair (int __domain, int __type, int __protocol,
+		       int __fds[2]) __THROW;
+
+/* Give the socket FD the local address ADDR (which is LEN bytes long).  */
+extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
+     __THROW;
+
+/* Put the local address of FD into *ADDR and its length in *LEN.  */
+extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
+			socklen_t *__restrict __len) __THROW;
+
+/* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
+   For connectionless socket types, just set the default address to send to
+   and the only address from which to accept transmissions.
+   Return 0 on success, -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
+
+/* Put the address of the peer connected to socket FD into *ADDR
+   (which is *LEN bytes long), and its actual length into *LEN.  */
+extern int getpeername (int __fd, __SOCKADDR_ARG __addr,
+			socklen_t *__restrict __len) __THROW;
+
+
+/* Send N bytes of BUF to socket FD.  Returns the number sent or -1.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern ssize_t send (int __fd, const void *__buf, size_t __n, int __flags);
+
+/* Read N bytes into BUF from socket FD.
+   Returns the number read or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags);
+
+/* Send N bytes of BUF on socket FD to peer at address ADDR (which is
+   ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern ssize_t sendto (int __fd, const void *__buf, size_t __n,
+		       int __flags, __CONST_SOCKADDR_ARG __addr,
+		       socklen_t __addr_len);
+
+/* Read N bytes into BUF through socket FD.
+   If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
+   the sender, and store the actual size of the address in *ADDR_LEN.
+   Returns the number of bytes read or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n,
+			 int __flags, __SOCKADDR_ARG __addr,
+			 socklen_t *__restrict __addr_len);
+
+
+/* Send a message described MESSAGE on socket FD.
+   Returns the number of bytes sent, or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern ssize_t sendmsg (int __fd, const struct msghdr *__message,
+			int __flags);
+
+#ifdef __USE_GNU
+/* Send a VLEN messages as described by VMESSAGES to socket FD.
+   Returns the number of datagrams successfully written or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int sendmmsg (int __fd, struct mmsghdr *__vmessages,
+		     unsigned int __vlen, int __flags);
+#endif
+
+/* Receive a message as described by MESSAGE from socket FD.
+   Returns the number of bytes read or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags);
+
+#ifdef __USE_GNU
+/* Receive up to VLEN messages as described by VMESSAGES from socket FD.
+   Returns the number of messages received or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int recvmmsg (int __fd, struct mmsghdr *__vmessages,
+		     unsigned int __vlen, int __flags,
+		     struct timespec *__tmo);
+#endif
+
+
+/* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
+   into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
+   actual length.  Returns 0 on success, -1 for errors.  */
+extern int getsockopt (int __fd, int __level, int __optname,
+		       void *__restrict __optval,
+		       socklen_t *__restrict __optlen) __THROW;
+
+/* Set socket FD's option OPTNAME at protocol level LEVEL
+   to *OPTVAL (which is OPTLEN bytes long).
+   Returns 0 on success, -1 for errors.  */
+extern int setsockopt (int __fd, int __level, int __optname,
+		       const void *__optval, socklen_t __optlen) __THROW;
+
+
+/* Prepare to accept connections on socket FD.
+   N connection requests will be queued before further requests are refused.
+   Returns 0 on success, -1 for errors.  */
+extern int listen (int __fd, int __n) __THROW;
+
+/* Await a connection on socket FD.
+   When a connection arrives, open a new socket to communicate with it,
+   set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
+   peer and *ADDR_LEN to the address's actual length, and return the
+   new socket's descriptor, or -1 for errors.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int accept (int __fd, __SOCKADDR_ARG __addr,
+		   socklen_t *__restrict __addr_len);
+
+#ifdef __USE_GNU
+/* Similar to 'accept' but takes an additional parameter to specify flags.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int accept4 (int __fd, __SOCKADDR_ARG __addr,
+		    socklen_t *__restrict __addr_len, int __flags);
+#endif
+
+/* Shut down all or part of the connection open on socket FD.
+   HOW determines what to shut down:
+     SHUT_RD   = No more receptions;
+     SHUT_WR   = No more transmissions;
+     SHUT_RDWR = No more receptions or transmissions.
+   Returns 0 on success, -1 for errors.  */
+extern int shutdown (int __fd, int __how) __THROW;
+
+
+#ifdef __USE_XOPEN2K
+/* Determine wheter socket is at a out-of-band mark.  */
+extern int sockatmark (int __fd) __THROW;
+#endif
+
+
+#ifdef __USE_MISC
+/* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>;
+   returns 1 if FD is open on an object of the indicated type, 0 if not,
+   or -1 for errors (setting errno).  */
+extern int isfdtype (int __fd, int __fdtype) __THROW;
+#endif
+
+
+/* Define some macros helping to catch buffer overflows.  */
+#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
+# include <bits/socket2.h>
+#endif
+
+__END_DECLS
+
+#endif /* sys/socket.h */
diff --git a/REORG.TODO/socket/sys/un.h b/REORG.TODO/socket/sys/un.h
new file mode 100644
index 0000000000..fc82f8c929
--- /dev/null
+++ b/REORG.TODO/socket/sys/un.h
@@ -0,0 +1,46 @@
+/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef	_SYS_UN_H
+#define	_SYS_UN_H	1
+
+#include <sys/cdefs.h>
+
+/* Get the definition of the macro to define the common sockaddr members.  */
+#include <bits/sockaddr.h>
+
+__BEGIN_DECLS
+
+/* Structure describing the address of an AF_LOCAL (aka AF_UNIX) socket.  */
+struct sockaddr_un
+  {
+    __SOCKADDR_COMMON (sun_);
+    char sun_path[108];		/* Path name.  */
+  };
+
+
+#ifdef __USE_MISC
+# include <string.h>		/* For prototype of `strlen'.  */
+
+/* Evaluate to actual length of the `sockaddr_un' structure.  */
+# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)	      \
+		      + strlen ((ptr)->sun_path))
+#endif
+
+__END_DECLS
+
+#endif	/* sys/un.h  */
diff --git a/REORG.TODO/socket/tst-accept4.c b/REORG.TODO/socket/tst-accept4.c
new file mode 100644
index 0000000000..a5cf3a237b
--- /dev/null
+++ b/REORG.TODO/socket/tst-accept4.c
@@ -0,0 +1,131 @@
+/* Test the accept4 function with differing flags arguments.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <support/check.h>
+#include <support/xsocket.h>
+#include <support/xunistd.h>
+#include <sys/socket.h>
+
+static bool
+is_nonblocking (int fd)
+{
+  int status = fcntl (fd, F_GETFL);
+  if (status < 0)
+    FAIL_EXIT1 ("fcntl (F_GETFL): %m");
+  return status & O_NONBLOCK;
+}
+
+static bool
+is_cloexec (int fd)
+{
+  int status = fcntl (fd, F_GETFD);
+  if (status < 0)
+    FAIL_EXIT1 ("fcntl (F_GETFD): %m");
+  return status & FD_CLOEXEC;
+}
+
+struct client
+{
+  int socket;
+  struct sockaddr_in address;
+};
+
+/* Perform a non-blocking connect to *SERVER_ADDRESS.  */
+static struct client
+client_connect (const struct sockaddr_in *server_address)
+{
+  struct client result;
+  result.socket = xsocket (AF_INET,
+                           SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
+  TEST_VERIFY (is_nonblocking (result.socket));
+  TEST_VERIFY (is_cloexec (result.socket));
+  int ret = connect (result.socket, (const struct sockaddr *) server_address,
+                     sizeof (*server_address));
+  if (ret < 0 && errno != EINPROGRESS)
+    FAIL_EXIT1 ("client connect: %m");
+  socklen_t sa_len = sizeof (result.address);
+  xgetsockname (result.socket, (struct sockaddr *) &result.address,
+                &sa_len);
+  TEST_VERIFY (sa_len == sizeof (result.address));
+  return result;
+}
+
+static void
+check_same_address (const struct sockaddr_in *left,
+                    const struct sockaddr_in *right)
+{
+  TEST_VERIFY (left->sin_family == AF_INET);
+  TEST_VERIFY (right->sin_family == AF_INET);
+  TEST_VERIFY (left->sin_addr.s_addr == right->sin_addr.s_addr);
+  TEST_VERIFY (left->sin_port == right->sin_port);
+}
+
+static int
+do_test (void)
+{
+  /* Create server socket.  */
+  int server_socket = xsocket (AF_INET, SOCK_STREAM, 0);
+  TEST_VERIFY (!is_nonblocking (server_socket));
+  TEST_VERIFY (!is_cloexec (server_socket));
+  struct sockaddr_in server_address =
+    {
+      .sin_family = AF_INET,
+      .sin_addr = {.s_addr = htonl (INADDR_LOOPBACK) },
+    };
+  xbind (server_socket,
+         (struct sockaddr *) &server_address, sizeof (server_address));
+  {
+    socklen_t sa_len = sizeof (server_address);
+    xgetsockname (server_socket, (struct sockaddr *) &server_address,
+                  &sa_len);
+    TEST_VERIFY (sa_len == sizeof (server_address));
+  }
+  xlisten (server_socket, 5);
+
+  for (int do_nonblock = 0; do_nonblock < 2; ++do_nonblock)
+    for (int do_cloexec = 0; do_cloexec < 2; ++do_cloexec)
+      {
+        int sockflags = 0;
+        if (do_nonblock)
+          sockflags |= SOCK_NONBLOCK;
+        if (do_cloexec)
+          sockflags |= SOCK_CLOEXEC;
+
+        struct client client = client_connect (&server_address);
+        struct sockaddr_in client_address;
+        socklen_t sa_len = sizeof (client_address);
+        int client_socket = xaccept4 (server_socket,
+                                      (struct sockaddr *) &client_address,
+                                      &sa_len, sockflags);
+        TEST_VERIFY (sa_len == sizeof (client_address));
+        TEST_VERIFY (is_nonblocking (client_socket) == do_nonblock);
+        TEST_VERIFY (is_cloexec (client_socket) == do_cloexec);
+        check_same_address (&client.address, &client_address);
+        xclose (client_socket);
+        xclose (client.socket);
+      }
+
+  xclose (server_socket);
+  return 0;
+}
+
+#include <support/test-driver.c>