Include winsock2.h and ws2tcpip.h instead of winsock.h.
[bpt/emacs.git] / nt / inc / sys / socket.h
1 /* Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005,
2 2006, 2007 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
20
21
22 /* Workable version of <sys/socket.h> based on winsock.h */
23
24 #ifndef _SOCKET_H_
25 #define _SOCKET_H_
26
27 /* defeat the multiple include protection */
28 #ifdef _WINSOCKAPI_
29 #undef _WINSOCKAPI_
30 #endif
31 #ifdef _WINSOCK_H
32 #undef _WINSOCK_H
33 #endif
34
35 /* avoid confusion with our version of select */
36 #ifdef select
37 #undef select
38 #define MUST_REDEF_SELECT
39 #endif
40
41 /* avoid clashing with our version of FD_SET if already defined */
42 #ifdef FD_SET
43 #undef FD_SET
44 #undef FD_CLR
45 #undef FD_ISSET
46 #undef FD_ZERO
47 #endif
48
49 /* avoid duplicate definition of timeval */
50 #ifdef HAVE_TIMEVAL
51 #define timeval ws_timeval
52 #endif
53
54 #include <winsock2.h>
55 #include <ws2tcpip.h>
56
57 /* redefine select to reference our version */
58 #ifdef MUST_REDEF_SELECT
59 #define select sys_select
60 #undef MUST_REDEF_SELECT
61 #endif
62
63 /* revert to our version of FD_SET */
64 #undef FD_SET
65 #undef FD_CLR
66 #undef FD_ISSET
67 #undef FD_ZERO
68
69 /* allow us to provide our own version of fd_set */
70 #define fd_set ws_fd_set
71 #include "w32.h"
72
73 #ifdef HAVE_TIMEVAL
74 #undef timeval
75 #endif
76
77 /* shadow functions where we provide our own wrapper */
78 #define socket sys_socket
79 #define bind sys_bind
80 #define connect sys_connect
81 #define htons sys_htons
82 #define ntohs sys_ntohs
83 #define inet_addr sys_inet_addr
84 #define gethostname sys_gethostname
85 #define gethostbyname sys_gethostbyname
86 #define getpeername sys_getpeername
87 #define getservbyname sys_getservbyname
88 #define shutdown sys_shutdown
89 #define setsockopt sys_setsockopt
90 #define listen sys_listen
91 #define getsockname sys_getsockname
92 #define accept sys_accept
93 #define recvfrom sys_recvfrom
94 #define sendto sys_sendto
95
96 int sys_socket(int af, int type, int protocol);
97 int sys_bind (int s, const struct sockaddr *addr, int namelen);
98 int sys_connect (int s, const struct sockaddr *addr, int namelen);
99 u_short sys_htons (u_short hostshort);
100 u_short sys_ntohs (u_short netshort);
101 unsigned long sys_inet_addr (const char * cp);
102 int sys_gethostname (char * name, int namelen);
103 struct hostent * sys_gethostbyname (const char * name);
104 struct servent * sys_getservbyname (const char * name, const char * proto);
105 int sys_getpeername (int s, struct sockaddr *addr, int * namelen);
106 int sys_shutdown (int socket, int how);
107 int sys_setsockopt (int s, int level, int oname, const void * oval, int olen);
108 int sys_listen (int s, int backlog);
109 int sys_getsockname (int s, struct sockaddr * name, int * namelen);
110 int sys_accept (int s, struct sockaddr *addr, int *addrlen);
111 int sys_recvfrom (int s, char *buf, int len, int flags,
112 struct sockaddr *from, int * fromlen);
113 int sys_sendto (int s, const char * buf, int len, int flags,
114 const struct sockaddr *to, int tolen);
115
116 /* In addition to wrappers for the winsock functions, we also provide
117 an fcntl function, for setting sockets to non-blocking mode. */
118 int fcntl (int s, int cmd, int options);
119 #define F_SETFL 4
120 #define O_NDELAY 04000
121
122 /* we are providing a real h_errno variable */
123 #undef h_errno
124 extern int h_errno;
125
126 /* map winsock error codes to standard names */
127 #define EWOULDBLOCK WSAEWOULDBLOCK
128 #define EINPROGRESS WSAEINPROGRESS
129 #define EALREADY WSAEALREADY
130 #define ENOTSOCK WSAENOTSOCK
131 #define EDESTADDRREQ WSAEDESTADDRREQ
132 #define EMSGSIZE WSAEMSGSIZE
133 #define EPROTOTYPE WSAEPROTOTYPE
134 #define ENOPROTOOPT WSAENOPROTOOPT
135 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
136 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
137 #define EOPNOTSUPP WSAEOPNOTSUPP
138 #define EPFNOSUPPORT WSAEPFNOSUPPORT
139 #define EAFNOSUPPORT WSAEAFNOSUPPORT
140 #define EADDRINUSE WSAEADDRINUSE
141 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
142 #define ENETDOWN WSAENETDOWN
143 #define ENETUNREACH WSAENETUNREACH
144 #define ENETRESET WSAENETRESET
145 #define ECONNABORTED WSAECONNABORTED
146 #define ECONNRESET WSAECONNRESET
147 #define ENOBUFS WSAENOBUFS
148 #define EISCONN WSAEISCONN
149 #define ENOTCONN WSAENOTCONN
150 #define ESHUTDOWN WSAESHUTDOWN
151 #define ETOOMANYREFS WSAETOOMANYREFS
152 #define ETIMEDOUT WSAETIMEDOUT
153 #define ECONNREFUSED WSAECONNREFUSED
154 #define ELOOP WSAELOOP
155 /* #define ENAMETOOLONG WSAENAMETOOLONG */
156 #define EHOSTDOWN WSAEHOSTDOWN
157 #define EHOSTUNREACH WSAEHOSTUNREACH
158 /* #define ENOTEMPTY WSAENOTEMPTY */
159 #define EPROCLIM WSAEPROCLIM
160 #define EUSERS WSAEUSERS
161 #define EDQUOT WSAEDQUOT
162 #define ESTALE WSAESTALE
163 #define EREMOTE WSAEREMOTE
164
165 #endif /* _SOCKET_H_ */
166
167 /* end of socket.h */
168
169 /* arch-tag: e3b8b91c-aaa0-4bc4-be57-a85a1dd247b4
170 (do not change this comment) */