]>
code.delx.au - gnu-emacs/blob - nt/inc/sys/socket.h
1 /* Copyright (C) 1995, 2001-2013 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 */
48 #define timeval ws_timeval
53 /* process.c uses uint16_t (from C99) for IPv6, but
54 apparently it is not defined in some versions of mingw and msvc. */
56 typedef unsigned short uint16_t;
59 /* redefine select to reference our version */
60 #ifdef MUST_REDEF_SELECT
61 #define select sys_select
62 #undef MUST_REDEF_SELECT
65 /* revert to our version of FD_SET */
71 /* allow us to provide our own version of fd_set */
72 #define fd_set ws_fd_set
79 /* shadow functions where we provide our own wrapper */
80 #define socket sys_socket
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
88 #define getpeername sys_getpeername
89 #define getservbyname sys_getservbyname
90 #define shutdown sys_shutdown
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
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
);
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
);
108 int sys_shutdown (int socket
, int how
);
109 int sys_setsockopt (int s
, int level
, int oname
, const void * oval
, int olen
);
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
);
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
);
122 #define O_NONBLOCK 04000
124 /* we are providing a real h_errno variable */
128 /* map winsock error codes to standard names */
129 #if defined(EWOULDBLOCK)
132 #define EWOULDBLOCK WSAEWOULDBLOCK
133 #if defined(EINPROGRESS)
136 #define EINPROGRESS WSAEINPROGRESS
137 #if defined(EALREADY)
140 #define EALREADY WSAEALREADY
141 #if defined(ENOTSOCK)
144 #define ENOTSOCK WSAENOTSOCK
145 #if defined(EDESTADDRREQ)
148 #define EDESTADDRREQ WSAEDESTADDRREQ
149 #if defined(EMSGSIZE)
152 #define EMSGSIZE WSAEMSGSIZE
153 #if defined(EPROTOTYPE)
156 #define EPROTOTYPE WSAEPROTOTYPE
157 #if defined(ENOPROTOOPT)
160 #define ENOPROTOOPT WSAENOPROTOOPT
161 #if defined(EPROTONOSUPPORT)
162 #undef EPROTONOSUPPORT
164 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
165 #if defined(ESOCKTNOSUPPORT)
166 #undef ESOCKTNOSUPPORT
168 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
169 #if defined(EOPNOTSUPP)
172 #define EOPNOTSUPP WSAEOPNOTSUPP
173 #if defined(EPFNOSUPPORT)
176 #define EPFNOSUPPORT WSAEPFNOSUPPORT
177 #if defined(EAFNOSUPPORT)
180 #define EAFNOSUPPORT WSAEAFNOSUPPORT
181 #if defined(EADDRINUSE)
184 #define EADDRINUSE WSAEADDRINUSE
185 #if defined(EADDRNOTAVAIL)
188 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
189 #if defined(ENETDOWN)
192 #define ENETDOWN WSAENETDOWN
193 #if defined(ENETUNREACH)
196 #define ENETUNREACH WSAENETUNREACH
197 #if defined(ENETRESET)
200 #define ENETRESET WSAENETRESET
201 #if defined(ECONNABORTED)
204 #define ECONNABORTED WSAECONNABORTED
205 #if defined(ECONNRESET)
208 #define ECONNRESET WSAECONNRESET
212 #define ENOBUFS WSAENOBUFS
216 #define EISCONN WSAEISCONN
217 #if defined(ENOTCONN)
220 #define ENOTCONN WSAENOTCONN
221 #if defined(ESHUTDOWN)
224 #define ESHUTDOWN WSAESHUTDOWN
225 #if defined(ETOOMANYREFS)
228 #define ETOOMANYREFS WSAETOOMANYREFS
229 #if defined(ETIMEDOUT)
232 #define ETIMEDOUT WSAETIMEDOUT
233 #if defined(ECONNREFUSED)
236 #define ECONNREFUSED WSAECONNREFUSED
240 #define ELOOP WSAELOOP
241 /* #define ENAMETOOLONG WSAENAMETOOLONG */
242 #if defined(EHOSTDOWN)
245 #define EHOSTDOWN WSAEHOSTDOWN
246 #if defined(EHOSTUNREACH)
249 #define EHOSTUNREACH WSAEHOSTUNREACH
250 /* #define ENOTEMPTY WSAENOTEMPTY */
251 #if defined(EPROCLIM)
254 #define EPROCLIM WSAEPROCLIM
258 #define EUSERS WSAEUSERS
262 #define EDQUOT WSAEDQUOT
266 #define ESTALE WSAESTALE
270 #define EREMOTE WSAEREMOTE
272 #endif /* _SOCKET_H_ */
274 /* end of socket.h */