summaryrefslogtreecommitdiffstats
path: root/gl/sys_socket.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/sys_socket.in.h')
-rw-r--r--gl/sys_socket.in.h163
1 files changed, 112 insertions, 51 deletions
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index fc105e6..b4cf0c3 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -1,6 +1,6 @@
1/* Provide a sys/socket header file for systems lacking it (read: MinGW) 1/* Provide a sys/socket header file for systems lacking it (read: MinGW)
2 and for systems where it is incomplete. 2 and for systems where it is incomplete.
3 Copyright (C) 2005-2010 Free Software Foundation, Inc. 3 Copyright (C) 2005-2013 Free Software Foundation, Inc.
4 Written by Simon Josefsson. 4 Written by Simon Josefsson.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation, 17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20/* This file is supposed to be used on platforms that lack <sys/socket.h>, 19/* This file is supposed to be used on platforms that lack <sys/socket.h>,
21 on platforms where <sys/socket.h> cannot be included standalone, and on 20 on platforms where <sys/socket.h> cannot be included standalone, and on
@@ -26,6 +25,7 @@
26#if __GNUC__ >= 3 25#if __GNUC__ >= 3
27@PRAGMA_SYSTEM_HEADER@ 26@PRAGMA_SYSTEM_HEADER@
28#endif 27#endif
28@PRAGMA_COLUMNS@
29 29
30#if defined _GL_ALREADY_INCLUDING_SYS_SOCKET_H 30#if defined _GL_ALREADY_INCLUDING_SYS_SOCKET_H
31/* Special invocation convention: 31/* Special invocation convention:
@@ -39,7 +39,7 @@
39#else 39#else
40/* Normal invocation convention. */ 40/* Normal invocation convention. */
41 41
42#ifndef _GL_SYS_SOCKET_H 42#ifndef _@GUARD_PREFIX@_SYS_SOCKET_H
43 43
44#if @HAVE_SYS_SOCKET_H@ 44#if @HAVE_SYS_SOCKET_H@
45 45
@@ -49,6 +49,10 @@
49 <sys/types.h>. */ 49 <sys/types.h>. */
50# include <sys/types.h> 50# include <sys/types.h>
51 51
52/* On FreeBSD 6.4, <sys/socket.h> defines some macros that assume that NULL
53 is defined. */
54# include <stddef.h>
55
52/* The include_next requires a split double-inclusion guard. */ 56/* The include_next requires a split double-inclusion guard. */
53# @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@ 57# @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
54 58
@@ -56,8 +60,13 @@
56 60
57#endif 61#endif
58 62
59#ifndef _GL_SYS_SOCKET_H 63#ifndef _@GUARD_PREFIX@_SYS_SOCKET_H
60#define _GL_SYS_SOCKET_H 64#define _@GUARD_PREFIX@_SYS_SOCKET_H
65
66_GL_INLINE_HEADER_BEGIN
67#ifndef _GL_SYS_SOCKET_INLINE
68# define _GL_SYS_SOCKET_INLINE _GL_INLINE
69#endif
61 70
62/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 71/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
63 72
@@ -66,11 +75,21 @@
66/* The definition of _GL_WARN_ON_USE is copied here. */ 75/* The definition of _GL_WARN_ON_USE is copied here. */
67 76
68#if !@HAVE_SA_FAMILY_T@ 77#if !@HAVE_SA_FAMILY_T@
78# if !GNULIB_defined_sa_family_t
69typedef unsigned short sa_family_t; 79typedef unsigned short sa_family_t;
80# define GNULIB_defined_sa_family_t 1
81# endif
70#endif 82#endif
71 83
72#if !@HAVE_STRUCT_SOCKADDR_STORAGE@ 84#if @HAVE_STRUCT_SOCKADDR_STORAGE@
73# include <alignof.h> 85/* Make the 'struct sockaddr_storage' field 'ss_family' visible on AIX 7.1. */
86# if !@HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY@
87# ifndef ss_family
88# define ss_family __ss_family
89# endif
90# endif
91#else
92# include <stdalign.h>
74/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on 93/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
75 2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */ 94 2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */
76# define __ss_aligntype unsigned long int 95# define __ss_aligntype unsigned long int
@@ -81,12 +100,22 @@ typedef unsigned short sa_family_t;
81 : alignof (__ss_aligntype)) \ 100 : alignof (__ss_aligntype)) \
82 + sizeof (__ss_aligntype))) 101 + sizeof (__ss_aligntype)))
83 102
103# if !GNULIB_defined_struct_sockaddr_storage
84struct sockaddr_storage 104struct sockaddr_storage
85{ 105{
86 sa_family_t ss_family; /* Address family, etc. */ 106 sa_family_t ss_family; /* Address family, etc. */
87 __ss_aligntype __ss_align; /* Force desired alignment. */ 107 __ss_aligntype __ss_align; /* Force desired alignment. */
88 char __ss_padding[_SS_PADSIZE]; 108 char __ss_padding[_SS_PADSIZE];
89}; 109};
110# define GNULIB_defined_struct_sockaddr_storage 1
111# endif
112
113#endif
114
115/* Get struct iovec. */
116/* But avoid namespace pollution on glibc systems. */
117#if ! defined __GLIBC__
118# include <sys/uio.h>
90#endif 119#endif
91 120
92#if @HAVE_SYS_SOCKET_H@ 121#if @HAVE_SYS_SOCKET_H@
@@ -118,16 +147,15 @@ struct sockaddr_storage
118 that you can influence which definitions you get by setting the 147 that you can influence which definitions you get by setting the
119 WINVER symbol before including these two files. For example, 148 WINVER symbol before including these two files. For example,
120 getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that 149 getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that
121 symbol is set indiriectly through WINVER). You can set this by 150 symbol is set indirectly through WINVER). You can set this by
122 adding AC_DEFINE(WINVER, 0x0501) to configure.ac. Note that your 151 adding AC_DEFINE(WINVER, 0x0501) to configure.ac. Note that your
123 code may not run on older Windows releases then. My Windows 2000 152 code may not run on older Windows releases then. My Windows 2000
124 box was not able to run the code, for example. The situation is 153 box was not able to run the code, for example. The situation is
125 slightly confusing because: 154 slightly confusing because
126 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp 155 <http://msdn.microsoft.com/en-us/library/ms738520>
127 suggests that getaddrinfo should be available on all Windows 156 suggests that getaddrinfo should be available on all Windows
128 releases. */ 157 releases. */
129 158
130
131# if @HAVE_WINSOCK2_H@ 159# if @HAVE_WINSOCK2_H@
132# include <winsock2.h> 160# include <winsock2.h>
133# endif 161# endif
@@ -151,17 +179,34 @@ struct sockaddr_storage
151# include <sys/types.h> 179# include <sys/types.h>
152# include <io.h> 180# include <io.h>
153 181
182# if !GNULIB_defined_socklen_t
154typedef int socklen_t; 183typedef int socklen_t;
184# define GNULIB_defined_socklen_t 1
185# endif
155 186
156# endif 187# endif
157 188
189/* Rudimentary 'struct msghdr'; this works as long as you don't try to
190 access msg_control or msg_controllen. */
191struct msghdr {
192 void *msg_name;
193 socklen_t msg_namelen;
194 struct iovec *msg_iov;
195 int msg_iovlen;
196 int msg_flags;
197};
198
158#endif 199#endif
159 200
201/* Fix some definitions from <winsock2.h>. */
202
160#if @HAVE_WINSOCK2_H@ 203#if @HAVE_WINSOCK2_H@
161 204
205# if !GNULIB_defined_rpl_fd_isset
206
162/* Re-define FD_ISSET to avoid a WSA call while we are not using 207/* Re-define FD_ISSET to avoid a WSA call while we are not using
163 network sockets. */ 208 network sockets. */
164static inline int 209_GL_SYS_SOCKET_INLINE int
165rpl_fd_isset (SOCKET fd, fd_set * set) 210rpl_fd_isset (SOCKET fd, fd_set * set)
166{ 211{
167 u_int i; 212 u_int i;
@@ -175,33 +220,46 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
175 return 0; 220 return 0;
176} 221}
177 222
223# define GNULIB_defined_rpl_fd_isset 1
224# endif
225
178# undef FD_ISSET 226# undef FD_ISSET
179# define FD_ISSET(fd, set) rpl_fd_isset(fd, set) 227# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
180 228
181#endif 229#endif
182 230
183/* Wrap everything else to use libc file descriptors for sockets. */ 231/* Hide some function declarations from <winsock2.h>. */
184 232
185#if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H 233#if @HAVE_WINSOCK2_H@
186# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 234# if !defined _@GUARD_PREFIX@_UNISTD_H
187# undef close 235# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
188# define close close_used_without_including_unistd_h 236# undef close
189# else 237# define close close_used_without_including_unistd_h
190 _GL_WARN_ON_USE (close, 238# else
191 "close() used without including <unistd.h>"); 239 _GL_WARN_ON_USE (close,
240 "close() used without including <unistd.h>");
241# endif
242# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
243# undef gethostname
244# define gethostname gethostname_used_without_including_unistd_h
245# else
246 _GL_WARN_ON_USE (gethostname,
247 "gethostname() used without including <unistd.h>");
248# endif
192# endif 249# endif
193#endif 250# if !defined _@GUARD_PREFIX@_SYS_SELECT_H
194 251# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
195#if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H 252# undef select
196# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 253# define select select_used_without_including_sys_select_h
197# undef gethostname 254# else
198# define gethostname gethostname_used_without_including_unistd_h 255 _GL_WARN_ON_USE (select,
199# else 256 "select() used without including <sys/select.h>");
200 _GL_WARN_ON_USE (gethostname, 257# endif
201 "gethostname() used without including <unistd.h>");
202# endif 258# endif
203#endif 259#endif
204 260
261/* Wrap everything else to use libc file descriptors for sockets. */
262
205#if @GNULIB_SOCKET@ 263#if @GNULIB_SOCKET@
206# if @HAVE_WINSOCK2_H@ 264# if @HAVE_WINSOCK2_H@
207# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 265# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -237,8 +295,11 @@ _GL_FUNCDECL_RPL (connect, int,
237_GL_CXXALIAS_RPL (connect, int, 295_GL_CXXALIAS_RPL (connect, int,
238 (int fd, const struct sockaddr *addr, socklen_t addrlen)); 296 (int fd, const struct sockaddr *addr, socklen_t addrlen));
239# else 297# else
240_GL_CXXALIAS_SYS (connect, int, 298/* Need to cast, because on NonStop Kernel, the third parameter is
241 (int fd, const struct sockaddr *addr, socklen_t addrlen)); 299 size_t addrlen. */
300_GL_CXXALIAS_SYS_CAST (connect, int,
301 (int fd,
302 const struct sockaddr *addr, socklen_t addrlen));
242# endif 303# endif
243_GL_CXXALIASWARN (connect); 304_GL_CXXALIASWARN (connect);
244#elif @HAVE_WINSOCK2_H@ 305#elif @HAVE_WINSOCK2_H@
@@ -292,8 +353,11 @@ _GL_FUNCDECL_RPL (bind, int,
292_GL_CXXALIAS_RPL (bind, int, 353_GL_CXXALIAS_RPL (bind, int,
293 (int fd, const struct sockaddr *addr, socklen_t addrlen)); 354 (int fd, const struct sockaddr *addr, socklen_t addrlen));
294# else 355# else
295_GL_CXXALIAS_SYS (bind, int, 356/* Need to cast, because on NonStop Kernel, the third parameter is
296 (int fd, const struct sockaddr *addr, socklen_t addrlen)); 357 size_t addrlen. */
358_GL_CXXALIAS_SYS_CAST (bind, int,
359 (int fd,
360 const struct sockaddr *addr, socklen_t addrlen));
297# endif 361# endif
298_GL_CXXALIASWARN (bind); 362_GL_CXXALIASWARN (bind);
299#elif @HAVE_WINSOCK2_H@ 363#elif @HAVE_WINSOCK2_H@
@@ -514,9 +578,11 @@ _GL_CXXALIAS_RPL (sendto, ssize_t,
514 (int fd, const void *buf, size_t len, int flags, 578 (int fd, const void *buf, size_t len, int flags,
515 const struct sockaddr *to, socklen_t tolen)); 579 const struct sockaddr *to, socklen_t tolen));
516# else 580# else
517_GL_CXXALIAS_SYS (sendto, ssize_t, 581/* Need to cast, because on NonStop Kernel, the sixth parameter is
518 (int fd, const void *buf, size_t len, int flags, 582 size_t tolen. */
519 const struct sockaddr *to, socklen_t tolen)); 583_GL_CXXALIAS_SYS_CAST (sendto, ssize_t,
584 (int fd, const void *buf, size_t len, int flags,
585 const struct sockaddr *to, socklen_t tolen));
520# endif 586# endif
521_GL_CXXALIASWARN (sendto); 587_GL_CXXALIASWARN (sendto);
522#elif @HAVE_WINSOCK2_H@ 588#elif @HAVE_WINSOCK2_H@
@@ -542,8 +608,11 @@ _GL_FUNCDECL_RPL (setsockopt, int, (int fd, int level, int optname,
542_GL_CXXALIAS_RPL (setsockopt, int, (int fd, int level, int optname, 608_GL_CXXALIAS_RPL (setsockopt, int, (int fd, int level, int optname,
543 const void * optval, socklen_t optlen)); 609 const void * optval, socklen_t optlen));
544# else 610# else
545_GL_CXXALIAS_SYS (setsockopt, int, (int fd, int level, int optname, 611/* Need to cast, because on NonStop Kernel, the fifth parameter is
546 const void * optval, socklen_t optlen)); 612 size_t optlen. */
613_GL_CXXALIAS_SYS_CAST (setsockopt, int,
614 (int fd, int level, int optname,
615 const void * optval, socklen_t optlen));
547# endif 616# endif
548_GL_CXXALIASWARN (setsockopt); 617_GL_CXXALIASWARN (setsockopt);
549#elif @HAVE_WINSOCK2_H@ 618#elif @HAVE_WINSOCK2_H@
@@ -580,16 +649,6 @@ _GL_WARN_ON_USE (shutdown, "shutdown is not always POSIX compliant - "
580# endif 649# endif
581#endif 650#endif
582 651
583#if @HAVE_WINSOCK2_H@
584# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
585# undef select
586# define select select_used_without_including_sys_select_h
587# else
588 _GL_WARN_ON_USE (select,
589 "select() used without including <sys/select.h>");
590# endif
591#endif
592
593#if @GNULIB_ACCEPT4@ 652#if @GNULIB_ACCEPT4@
594/* Accept a connection on a socket, with specific opening flags. 653/* Accept a connection on a socket, with specific opening flags.
595 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) 654 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
@@ -623,6 +682,8 @@ _GL_WARN_ON_USE (accept4, "accept4 is unportable - "
623# endif 682# endif
624#endif 683#endif
625 684
626#endif /* _GL_SYS_SOCKET_H */ 685_GL_INLINE_HEADER_END
627#endif /* _GL_SYS_SOCKET_H */ 686
687#endif /* _@GUARD_PREFIX@_SYS_SOCKET_H */
688#endif /* _@GUARD_PREFIX@_SYS_SOCKET_H */
628#endif 689#endif