Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[bpt/emacs.git] / nt / inc / sys / socket.h
1 /* Copyright (C) 1995, 2001-2013 Free Software Foundation, Inc.
2
3 This file is part of GNU Emacs.
4
5 GNU Emacs is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 GNU Emacs is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
17
18
19 /* Workable version of <sys/socket.h> based on winsock.h */
20
21 #ifndef _SOCKET_H_
22 #define _SOCKET_H_
23
24 /* defeat the multiple include protection */
25 #ifdef _WINSOCKAPI_
26 #undef _WINSOCKAPI_
27 #endif
28 #ifdef _WINSOCK_H
29 #undef _WINSOCK_H
30 #endif
31
32 /* avoid confusion with our version of select */
33 #ifdef select
34 #undef select
35 #define MUST_REDEF_SELECT
36 #endif
37
38 /* avoid clashing with our version of FD_SET if already defined */
39 #ifdef FD_SET
40 #undef FD_SET
41 #undef FD_CLR
42 #undef FD_ISSET
43 #undef FD_ZERO
44 #endif
45
46 /* avoid duplicate definition of timeval */
47 #ifdef HAVE_TIMEVAL
48 #define timeval ws_timeval
49 #endif
50
51 #include <winsock2.h>
52 #include <ws2tcpip.h>
53 /* process.c uses uint16_t (from C99) for IPv6, but
54 apparently it is not defined in some versions of mingw and msvc. */
55 #ifndef UINT16_C
56 typedef unsigned short uint16_t;
57 #endif
58
59 /* redefine select to reference our version */
60 #ifdef MUST_REDEF_SELECT
61 #define select sys_select
62 #undef MUST_REDEF_SELECT
63 #endif
64
65 /* revert to our version of FD_SET */
66 #undef FD_SET
67 #undef FD_CLR
68 #undef FD_ISSET
69 #undef FD_ZERO
70
71 /* allow us to provide our own version of fd_set */
72 #define fd_set ws_fd_set
73 #include "w32.h"
74
75 #ifdef HAVE_TIMEVAL
76 #undef timeval
77 #endif
78
79 /* shadow functions where we provide our own wrapper */
80 #define socket sys_socket
81 #define bind sys_bind
82 #define connect sys_connect
83 #define htons sys_htons
84 #define ntohs sys_ntohs
85 #define inet_addr sys_inet_addr
86 #define gethostname sys_gethostname
87 #define gethostbyname sys_gethostbyname
88 #define getpeername sys_getpeername
89 #define getservbyname sys_getservbyname
90 #define shutdown sys_shutdown
91 #define setsockopt sys_setsockopt
92 #define listen sys_listen
93 #define getsockname sys_getsockname
94 #define accept sys_accept
95 #define recvfrom sys_recvfrom
96 #define sendto sys_sendto
97
98 int sys_socket(int af, int type, int protocol);
99 int sys_bind (int s, const struct sockaddr *addr, int namelen);
100 int sys_connect (int s, const struct sockaddr *addr, int namelen);
101 u_short sys_htons (u_short hostshort);
102 u_short sys_ntohs (u_short netshort);
103 unsigned long sys_inet_addr (const char * cp);
104 int sys_gethostname (char * name, int namelen);
105 struct hostent * sys_gethostbyname (const char * name);
106 struct servent * sys_getservbyname (const char * name, const char * proto);
107 int sys_getpeername (int s, struct sockaddr *addr, int * namelen);
108 int sys_shutdown (int socket, int how);
109 int sys_setsockopt (int s, int level, int oname, const void * oval, int olen);
110 int sys_listen (int s, int backlog);
111 int sys_getsockname (int s, struct sockaddr * name, int * namelen);
112 int sys_accept (int s, struct sockaddr *addr, int *addrlen);
113 int sys_recvfrom (int s, char *buf, int len, int flags,
114 struct sockaddr *from, int * fromlen);
115 int sys_sendto (int s, const char * buf, int len, int flags,
116 const struct sockaddr *to, int tolen);
117
118 /* In addition to wrappers for the winsock functions, we also provide
119 an fcntl function, for setting sockets to non-blocking mode. */
120 int fcntl (int s, int cmd, int options);
121 #define F_SETFL 4
122 #define O_NONBLOCK 04000
123
124 /* we are providing a real h_errno variable */
125 #undef h_errno
126 extern int h_errno;
127
128 /* map winsock error codes to standard names */
129 #if defined(EWOULDBLOCK)
130 #undef EWOULDBLOCK
131 #endif
132 #define EWOULDBLOCK WSAEWOULDBLOCK
133 #if defined(EINPROGRESS)
134 #undef EINPROGRESS
135 #endif
136 #define EINPROGRESS WSAEINPROGRESS
137 #if defined(EALREADY)
138 #undef EALREADY
139 #endif
140 #define EALREADY WSAEALREADY
141 #if defined(ENOTSOCK)
142 #undef ENOTSOCK
143 #endif
144 #define ENOTSOCK WSAENOTSOCK
145 #if defined(EDESTADDRREQ)
146 #undef EDESTADDRREQ
147 #endif
148 #define EDESTADDRREQ WSAEDESTADDRREQ
149 #if defined(EMSGSIZE)
150 #undef EMSGSIZE
151 #endif
152 #define EMSGSIZE WSAEMSGSIZE
153 #if defined(EPROTOTYPE)
154 #undef EPROTOTYPE
155 #endif
156 #define EPROTOTYPE WSAEPROTOTYPE
157 #if defined(ENOPROTOOPT)
158 #undef ENOPROTOOPT
159 #endif
160 #define ENOPROTOOPT WSAENOPROTOOPT
161 #if defined(EPROTONOSUPPORT)
162 #undef EPROTONOSUPPORT
163 #endif
164 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
165 #if defined(ESOCKTNOSUPPORT)
166 #undef ESOCKTNOSUPPORT
167 #endif
168 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
169 #if defined(EOPNOTSUPP)
170 #undef EOPNOTSUPP
171 #endif
172 #define EOPNOTSUPP WSAEOPNOTSUPP
173 #if defined(EPFNOSUPPORT)
174 #undef EPFNOSUPPORT
175 #endif
176 #define EPFNOSUPPORT WSAEPFNOSUPPORT
177 #if defined(EAFNOSUPPORT)
178 #undef EAFNOSUPPORT
179 #endif
180 #define EAFNOSUPPORT WSAEAFNOSUPPORT
181 #if defined(EADDRINUSE)
182 #undef EADDRINUSE
183 #endif
184 #define EADDRINUSE WSAEADDRINUSE
185 #if defined(EADDRNOTAVAIL)
186 #undef EADDRNOTAVAIL
187 #endif
188 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
189 #if defined(ENETDOWN)
190 #undef ENETDOWN
191 #endif
192 #define ENETDOWN WSAENETDOWN
193 #if defined(ENETUNREACH)
194 #undef ENETUNREACH
195 #endif
196 #define ENETUNREACH WSAENETUNREACH
197 #if defined(ENETRESET)
198 #undef ENETRESET
199 #endif
200 #define ENETRESET WSAENETRESET
201 #if defined(ECONNABORTED)
202 #undef ECONNABORTED
203 #endif
204 #define ECONNABORTED WSAECONNABORTED
205 #if defined(ECONNRESET)
206 #undef ECONNRESET
207 #endif
208 #define ECONNRESET WSAECONNRESET
209 #if defined(ENOBUFS)
210 #undef ENOBUFS
211 #endif
212 #define ENOBUFS WSAENOBUFS
213 #if defined(EISCONN)
214 #undef EISCONN
215 #endif
216 #define EISCONN WSAEISCONN
217 #if defined(ENOTCONN)
218 #undef ENOTCONN
219 #endif
220 #define ENOTCONN WSAENOTCONN
221 #if defined(ESHUTDOWN)
222 #undef ESHUTDOWN
223 #endif
224 #define ESHUTDOWN WSAESHUTDOWN
225 #if defined(ETOOMANYREFS)
226 #undef ETOOMANYREFS
227 #endif
228 #define ETOOMANYREFS WSAETOOMANYREFS
229 #if defined(ETIMEDOUT)
230 #undef ETIMEDOUT
231 #endif
232 #define ETIMEDOUT WSAETIMEDOUT
233 #if defined(ECONNREFUSED)
234 #undef ECONNREFUSED
235 #endif
236 #define ECONNREFUSED WSAECONNREFUSED
237 #if defined(ELOOP)
238 #undef ELOOP
239 #endif
240 #define ELOOP WSAELOOP
241 /* #define ENAMETOOLONG WSAENAMETOOLONG */
242 #if defined(EHOSTDOWN)
243 #undef EHOSTDOWN
244 #endif
245 #define EHOSTDOWN WSAEHOSTDOWN
246 #if defined(EHOSTUNREACH)
247 #undef EHOSTUNREACH
248 #endif
249 #define EHOSTUNREACH WSAEHOSTUNREACH
250 /* #define ENOTEMPTY WSAENOTEMPTY */
251 #if defined(EPROCLIM)
252 #undef EPROCLIM
253 #endif
254 #define EPROCLIM WSAEPROCLIM
255 #if defined(EUSERS)
256 #undef EUSERS
257 #endif
258 #define EUSERS WSAEUSERS
259 #if defined(EDQUOT)
260 #undef EDQUOT
261 #endif
262 #define EDQUOT WSAEDQUOT
263 #if defined(ESTALE)
264 #undef ESTALE
265 #endif
266 #define ESTALE WSAESTALE
267 #if defined(EREMOTE)
268 #undef EREMOTE
269 #endif
270 #define EREMOTE WSAEREMOTE
271
272 #endif /* _SOCKET_H_ */
273
274 /* end of socket.h */