Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / nt / inc / sys / socket.h
blob4800739d9c1d63ccc297cfb63a3ffff736ff51c8
1 /* Copyright (C) 1995, 2001-2014 Free Software Foundation, Inc.
3 This file is part of GNU Emacs.
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.
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.
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/>. */
19 /* Workable version of <sys/socket.h> based on winsock.h */
21 #ifndef _SOCKET_H_
22 #define _SOCKET_H_
24 /* defeat the multiple include protection */
25 #ifdef _WINSOCKAPI_
26 #undef _WINSOCKAPI_
27 #endif
28 #ifdef _WINSOCK_H
29 #undef _WINSOCK_H
30 #endif
32 /* avoid confusion with our version of select */
33 #ifdef select
34 #undef select
35 #define MUST_REDEF_SELECT
36 #endif
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
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
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
60 /* redefine select to reference our version */
61 #ifdef MUST_REDEF_SELECT
62 #define select sys_select
63 #undef MUST_REDEF_SELECT
64 #endif
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
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 */
79 #if defined (HAVE_TIMEVAL) && defined (_MSC_VER)
80 #undef timeval
81 #endif
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
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);
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 F_SETFD 2
127 #define O_NONBLOCK 04000
128 #define O_CLOEXEC O_NOINHERIT
129 #define F_DUPFD_CLOEXEC 0x40000000
130 #define FD_CLOEXEC 1
132 /* we are providing a real h_errno variable */
133 #undef h_errno
134 extern int h_errno;
136 /* map winsock error codes to standard names */
137 #if defined(EWOULDBLOCK)
138 #undef EWOULDBLOCK
139 #endif
140 #define EWOULDBLOCK WSAEWOULDBLOCK
141 #if defined(EINPROGRESS)
142 #undef EINPROGRESS
143 #endif
144 #define EINPROGRESS WSAEINPROGRESS
145 #if defined(EALREADY)
146 #undef EALREADY
147 #endif
148 #define EALREADY WSAEALREADY
149 #if defined(ENOTSOCK)
150 #undef ENOTSOCK
151 #endif
152 #define ENOTSOCK WSAENOTSOCK
153 #if defined(EDESTADDRREQ)
154 #undef EDESTADDRREQ
155 #endif
156 #define EDESTADDRREQ WSAEDESTADDRREQ
157 #if defined(EMSGSIZE)
158 #undef EMSGSIZE
159 #endif
160 #define EMSGSIZE WSAEMSGSIZE
161 #if defined(EPROTOTYPE)
162 #undef EPROTOTYPE
163 #endif
164 #define EPROTOTYPE WSAEPROTOTYPE
165 #if defined(ENOPROTOOPT)
166 #undef ENOPROTOOPT
167 #endif
168 #define ENOPROTOOPT WSAENOPROTOOPT
169 #if defined(EPROTONOSUPPORT)
170 #undef EPROTONOSUPPORT
171 #endif
172 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
173 #if defined(ESOCKTNOSUPPORT)
174 #undef ESOCKTNOSUPPORT
175 #endif
176 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
177 #if defined(EOPNOTSUPP)
178 #undef EOPNOTSUPP
179 #endif
180 #define EOPNOTSUPP WSAEOPNOTSUPP
181 #if defined(EPFNOSUPPORT)
182 #undef EPFNOSUPPORT
183 #endif
184 #define EPFNOSUPPORT WSAEPFNOSUPPORT
185 #if defined(EAFNOSUPPORT)
186 #undef EAFNOSUPPORT
187 #endif
188 #define EAFNOSUPPORT WSAEAFNOSUPPORT
189 #if defined(EADDRINUSE)
190 #undef EADDRINUSE
191 #endif
192 #define EADDRINUSE WSAEADDRINUSE
193 #if defined(EADDRNOTAVAIL)
194 #undef EADDRNOTAVAIL
195 #endif
196 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
197 #if defined(ENETDOWN)
198 #undef ENETDOWN
199 #endif
200 #define ENETDOWN WSAENETDOWN
201 #if defined(ENETUNREACH)
202 #undef ENETUNREACH
203 #endif
204 #define ENETUNREACH WSAENETUNREACH
205 #if defined(ENETRESET)
206 #undef ENETRESET
207 #endif
208 #define ENETRESET WSAENETRESET
209 #if defined(ECONNABORTED)
210 #undef ECONNABORTED
211 #endif
212 #define ECONNABORTED WSAECONNABORTED
213 #if defined(ECONNRESET)
214 #undef ECONNRESET
215 #endif
216 #define ECONNRESET WSAECONNRESET
217 #if defined(ENOBUFS)
218 #undef ENOBUFS
219 #endif
220 #define ENOBUFS WSAENOBUFS
221 #if defined(EISCONN)
222 #undef EISCONN
223 #endif
224 #define EISCONN WSAEISCONN
225 #if defined(ENOTCONN)
226 #undef ENOTCONN
227 #endif
228 #define ENOTCONN WSAENOTCONN
229 #if defined(ESHUTDOWN)
230 #undef ESHUTDOWN
231 #endif
232 #define ESHUTDOWN WSAESHUTDOWN
233 #if defined(ETOOMANYREFS)
234 #undef ETOOMANYREFS
235 #endif
236 #define ETOOMANYREFS WSAETOOMANYREFS
237 #if defined(ETIMEDOUT)
238 #undef ETIMEDOUT
239 #endif
240 #define ETIMEDOUT WSAETIMEDOUT
241 #if defined(ECONNREFUSED)
242 #undef ECONNREFUSED
243 #endif
244 #define ECONNREFUSED WSAECONNREFUSED
245 #if defined(ELOOP)
246 #undef ELOOP
247 #endif
248 #define ELOOP WSAELOOP
249 /* #define ENAMETOOLONG WSAENAMETOOLONG */
250 #if defined(EHOSTDOWN)
251 #undef EHOSTDOWN
252 #endif
253 #define EHOSTDOWN WSAEHOSTDOWN
254 #if defined(EHOSTUNREACH)
255 #undef EHOSTUNREACH
256 #endif
257 #define EHOSTUNREACH WSAEHOSTUNREACH
258 /* #define ENOTEMPTY WSAENOTEMPTY */
259 #if defined(EPROCLIM)
260 #undef EPROCLIM
261 #endif
262 #define EPROCLIM WSAEPROCLIM
263 #if defined(EUSERS)
264 #undef EUSERS
265 #endif
266 #define EUSERS WSAEUSERS
267 #if defined(EDQUOT)
268 #undef EDQUOT
269 #endif
270 #define EDQUOT WSAEDQUOT
271 #if defined(ESTALE)
272 #undef ESTALE
273 #endif
274 #define ESTALE WSAESTALE
275 #if defined(EREMOTE)
276 #undef EREMOTE
277 #endif
278 #define EREMOTE WSAEREMOTE
280 #endif /* _SOCKET_H_ */
282 /* end of socket.h */