]> code.delx.au - gnu-emacs/blob - nt/inc/sys/socket.h
Support building Emacs on MS-Windows using the Posix configury.
[gnu-emacs] / 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. 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
102 int sys_socket(int af, int type, int protocol);
103 int sys_bind (int s, const struct sockaddr *addr, int namelen);
104 int sys_connect (int s, const struct sockaddr *addr, int namelen);
105 u_short sys_htons (u_short hostshort);
106 u_short sys_ntohs (u_short netshort);
107 unsigned long sys_inet_addr (const char * cp);
108 int sys_gethostname (char * name, int namelen);
109 struct hostent * sys_gethostbyname (const char * name);
110 struct servent * sys_getservbyname (const char * name, const char * proto);
111 int sys_getpeername (int s, struct sockaddr *addr, int * namelen);
112 int sys_shutdown (int socket, int how);
113 int sys_setsockopt (int s, int level, int oname, const void * oval, int olen);
114 int sys_listen (int s, int backlog);
115 int sys_getsockname (int s, struct sockaddr * name, int * namelen);
116 int sys_accept (int s, struct sockaddr *addr, int *addrlen);
117 int sys_recvfrom (int s, char *buf, int len, int flags,
118 struct sockaddr *from, int * fromlen);
119 int sys_sendto (int s, const char * buf, int len, int flags,
120 const struct sockaddr *to, int tolen);
121
122 /* In addition to wrappers for the winsock functions, we also provide
123 an fcntl function, for setting sockets to non-blocking mode. */
124 int fcntl (int s, int cmd, int options);
125 #define F_SETFL 4
126 #define O_NONBLOCK 04000
127
128 /* we are providing a real h_errno variable */
129 #undef h_errno
130 extern int h_errno;
131
132 /* map winsock error codes to standard names */
133 #if defined(EWOULDBLOCK)
134 #undef EWOULDBLOCK
135 #endif
136 #define EWOULDBLOCK WSAEWOULDBLOCK
137 #if defined(EINPROGRESS)
138 #undef EINPROGRESS
139 #endif
140 #define EINPROGRESS WSAEINPROGRESS
141 #if defined(EALREADY)
142 #undef EALREADY
143 #endif
144 #define EALREADY WSAEALREADY
145 #if defined(ENOTSOCK)
146 #undef ENOTSOCK
147 #endif
148 #define ENOTSOCK WSAENOTSOCK
149 #if defined(EDESTADDRREQ)
150 #undef EDESTADDRREQ
151 #endif
152 #define EDESTADDRREQ WSAEDESTADDRREQ
153 #if defined(EMSGSIZE)
154 #undef EMSGSIZE
155 #endif
156 #define EMSGSIZE WSAEMSGSIZE
157 #if defined(EPROTOTYPE)
158 #undef EPROTOTYPE
159 #endif
160 #define EPROTOTYPE WSAEPROTOTYPE
161 #if defined(ENOPROTOOPT)
162 #undef ENOPROTOOPT
163 #endif
164 #define ENOPROTOOPT WSAENOPROTOOPT
165 #if defined(EPROTONOSUPPORT)
166 #undef EPROTONOSUPPORT
167 #endif
168 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
169 #if defined(ESOCKTNOSUPPORT)
170 #undef ESOCKTNOSUPPORT
171 #endif
172 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
173 #if defined(EOPNOTSUPP)
174 #undef EOPNOTSUPP
175 #endif
176 #define EOPNOTSUPP WSAEOPNOTSUPP
177 #if defined(EPFNOSUPPORT)
178 #undef EPFNOSUPPORT
179 #endif
180 #define EPFNOSUPPORT WSAEPFNOSUPPORT
181 #if defined(EAFNOSUPPORT)
182 #undef EAFNOSUPPORT
183 #endif
184 #define EAFNOSUPPORT WSAEAFNOSUPPORT
185 #if defined(EADDRINUSE)
186 #undef EADDRINUSE
187 #endif
188 #define EADDRINUSE WSAEADDRINUSE
189 #if defined(EADDRNOTAVAIL)
190 #undef EADDRNOTAVAIL
191 #endif
192 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
193 #if defined(ENETDOWN)
194 #undef ENETDOWN
195 #endif
196 #define ENETDOWN WSAENETDOWN
197 #if defined(ENETUNREACH)
198 #undef ENETUNREACH
199 #endif
200 #define ENETUNREACH WSAENETUNREACH
201 #if defined(ENETRESET)
202 #undef ENETRESET
203 #endif
204 #define ENETRESET WSAENETRESET
205 #if defined(ECONNABORTED)
206 #undef ECONNABORTED
207 #endif
208 #define ECONNABORTED WSAECONNABORTED
209 #if defined(ECONNRESET)
210 #undef ECONNRESET
211 #endif
212 #define ECONNRESET WSAECONNRESET
213 #if defined(ENOBUFS)
214 #undef ENOBUFS
215 #endif
216 #define ENOBUFS WSAENOBUFS
217 #if defined(EISCONN)
218 #undef EISCONN
219 #endif
220 #define EISCONN WSAEISCONN
221 #if defined(ENOTCONN)
222 #undef ENOTCONN
223 #endif
224 #define ENOTCONN WSAENOTCONN
225 #if defined(ESHUTDOWN)
226 #undef ESHUTDOWN
227 #endif
228 #define ESHUTDOWN WSAESHUTDOWN
229 #if defined(ETOOMANYREFS)
230 #undef ETOOMANYREFS
231 #endif
232 #define ETOOMANYREFS WSAETOOMANYREFS
233 #if defined(ETIMEDOUT)
234 #undef ETIMEDOUT
235 #endif
236 #define ETIMEDOUT WSAETIMEDOUT
237 #if defined(ECONNREFUSED)
238 #undef ECONNREFUSED
239 #endif
240 #define ECONNREFUSED WSAECONNREFUSED
241 #if defined(ELOOP)
242 #undef ELOOP
243 #endif
244 #define ELOOP WSAELOOP
245 /* #define ENAMETOOLONG WSAENAMETOOLONG */
246 #if defined(EHOSTDOWN)
247 #undef EHOSTDOWN
248 #endif
249 #define EHOSTDOWN WSAEHOSTDOWN
250 #if defined(EHOSTUNREACH)
251 #undef EHOSTUNREACH
252 #endif
253 #define EHOSTUNREACH WSAEHOSTUNREACH
254 /* #define ENOTEMPTY WSAENOTEMPTY */
255 #if defined(EPROCLIM)
256 #undef EPROCLIM
257 #endif
258 #define EPROCLIM WSAEPROCLIM
259 #if defined(EUSERS)
260 #undef EUSERS
261 #endif
262 #define EUSERS WSAEUSERS
263 #if defined(EDQUOT)
264 #undef EDQUOT
265 #endif
266 #define EDQUOT WSAEDQUOT
267 #if defined(ESTALE)
268 #undef ESTALE
269 #endif
270 #define ESTALE WSAESTALE
271 #if defined(EREMOTE)
272 #undef EREMOTE
273 #endif
274 #define EREMOTE WSAEREMOTE
275
276 #endif /* _SOCKET_H_ */
277
278 /* end of socket.h */