]> code.delx.au - gnu-emacs/blob - nt/inc/sys/socket.h
Merge from origin/emacs-25
[gnu-emacs] / nt / inc / sys / socket.h
1 /* Copyright (C) 1995, 2001-2016 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 (at
8 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. MinGW uses _TIMEVAL_DEFINED
47 in sys/time.h to avoid that. */
48 #if defined (HAVE_TIMEVAL) && defined (_MSC_VER)
49 #define timeval ws_timeval
50 #endif
51
52 #include <winsock2.h>
53 #include <ws2tcpip.h>
54 /* process.c uses uint16_t (from C99) for IPv6, but
55 apparently it is not defined in some versions of mingw and msvc. */
56 #ifndef UINT16_C
57 typedef unsigned short uint16_t;
58 #endif
59
60 /* redefine select to reference our version */
61 #ifdef MUST_REDEF_SELECT
62 #define select sys_select
63 #undef MUST_REDEF_SELECT
64 #endif
65
66 /* Revert to our version of FD_SET, but not when included from test
67 programs run by configure. */
68 #ifdef EMACS_CONFIG_H
69 #undef FD_SET
70 #undef FD_CLR
71 #undef FD_ISSET
72 #undef FD_ZERO
73
74 /* allow us to provide our own version of fd_set */
75 #define fd_set ws_fd_set
76 #include "w32.h"
77 #endif /* EMACS_CONFIG_H */
78
79 #if defined (HAVE_TIMEVAL) && defined (_MSC_VER)
80 #undef timeval
81 #endif
82
83 /* shadow functions where we provide our own wrapper */
84 #define socket sys_socket
85 #define bind sys_bind
86 #define connect sys_connect
87 #define htons sys_htons
88 #define ntohs sys_ntohs
89 #define inet_addr sys_inet_addr
90 #define gethostname sys_gethostname
91 #define gethostbyname sys_gethostbyname
92 #define getpeername sys_getpeername
93 #define getservbyname sys_getservbyname
94 #define shutdown sys_shutdown
95 #define setsockopt sys_setsockopt
96 #define listen sys_listen
97 #define getsockname sys_getsockname
98 #define accept sys_accept
99 #define recvfrom sys_recvfrom
100 #define sendto sys_sendto
101 #define getaddrinfo sys_getaddrinfo
102 #define freeaddrinfo sys_freeaddrinfo
103
104 int sys_socket(int af, int type, int protocol);
105 int sys_bind (int s, const struct sockaddr *addr, int namelen);
106 int sys_connect (int s, const struct sockaddr *addr, int namelen);
107 u_short sys_htons (u_short hostshort);
108 u_short sys_ntohs (u_short netshort);
109 unsigned long sys_inet_addr (const char * cp);
110 int sys_gethostname (char * name, int namelen);
111 struct hostent * sys_gethostbyname (const char * name);
112 struct servent * sys_getservbyname (const char * name, const char * proto);
113 int sys_getpeername (int s, struct sockaddr *addr, int * namelen);
114 int sys_shutdown (int socket, int how);
115 int sys_setsockopt (int s, int level, int oname, const void * oval, int olen);
116 int sys_listen (int s, int backlog);
117 int sys_getsockname (int s, struct sockaddr * name, int * namelen);
118 int sys_accept (int s, struct sockaddr *addr, int *addrlen);
119 int sys_recvfrom (int s, char *buf, int len, int flags,
120 struct sockaddr *from, int * fromlen);
121 int sys_sendto (int s, const char * buf, int len, int flags,
122 const struct sockaddr *to, int tolen);
123 int sys_getaddrinfo (const char * node, const char * service,
124 const struct addrinfo * hints, struct addrinfo ** res);
125 void sys_freeaddrinfo (struct addrinfo * ai);
126
127 /* In addition to wrappers for the winsock functions, we also provide
128 an fcntl function, for setting sockets to non-blocking mode. */
129 int fcntl (int s, int cmd, int options);
130 #define F_SETFL 4
131 #define F_SETFD 2
132 #define O_NONBLOCK 04000
133 #define O_CLOEXEC O_NOINHERIT
134 #define F_DUPFD_CLOEXEC 0x40000000
135 #define FD_CLOEXEC 1
136
137 /* we are providing a real h_errno variable */
138 #undef h_errno
139 extern int h_errno;
140
141 /* map winsock error codes to standard names */
142 #if defined(EWOULDBLOCK)
143 #undef EWOULDBLOCK
144 #endif
145 #define EWOULDBLOCK WSAEWOULDBLOCK
146 #if defined(EINPROGRESS)
147 #undef EINPROGRESS
148 #endif
149 #define EINPROGRESS WSAEINPROGRESS
150 #if defined(EALREADY)
151 #undef EALREADY
152 #endif
153 #define EALREADY WSAEALREADY
154 #if defined(ENOTSOCK)
155 #undef ENOTSOCK
156 #endif
157 #define ENOTSOCK WSAENOTSOCK
158 #if defined(EDESTADDRREQ)
159 #undef EDESTADDRREQ
160 #endif
161 #define EDESTADDRREQ WSAEDESTADDRREQ
162 #if defined(EMSGSIZE)
163 #undef EMSGSIZE
164 #endif
165 #define EMSGSIZE WSAEMSGSIZE
166 #if defined(EPROTOTYPE)
167 #undef EPROTOTYPE
168 #endif
169 #define EPROTOTYPE WSAEPROTOTYPE
170 #if defined(ENOPROTOOPT)
171 #undef ENOPROTOOPT
172 #endif
173 #define ENOPROTOOPT WSAENOPROTOOPT
174 #if defined(EPROTONOSUPPORT)
175 #undef EPROTONOSUPPORT
176 #endif
177 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
178 #if defined(ESOCKTNOSUPPORT)
179 #undef ESOCKTNOSUPPORT
180 #endif
181 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
182 #if defined(EOPNOTSUPP)
183 #undef EOPNOTSUPP
184 #endif
185 #define EOPNOTSUPP WSAEOPNOTSUPP
186 #if defined(EPFNOSUPPORT)
187 #undef EPFNOSUPPORT
188 #endif
189 #define EPFNOSUPPORT WSAEPFNOSUPPORT
190 #if defined(EAFNOSUPPORT)
191 #undef EAFNOSUPPORT
192 #endif
193 #define EAFNOSUPPORT WSAEAFNOSUPPORT
194 #if defined(EADDRINUSE)
195 #undef EADDRINUSE
196 #endif
197 #define EADDRINUSE WSAEADDRINUSE
198 #if defined(EADDRNOTAVAIL)
199 #undef EADDRNOTAVAIL
200 #endif
201 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
202 #if defined(ENETDOWN)
203 #undef ENETDOWN
204 #endif
205 #define ENETDOWN WSAENETDOWN
206 #if defined(ENETUNREACH)
207 #undef ENETUNREACH
208 #endif
209 #define ENETUNREACH WSAENETUNREACH
210 #if defined(ENETRESET)
211 #undef ENETRESET
212 #endif
213 #define ENETRESET WSAENETRESET
214 #if defined(ECONNABORTED)
215 #undef ECONNABORTED
216 #endif
217 #define ECONNABORTED WSAECONNABORTED
218 #if defined(ECONNRESET)
219 #undef ECONNRESET
220 #endif
221 #define ECONNRESET WSAECONNRESET
222 #if defined(ENOBUFS)
223 #undef ENOBUFS
224 #endif
225 #define ENOBUFS WSAENOBUFS
226 #if defined(EISCONN)
227 #undef EISCONN
228 #endif
229 #define EISCONN WSAEISCONN
230 #if defined(ENOTCONN)
231 #undef ENOTCONN
232 #endif
233 #define ENOTCONN WSAENOTCONN
234 #if defined(ESHUTDOWN)
235 #undef ESHUTDOWN
236 #endif
237 #define ESHUTDOWN WSAESHUTDOWN
238 #if defined(ETOOMANYREFS)
239 #undef ETOOMANYREFS
240 #endif
241 #define ETOOMANYREFS WSAETOOMANYREFS
242 #if defined(ETIMEDOUT)
243 #undef ETIMEDOUT
244 #endif
245 #define ETIMEDOUT WSAETIMEDOUT
246 #if defined(ECONNREFUSED)
247 #undef ECONNREFUSED
248 #endif
249 #define ECONNREFUSED WSAECONNREFUSED
250 #if defined(ELOOP)
251 #undef ELOOP
252 #endif
253 #define ELOOP WSAELOOP
254 /* #define ENAMETOOLONG WSAENAMETOOLONG */
255 #if defined(EHOSTDOWN)
256 #undef EHOSTDOWN
257 #endif
258 #define EHOSTDOWN WSAEHOSTDOWN
259 #if defined(EHOSTUNREACH)
260 #undef EHOSTUNREACH
261 #endif
262 #define EHOSTUNREACH WSAEHOSTUNREACH
263 /* #define ENOTEMPTY WSAENOTEMPTY */
264 #if defined(EPROCLIM)
265 #undef EPROCLIM
266 #endif
267 #define EPROCLIM WSAEPROCLIM
268 #if defined(EUSERS)
269 #undef EUSERS
270 #endif
271 #define EUSERS WSAEUSERS
272 #if defined(EDQUOT)
273 #undef EDQUOT
274 #endif
275 #define EDQUOT WSAEDQUOT
276 #if defined(ESTALE)
277 #undef ESTALE
278 #endif
279 #define ESTALE WSAESTALE
280 #if defined(EREMOTE)
281 #undef EREMOTE
282 #endif
283 #define EREMOTE WSAEREMOTE
284
285 #endif /* _SOCKET_H_ */
286
287 /* end of socket.h */