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