Merge from emacs-23; up to 2010-05-28T19:18:47Z!juri@jurta.org.
[bpt/emacs.git] / nt / inc / sys / socket.h
1 /* Copyright (C) 1995, 2001-2011 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 */
47 #ifdef HAVE_TIMEVAL
48 #define timeval ws_timeval
49 #endif
50
51 #include <winsock2.h>
52 #include <ws2tcpip.h>
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
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
70
71 /* allow us to provide our own version of fd_set */
72 #define fd_set ws_fd_set
73 #include "w32.h"
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
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
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);
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);
117
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
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 */
129 #define EWOULDBLOCK WSAEWOULDBLOCK
130 #define EINPROGRESS WSAEINPROGRESS
131 #define EALREADY WSAEALREADY
132 #define ENOTSOCK WSAENOTSOCK
133 #define EDESTADDRREQ WSAEDESTADDRREQ
134 #define EMSGSIZE WSAEMSGSIZE
135 #define EPROTOTYPE WSAEPROTOTYPE
136 #define ENOPROTOOPT WSAENOPROTOOPT
137 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
138 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
139 #define EOPNOTSUPP WSAEOPNOTSUPP
140 #define EPFNOSUPPORT WSAEPFNOSUPPORT
141 #define EAFNOSUPPORT WSAEAFNOSUPPORT
142 #define EADDRINUSE WSAEADDRINUSE
143 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
144 #define ENETDOWN WSAENETDOWN
145 #define ENETUNREACH WSAENETUNREACH
146 #define ENETRESET WSAENETRESET
147 #define ECONNABORTED WSAECONNABORTED
148 #define ECONNRESET WSAECONNRESET
149 #define ENOBUFS WSAENOBUFS
150 #define EISCONN WSAEISCONN
151 #define ENOTCONN WSAENOTCONN
152 #define ESHUTDOWN WSAESHUTDOWN
153 #define ETOOMANYREFS WSAETOOMANYREFS
154 #define ETIMEDOUT WSAETIMEDOUT
155 #define ECONNREFUSED WSAECONNREFUSED
156 #define ELOOP WSAELOOP
157 /* #define ENAMETOOLONG WSAENAMETOOLONG */
158 #define EHOSTDOWN WSAEHOSTDOWN
159 #define EHOSTUNREACH WSAEHOSTUNREACH
160 /* #define ENOTEMPTY WSAENOTEMPTY */
161 #define EPROCLIM WSAEPROCLIM
162 #define EUSERS WSAEUSERS
163 #define EDQUOT WSAEDQUOT
164 #define ESTALE WSAESTALE
165 #define EREMOTE WSAEREMOTE
166
167 #endif /* _SOCKET_H_ */
168
169 /* end of socket.h */