Override <sys/socket.h> when it exists but is incomplete.
[gnulib.git] / lib / sys_socket.in.h
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.
5
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)
9    any later version.
10
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.
15
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.  */
19
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
24    application.  */
25
26 #ifndef _GL_SYS_SOCKET_H
27
28 #if @HAVE_SYS_SOCKET_H@
29
30 /* On many platforms, <sys/socket.h> assumes prior inclusion of
31    <sys/types.h>.  */
32 # include <sys/types.h>
33
34 /* The include_next requires a split double-inclusion guard.  */
35 # @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
36
37 #endif
38
39 #ifndef _GL_SYS_SOCKET_H
40 #define _GL_SYS_SOCKET_H
41
42 #if @HAVE_SYS_SOCKET_H@
43
44 /* A platform that has <sys/socket.h>.  */
45
46 /* For shutdown().  */
47 # if !defined SHUT_RD
48 #  define SHUT_RD 0
49 # endif
50 # if !defined SHUT_WR
51 #  define SHUT_WR 1
52 # endif
53 # if !defined SHUT_RDWR
54 #  define SHUT_RDWR 2
55 # endif
56
57 #else
58
59 /* A platform that lacks <sys/socket.h>.
60
61    Currently only MinGW is supported.  See the gnulib manual regarding
62    Windows sockets.  MinGW has the header files winsock2.h and
63    ws2tcpip.h that declare the sys/socket.h definitions we need.  Note
64    that you can influence which definitions you get by setting the
65    WINVER symbol before including these two files.  For example,
66    getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that
67    symbol is set indiriectly through WINVER).  You can set this by
68    adding AC_DEFINE(WINVER, 0x0501) to configure.ac.  Note that your
69    code may not run on older Windows releases then.  My Windows 2000
70    box was not able to run the code, for example.  The situation is
71    slightly confusing because:
72    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
73    suggests that getaddrinfo should be available on all Windows
74    releases. */
75
76
77 # if @HAVE_WINSOCK2_H@
78 #  include <winsock2.h>
79 # endif
80 # if @HAVE_WS2TCPIP_H@
81 #  include <ws2tcpip.h>
82 # endif
83
84 /* For shutdown(). */
85 # if !defined SHUT_RD && defined SD_RECEIVE
86 #  define SHUT_RD SD_RECEIVE
87 # endif
88 # if !defined SHUT_WR && defined SD_SEND
89 #  define SHUT_WR SD_SEND
90 # endif
91 # if !defined SHUT_RDWR && defined SD_BOTH
92 #  define SHUT_RDWR SD_BOTH
93 # endif
94
95 # if defined _WIN32 || defined __WIN32__
96 #  define ENOTSOCK                WSAENOTSOCK
97 #  define EADDRINUSE              WSAEADDRINUSE
98 #  define ENETRESET               WSAENETRESET
99 #  define ECONNABORTED            WSAECONNABORTED
100 #  define ECONNRESET              WSAECONNRESET
101 #  define ENOTCONN                WSAENOTCONN
102 #  define ESHUTDOWN               WSAESHUTDOWN
103 # endif
104
105 #endif /* HAVE_SYS_SOCKET_H */
106
107 #endif /* _GL_SYS_SOCKET_H */
108 #endif /* _GL_SYS_SOCKET_H */