gettext: Sync with gettext 0.23.
[gnulib.git] / tests / test-sys_socket.c
blob5c1ad1154074b76f97c4453774e45bcad357bdfd
1 /* Test of <sys/socket.h> substitute.
2 Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 #include <config.h>
21 #include <sys/socket.h>
23 /* POSIX mandates that AF_UNSPEC shall be 0. */
24 static_assert (AF_UNSPEC == 0);
26 /* Check that the 'socklen_t' type is defined. */
27 socklen_t t1;
29 /* Check that the 'size_t' and 'ssize_t' types are defined. */
30 size_t t2;
31 ssize_t t3;
33 /* Check that 'struct iovec' is defined. */
34 struct iovec io;
36 /* Check that a minimal set of 'struct msghdr' is defined. */
37 struct msghdr msg;
39 #include <errno.h>
41 #include "intprops.h"
43 /* POSIX requires that 'socklen_t' is an integer type with a width of at
44 least 32 bits. */
45 static_assert (32 <= TYPE_WIDTH (socklen_t));
47 /* POSIX requires that sa_family_t is an unsigned integer type. */
48 static_assert (! TYPE_SIGNED (sa_family_t));
51 int
52 main (void)
54 struct sockaddr_storage x;
55 sa_family_t i;
57 /* Check some errno values. */
58 switch (ENOTSOCK)
60 case ENOTSOCK:
61 case EADDRINUSE:
62 case ENETRESET:
63 case ECONNABORTED:
64 case ECONNRESET:
65 case ENOTCONN:
66 case ESHUTDOWN:
67 break;
70 /* Check that each supported address family has a distinct value. */
71 switch (0)
73 case AF_UNSPEC:
74 #if HAVE_IPV4
75 case AF_INET:
76 #endif
77 #if HAVE_IPV6
78 case AF_INET6:
79 #endif
80 #if HAVE_UNIXSOCKET
81 case AF_UNIX:
82 #endif
83 default:
84 break;
87 /* Check that the shutdown type macros are defined to distinct values. */
88 #if HAVE_SHUTDOWN
89 switch (0)
91 case SHUT_RD:
92 case SHUT_WR:
93 case SHUT_RDWR:
94 default:
95 break;
97 #endif
99 x.ss_family = 42;
100 i = 42;
101 msg.msg_iov = &io;
103 return (x.ss_family - i + msg.msg_namelen + msg.msg_iov->iov_len
104 + msg.msg_iovlen);