1 /* Copyright (C) 1995, 2001-2015 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 */
24 /* defeat the multiple include protection */
32 /* avoid confusion with our version of select */
35 #define MUST_REDEF_SELECT
38 /* avoid clashing with our version of FD_SET if already defined */
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
54 /* process.c uses uint16_t (from C99) for IPv6, but
55 apparently it is not defined in some versions of mingw and msvc. */
57 typedef unsigned short uint16_t;
60 /* redefine select to reference our version */
61 #ifdef MUST_REDEF_SELECT
62 #define select sys_select
63 #undef MUST_REDEF_SELECT
66 /* Revert to our version of FD_SET, but not when included from test
67 programs run by configure. */
74 /* allow us to provide our own version of fd_set */
75 #define fd_set ws_fd_set
77 #endif /* EMACS_CONFIG_H */
79 #if defined (HAVE_TIMEVAL) && defined (_MSC_VER)
83 /* shadow functions where we provide our own wrapper */
84 #define socket sys_socket
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
);
127 #define O_NONBLOCK 04000
128 #define O_CLOEXEC O_NOINHERIT
129 #define F_DUPFD_CLOEXEC 0x40000000
132 /* we are providing a real h_errno variable */
136 /* map winsock error codes to standard names */
137 #if defined(EWOULDBLOCK)
140 #define EWOULDBLOCK WSAEWOULDBLOCK
141 #if defined(EINPROGRESS)
144 #define EINPROGRESS WSAEINPROGRESS
145 #if defined(EALREADY)
148 #define EALREADY WSAEALREADY
149 #if defined(ENOTSOCK)
152 #define ENOTSOCK WSAENOTSOCK
153 #if defined(EDESTADDRREQ)
156 #define EDESTADDRREQ WSAEDESTADDRREQ
157 #if defined(EMSGSIZE)
160 #define EMSGSIZE WSAEMSGSIZE
161 #if defined(EPROTOTYPE)
164 #define EPROTOTYPE WSAEPROTOTYPE
165 #if defined(ENOPROTOOPT)
168 #define ENOPROTOOPT WSAENOPROTOOPT
169 #if defined(EPROTONOSUPPORT)
170 #undef EPROTONOSUPPORT
172 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
173 #if defined(ESOCKTNOSUPPORT)
174 #undef ESOCKTNOSUPPORT
176 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
177 #if defined(EOPNOTSUPP)
180 #define EOPNOTSUPP WSAEOPNOTSUPP
181 #if defined(EPFNOSUPPORT)
184 #define EPFNOSUPPORT WSAEPFNOSUPPORT
185 #if defined(EAFNOSUPPORT)
188 #define EAFNOSUPPORT WSAEAFNOSUPPORT
189 #if defined(EADDRINUSE)
192 #define EADDRINUSE WSAEADDRINUSE
193 #if defined(EADDRNOTAVAIL)
196 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
197 #if defined(ENETDOWN)
200 #define ENETDOWN WSAENETDOWN
201 #if defined(ENETUNREACH)
204 #define ENETUNREACH WSAENETUNREACH
205 #if defined(ENETRESET)
208 #define ENETRESET WSAENETRESET
209 #if defined(ECONNABORTED)
212 #define ECONNABORTED WSAECONNABORTED
213 #if defined(ECONNRESET)
216 #define ECONNRESET WSAECONNRESET
220 #define ENOBUFS WSAENOBUFS
224 #define EISCONN WSAEISCONN
225 #if defined(ENOTCONN)
228 #define ENOTCONN WSAENOTCONN
229 #if defined(ESHUTDOWN)
232 #define ESHUTDOWN WSAESHUTDOWN
233 #if defined(ETOOMANYREFS)
236 #define ETOOMANYREFS WSAETOOMANYREFS
237 #if defined(ETIMEDOUT)
240 #define ETIMEDOUT WSAETIMEDOUT
241 #if defined(ECONNREFUSED)
244 #define ECONNREFUSED WSAECONNREFUSED
248 #define ELOOP WSAELOOP
249 /* #define ENAMETOOLONG WSAENAMETOOLONG */
250 #if defined(EHOSTDOWN)
253 #define EHOSTDOWN WSAEHOSTDOWN
254 #if defined(EHOSTUNREACH)
257 #define EHOSTUNREACH WSAEHOSTUNREACH
258 /* #define ENOTEMPTY WSAENOTEMPTY */
259 #if defined(EPROCLIM)
262 #define EPROCLIM WSAEPROCLIM
266 #define EUSERS WSAEUSERS
270 #define EDQUOT WSAEDQUOT
274 #define ESTALE WSAESTALE
278 #define EREMOTE WSAEREMOTE
280 #endif /* _SOCKET_H_ */
282 /* end of socket.h */