Commit | Line | Data |
---|---|---|
acaf905b | 1 | /* Copyright (C) 1995, 2001-2012 Free Software Foundation, Inc. |
41eca17b AI |
2 | |
3 | This file is part of GNU Emacs. | |
4 | ||
eef0be9e | 5 | GNU Emacs is free software: you can redistribute it and/or modify |
41eca17b | 6 | it under the terms of the GNU General Public License as published by |
eef0be9e GM |
7 | the Free Software Foundation, either version 3 of the License, or |
8 | (at your option) any later version. | |
41eca17b AI |
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 | |
eef0be9e | 16 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
41eca17b AI |
17 | |
18 | ||
c911543b GV |
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 | |
00a08ac7 AI |
28 | #ifdef _WINSOCK_H |
29 | #undef _WINSOCK_H | |
30 | #endif | |
c911543b GV |
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 | ||
c911543b GV |
46 | /* avoid duplicate definition of timeval */ |
47 | #ifdef HAVE_TIMEVAL | |
48 | #define timeval ws_timeval | |
49 | #endif | |
50 | ||
a2dcccd9 JR |
51 | #include <winsock2.h> |
52 | #include <ws2tcpip.h> | |
bfbe85fc JR |
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 | |
c911543b GV |
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 | |
00a08ac7 AI |
70 | |
71 | /* allow us to provide our own version of fd_set */ | |
72 | #define fd_set ws_fd_set | |
6219f8bf | 73 | #include "w32.h" |
c911543b GV |
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 | |
6b99b0a8 | 88 | #define getpeername sys_getpeername |
c911543b | 89 | #define getservbyname sys_getservbyname |
86b9a6a9 | 90 | #define shutdown sys_shutdown |
ef2cd596 JR |
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 | |
c911543b GV |
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); | |
6b99b0a8 JR |
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); | |
86b9a6a9 | 108 | int sys_shutdown (int socket, int how); |
727dcb1c | 109 | int sys_setsockopt (int s, int level, int oname, const void * oval, int olen); |
ef2cd596 JR |
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); | |
c911543b | 117 | |
6b99b0a8 JR |
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_NDELAY 04000 | |
123 | ||
c911543b GV |
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 */ | |
62aba0d4 FP |
129 | #if defined(EWOULDBLOCK) |
130 | #undef EWOULDBLOCK | |
131 | #endif | |
c911543b | 132 | #define EWOULDBLOCK WSAEWOULDBLOCK |
62aba0d4 FP |
133 | #if defined(EINPROGRESS) |
134 | #undef EINPROGRESS | |
135 | #endif | |
c911543b | 136 | #define EINPROGRESS WSAEINPROGRESS |
62aba0d4 FP |
137 | #if defined(EALREADY) |
138 | #undef EALREADY | |
139 | #endif | |
c911543b | 140 | #define EALREADY WSAEALREADY |
62aba0d4 FP |
141 | #if defined(ENOTSOCK) |
142 | #undef ENOTSOCK | |
143 | #endif | |
c911543b | 144 | #define ENOTSOCK WSAENOTSOCK |
62aba0d4 FP |
145 | #if defined(EDESTADDRREQ) |
146 | #undef EDESTADDRREQ | |
147 | #endif | |
c911543b | 148 | #define EDESTADDRREQ WSAEDESTADDRREQ |
62aba0d4 FP |
149 | #if defined(EMSGSIZE) |
150 | #undef EMSGSIZE | |
151 | #endif | |
c911543b | 152 | #define EMSGSIZE WSAEMSGSIZE |
62aba0d4 FP |
153 | #if defined(EPROTOTYPE) |
154 | #undef EPROTOTYPE | |
155 | #endif | |
c911543b | 156 | #define EPROTOTYPE WSAEPROTOTYPE |
62aba0d4 FP |
157 | #if defined(ENOPROTOOPT) |
158 | #undef ENOPROTOOPT | |
159 | #endif | |
c911543b | 160 | #define ENOPROTOOPT WSAENOPROTOOPT |
62aba0d4 FP |
161 | #if defined(EPROTONOSUPPORT) |
162 | #undef EPROTONOSUPPORT | |
163 | #endif | |
c911543b | 164 | #define EPROTONOSUPPORT WSAEPROTONOSUPPORT |
62aba0d4 FP |
165 | #if defined(ESOCKTNOSUPPORT) |
166 | #undef ESOCKTNOSUPPORT | |
167 | #endif | |
c911543b | 168 | #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT |
62aba0d4 FP |
169 | #if defined(EOPNOTSUPP) |
170 | #undef EOPNOTSUPP | |
171 | #endif | |
c911543b | 172 | #define EOPNOTSUPP WSAEOPNOTSUPP |
62aba0d4 FP |
173 | #if defined(EPFNOSUPPORT) |
174 | #undef EPFNOSUPPORT | |
175 | #endif | |
c911543b | 176 | #define EPFNOSUPPORT WSAEPFNOSUPPORT |
62aba0d4 FP |
177 | #if defined(EAFNOSUPPORT) |
178 | #undef EAFNOSUPPORT | |
179 | #endif | |
c911543b | 180 | #define EAFNOSUPPORT WSAEAFNOSUPPORT |
62aba0d4 FP |
181 | #if defined(EADDRINUSE) |
182 | #undef EADDRINUSE | |
183 | #endif | |
c911543b | 184 | #define EADDRINUSE WSAEADDRINUSE |
62aba0d4 FP |
185 | #if defined(EADDRNOTAVAIL) |
186 | #undef EADDRNOTAVAIL | |
187 | #endif | |
c911543b | 188 | #define EADDRNOTAVAIL WSAEADDRNOTAVAIL |
62aba0d4 FP |
189 | #if defined(ENETDOWN) |
190 | #undef ENETDOWN | |
191 | #endif | |
c911543b | 192 | #define ENETDOWN WSAENETDOWN |
62aba0d4 FP |
193 | #if defined(ENETUNREACH) |
194 | #undef ENETUNREACH | |
195 | #endif | |
c911543b | 196 | #define ENETUNREACH WSAENETUNREACH |
62aba0d4 FP |
197 | #if defined(ENETRESET) |
198 | #undef ENETRESET | |
199 | #endif | |
c911543b | 200 | #define ENETRESET WSAENETRESET |
62aba0d4 FP |
201 | #if defined(ECONNABORTED) |
202 | #undef ECONNABORTED | |
203 | #endif | |
c911543b | 204 | #define ECONNABORTED WSAECONNABORTED |
62aba0d4 FP |
205 | #if defined(ECONNRESET) |
206 | #undef ECONNRESET | |
207 | #endif | |
c911543b | 208 | #define ECONNRESET WSAECONNRESET |
62aba0d4 FP |
209 | #if defined(ENOBUFS) |
210 | #undef ENOBUFS | |
211 | #endif | |
c911543b | 212 | #define ENOBUFS WSAENOBUFS |
62aba0d4 FP |
213 | #if defined(EISCONN) |
214 | #undef EISCONN | |
215 | #endif | |
c911543b | 216 | #define EISCONN WSAEISCONN |
62aba0d4 FP |
217 | #if defined(ENOTCONN) |
218 | #undef ENOTCONN | |
219 | #endif | |
c911543b | 220 | #define ENOTCONN WSAENOTCONN |
62aba0d4 FP |
221 | #if defined(ESHUTDOWN) |
222 | #undef ESHUTDOWN | |
223 | #endif | |
c911543b | 224 | #define ESHUTDOWN WSAESHUTDOWN |
62aba0d4 FP |
225 | #if defined(ETOOMANYREFS) |
226 | #undef ETOOMANYREFS | |
227 | #endif | |
c911543b | 228 | #define ETOOMANYREFS WSAETOOMANYREFS |
62aba0d4 FP |
229 | #if defined(ETIMEDOUT) |
230 | #undef ETIMEDOUT | |
231 | #endif | |
c911543b | 232 | #define ETIMEDOUT WSAETIMEDOUT |
62aba0d4 FP |
233 | #if defined(ECONNREFUSED) |
234 | #undef ECONNREFUSED | |
235 | #endif | |
c911543b | 236 | #define ECONNREFUSED WSAECONNREFUSED |
62aba0d4 FP |
237 | #if defined(ELOOP) |
238 | #undef ELOOP | |
239 | #endif | |
c911543b GV |
240 | #define ELOOP WSAELOOP |
241 | /* #define ENAMETOOLONG WSAENAMETOOLONG */ | |
62aba0d4 FP |
242 | #if defined(EHOSTDOWN) |
243 | #undef EHOSTDOWN | |
244 | #endif | |
c911543b | 245 | #define EHOSTDOWN WSAEHOSTDOWN |
62aba0d4 FP |
246 | #if defined(EHOSTUNREACH) |
247 | #undef EHOSTUNREACH | |
248 | #endif | |
c911543b GV |
249 | #define EHOSTUNREACH WSAEHOSTUNREACH |
250 | /* #define ENOTEMPTY WSAENOTEMPTY */ | |
62aba0d4 FP |
251 | #if defined(EPROCLIM) |
252 | #undef EPROCLIM | |
253 | #endif | |
c911543b | 254 | #define EPROCLIM WSAEPROCLIM |
62aba0d4 FP |
255 | #if defined(EUSERS) |
256 | #undef EUSERS | |
257 | #endif | |
c911543b | 258 | #define EUSERS WSAEUSERS |
62aba0d4 FP |
259 | #if defined(EDQUOT) |
260 | #undef EDQUOT | |
261 | #endif | |
c911543b | 262 | #define EDQUOT WSAEDQUOT |
62aba0d4 FP |
263 | #if defined(ESTALE) |
264 | #undef ESTALE | |
265 | #endif | |
c911543b | 266 | #define ESTALE WSAESTALE |
62aba0d4 FP |
267 | #if defined(EREMOTE) |
268 | #undef EREMOTE | |
269 | #endif | |
c911543b GV |
270 | #define EREMOTE WSAEREMOTE |
271 | ||
272 | #endif /* _SOCKET_H_ */ | |
273 | ||
274 | /* end of socket.h */ |