1 /* Provide a sys/socket header file for systems lacking it (read: MinGW)
2 and for systems where it is incomplete.
3 Copyright (C) 2005-2008 Free Software Foundation, Inc.
4 Written by Simon Josefsson.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
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,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* 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
22 platforms where <sys/socket.h> does not provide all necessary definitions.
23 It is intended to provide definitions and prototypes needed by an
26 #ifndef _GL_SYS_SOCKET_H
28 #if @HAVE_SYS_SOCKET_H@
30 @PRAGMA_SYSTEM_HEADER@
32 /* On many platforms, <sys/socket.h> assumes prior inclusion of
34 # include <sys/types.h>
36 /* The include_next requires a split double-inclusion guard. */
37 # @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
41 #ifndef _GL_SYS_SOCKET_H
42 #define _GL_SYS_SOCKET_H
44 #if @HAVE_SYS_SOCKET_H@
46 /* A platform that has <sys/socket.h>. */
55 # if !defined SHUT_RDWR
61 /* A platform that lacks <sys/socket.h>.
63 Currently only MinGW is supported. See the gnulib manual regarding
64 Windows sockets. MinGW has the header files winsock2.h and
65 ws2tcpip.h that declare the sys/socket.h definitions we need. Note
66 that you can influence which definitions you get by setting the
67 WINVER symbol before including these two files. For example,
68 getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that
69 symbol is set indiriectly through WINVER). You can set this by
70 adding AC_DEFINE(WINVER, 0x0501) to configure.ac. Note that your
71 code may not run on older Windows releases then. My Windows 2000
72 box was not able to run the code, for example. The situation is
73 slightly confusing because:
74 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
75 suggests that getaddrinfo should be available on all Windows
79 # if @HAVE_WINSOCK2_H@
80 # include <winsock2.h>
82 # if @HAVE_WS2TCPIP_H@
83 # include <ws2tcpip.h>
87 # if !defined SHUT_RD && defined SD_RECEIVE
88 # define SHUT_RD SD_RECEIVE
90 # if !defined SHUT_WR && defined SD_SEND
91 # define SHUT_WR SD_SEND
93 # if !defined SHUT_RDWR && defined SD_BOTH
94 # define SHUT_RDWR SD_BOTH
97 # if defined _WIN32 || defined __WIN32__
98 # define EINPROGRESS WSAEINPROGRESS
99 # define ENOTSOCK WSAENOTSOCK
100 # define EADDRINUSE WSAEADDRINUSE
101 # define ENETRESET WSAENETRESET
102 # define ECONNABORTED WSAECONNABORTED
103 # define ECONNRESET WSAECONNRESET
104 # define ENOTCONN WSAENOTCONN
105 # define ESHUTDOWN WSAESHUTDOWN
108 # if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
109 # define setsockopt(a,b,c,d,e) rpl_setsockopt(a,b,c,d,e)
111 rpl_setsockopt(int socket, int level, int optname, const void *optval,
114 return (setsockopt)(socket, level, optname, optval, optlen);
118 #endif /* HAVE_SYS_SOCKET_H */
120 #endif /* _GL_SYS_SOCKET_H */
121 #endif /* _GL_SYS_SOCKET_H */