diff options
Diffstat (limited to 'socket')
-rw-r--r-- | socket/Makefile | 9 | ||||
-rw-r--r-- | socket/accept.c | 2 | ||||
-rw-r--r-- | socket/accept4.c | 2 | ||||
-rw-r--r-- | socket/bind.c | 2 | ||||
-rw-r--r-- | socket/bits/socket2.h | 2 | ||||
-rw-r--r-- | socket/bits/types/struct_osockaddr.h | 12 | ||||
-rw-r--r-- | socket/connect.c | 2 | ||||
-rw-r--r-- | socket/getpeername.c | 2 | ||||
-rw-r--r-- | socket/getsockname.c | 2 | ||||
-rw-r--r-- | socket/getsockopt.c | 2 | ||||
-rw-r--r-- | socket/have_sock_cloexec.c | 28 | ||||
-rw-r--r-- | socket/isfdtype.c | 2 | ||||
-rw-r--r-- | socket/listen.c | 2 | ||||
-rw-r--r-- | socket/opensock.c | 4 | ||||
-rw-r--r-- | socket/recv.c | 2 | ||||
-rw-r--r-- | socket/recvfrom.c | 2 | ||||
-rw-r--r-- | socket/recvmmsg.c | 2 | ||||
-rw-r--r-- | socket/recvmsg.c | 2 | ||||
-rw-r--r-- | socket/sa_len.c | 2 | ||||
-rw-r--r-- | socket/send.c | 4 | ||||
-rw-r--r-- | socket/sendmmsg.c | 2 | ||||
-rw-r--r-- | socket/sendmsg.c | 2 | ||||
-rw-r--r-- | socket/sendto.c | 4 | ||||
-rw-r--r-- | socket/setsockopt.c | 4 | ||||
-rw-r--r-- | socket/shutdown.c | 2 | ||||
-rw-r--r-- | socket/sockatmark.c | 2 | ||||
-rw-r--r-- | socket/socket.c | 2 | ||||
-rw-r--r-- | socket/socketpair.c | 2 | ||||
-rw-r--r-- | socket/sys/socket.h | 17 | ||||
-rw-r--r-- | socket/sys/un.h | 2 | ||||
-rw-r--r-- | socket/tst-accept4.c | 131 |
31 files changed, 182 insertions, 75 deletions
diff --git a/socket/Makefile b/socket/Makefile index 92450e8522..b41eb07150 100644 --- a/socket/Makefile +++ b/socket/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2016 Free Software Foundation, Inc. +# Copyright (C) 1991-2018 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 @@ -23,13 +23,16 @@ subdir := socket include ../Makeconfig headers := sys/socket.h sys/un.h bits/sockaddr.h bits/socket.h \ - bits/socket2.h sys/socketvar.h net/if.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 -aux := have_sock_cloexec sa_len +tests := tst-accept4 + +aux := sa_len include ../Rules diff --git a/socket/accept.c b/socket/accept.c index a28042f5c5..84894a97d6 100644 --- a/socket/accept.c +++ b/socket/accept.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/accept4.c b/socket/accept4.c index b2cdb1ef65..88bcc231e0 100644 --- a/socket/accept4.c +++ b/socket/accept4.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2016 Free Software Foundation, Inc. +/* Copyright (C) 2008-2018 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 diff --git a/socket/bind.c b/socket/bind.c index cd47a7cb8e..45cef47a72 100644 --- a/socket/bind.c +++ b/socket/bind.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/bits/socket2.h b/socket/bits/socket2.h index f499518f5c..a129e69735 100644 --- a/socket/bits/socket2.h +++ b/socket/bits/socket2.h @@ -1,5 +1,5 @@ /* Checking macros for socket functions. - Copyright (C) 2005-2016 Free Software Foundation, Inc. + Copyright (C) 2005-2018 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 diff --git a/socket/bits/types/struct_osockaddr.h b/socket/bits/types/struct_osockaddr.h new file mode 100644 index 0000000000..e0bf59d383 --- /dev/null +++ b/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/socket/connect.c b/socket/connect.c index 4e7eb1c9a9..ceb7dc4a72 100644 --- a/socket/connect.c +++ b/socket/connect.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/getpeername.c b/socket/getpeername.c index 5784cc5bc2..e273b6b1e8 100644 --- a/socket/getpeername.c +++ b/socket/getpeername.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/getsockname.c b/socket/getsockname.c index ed7b2ff8e7..fe43b12b3d 100644 --- a/socket/getsockname.c +++ b/socket/getsockname.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/getsockopt.c b/socket/getsockopt.c index 1894eca594..508e80e992 100644 --- a/socket/getsockopt.c +++ b/socket/getsockopt.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/have_sock_cloexec.c b/socket/have_sock_cloexec.c deleted file mode 100644 index 3284094d76..0000000000 --- a/socket/have_sock_cloexec.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2008-2016 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 <fcntl.h> -#include <sys/socket.h> -#include <kernel-features.h> - -#if defined O_CLOEXEC && !defined __ASSUME_PIPE2 -int __have_pipe2; -#endif - -#if defined O_CLOEXEC && !defined __ASSUME_DUP3 -int __have_dup3; -#endif diff --git a/socket/isfdtype.c b/socket/isfdtype.c index 7d4ae0590c..a3dbf1a757 100644 --- a/socket/isfdtype.c +++ b/socket/isfdtype.c @@ -1,5 +1,5 @@ /* isfdtype - Determine whether descriptor has given property. Stub version. - Copyright (C) 1996-2016 Free Software Foundation, Inc. + Copyright (C) 1996-2018 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 diff --git a/socket/listen.c b/socket/listen.c index 32de51c008..962b169d96 100644 --- a/socket/listen.c +++ b/socket/listen.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/opensock.c b/socket/opensock.c index 19b96192c4..b065fb692c 100644 --- a/socket/opensock.c +++ b/socket/opensock.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999-2016 Free Software Foundation, Inc. +/* Copyright (C) 1999-2018 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 @@ -21,7 +21,7 @@ /* Return a socket of any type. The socket can be used in subsequent ioctl calls to talk to the kernel. */ -int internal_function +int __opensock (void) { /* Cache the last AF that worked, to avoid many redundant calls to diff --git a/socket/recv.c b/socket/recv.c index 3e4232d555..6e8938d952 100644 --- a/socket/recv.c +++ b/socket/recv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/recvfrom.c b/socket/recvfrom.c index 357c0b5ad3..7b87d9436e 100644 --- a/socket/recvfrom.c +++ b/socket/recvfrom.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/recvmmsg.c b/socket/recvmmsg.c index 2a8755aa57..2fc95c0fb7 100644 --- a/socket/recvmmsg.c +++ b/socket/recvmmsg.c @@ -1,5 +1,5 @@ /* Receive multiple messages on a socket. Stub version. - Copyright (C) 2010-2016 Free Software Foundation, Inc. + Copyright (C) 2010-2018 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 diff --git a/socket/recvmsg.c b/socket/recvmsg.c index 83cd3b6979..2bd80c36b8 100644 --- a/socket/recvmsg.c +++ b/socket/recvmsg.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/sa_len.c b/socket/sa_len.c index 1a7f21d5f9..1efc1baeb5 100644 --- a/socket/sa_len.c +++ b/socket/sa_len.c @@ -1,5 +1,5 @@ /* Helper for SA_LEN macro. - Copyright (C) 2013-2016 Free Software Foundation, Inc. + Copyright (C) 2013-2018 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 diff --git a/socket/send.c b/socket/send.c index 305934d6f2..6a3b887d8e 100644 --- a/socket/send.c +++ b/socket/send.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -20,7 +20,7 @@ /* 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) +__send (int fd, const void *buf, size_t n, int flags) { __set_errno (ENOSYS); return -1; diff --git a/socket/sendmmsg.c b/socket/sendmmsg.c index 12a018b526..bf34ed3c65 100644 --- a/socket/sendmmsg.c +++ b/socket/sendmmsg.c @@ -1,5 +1,5 @@ /* Send multiple messages on a socket. Stub version. - Copyright (C) 2011-2016 Free Software Foundation, Inc. + Copyright (C) 2011-2018 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 diff --git a/socket/sendmsg.c b/socket/sendmsg.c index e72f64374b..34ec5ead42 100644 --- a/socket/sendmsg.c +++ b/socket/sendmsg.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/sendto.c b/socket/sendto.c index 1419ce3f7d..b00a30c04a 100644 --- a/socket/sendto.c +++ b/socket/sendto.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 @@ -21,7 +21,7 @@ /* 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, +__sendto (int fd, const void *buf, size_t n, int flags, __CONST_SOCKADDR_ARG addr, socklen_t addr_len) { __set_errno (ENOSYS); diff --git a/socket/setsockopt.c b/socket/setsockopt.c index 6f3891849e..6c54cce640 100644 --- a/socket/setsockopt.c +++ b/socket/setsockopt.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 @@ -22,7 +22,7 @@ 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, +__setsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen) { __set_errno (ENOSYS); diff --git a/socket/shutdown.c b/socket/shutdown.c index d33f6bb566..152ce655c5 100644 --- a/socket/shutdown.c +++ b/socket/shutdown.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/sockatmark.c b/socket/sockatmark.c index c35c2bf44e..f8baa34bf3 100644 --- a/socket/sockatmark.c +++ b/socket/sockatmark.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2016 Free Software Foundation, Inc. +/* Copyright (C) 2001-2018 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 diff --git a/socket/socket.c b/socket/socket.c index 19d74ee60a..7ef09d019b 100644 --- a/socket/socket.c +++ b/socket/socket.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/socketpair.c b/socket/socketpair.c index 3cd7dcad06..01f54a1204 100644 --- a/socket/socketpair.c +++ b/socket/socketpair.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/sys/socket.h b/socket/sys/socket.h index c9f0f5080d..4a9c016456 100644 --- a/socket/sys/socket.h +++ b/socket/sys/socket.h @@ -1,5 +1,5 @@ /* Declarations of socket constants, types, and functions. - Copyright (C) 1991-2016 Free Software Foundation, Inc. + Copyright (C) 1991-2018 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 @@ -23,14 +23,9 @@ __BEGIN_DECLS -#include <sys/uio.h> +#include <bits/types/struct_iovec.h> #define __need_size_t #include <stddef.h> -#ifdef __USE_GNU -/* Get the __sigset_t definition. */ -# include <bits/sigset.h> -#endif - /* This operating system-specific header file defines the SOCK_*, PF_*, AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr', @@ -38,13 +33,7 @@ __BEGIN_DECLS #include <bits/socket.h> #ifdef __USE_MISC -/* 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]; - }; +# include <bits/types/struct_osockaddr.h> #endif /* The following constants should be used for the second parameter of diff --git a/socket/sys/un.h b/socket/sys/un.h index 7a1a67b22e..efc2194a3a 100644 --- a/socket/sys/un.h +++ b/socket/sys/un.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2016 Free Software Foundation, Inc. +/* Copyright (C) 1991-2018 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 diff --git a/socket/tst-accept4.c b/socket/tst-accept4.c new file mode 100644 index 0000000000..e1c61370b8 --- /dev/null +++ b/socket/tst-accept4.c @@ -0,0 +1,131 @@ +/* Test the accept4 function with differing flags arguments. + Copyright (C) 2017-2018 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> |