This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Include ws2tcpip.h to get IPv6 definitions
[perl5.git] / win32 / include / sys / socket.h
CommitLineData
cb69f87a 1/* sys/socket.h */
0a753a76 2
cb69f87a
MB
3/* djl */
4/* Provide UNIX compatibility */
0a753a76 5
0a753a76
PP
6#ifndef _INC_SYS_SOCKET
7#define _INC_SYS_SOCKET
8
a835ef8a
NIS
9#define WIN32_LEAN_AND_MEAN
10#ifdef __GNUC__
32ce4731 11# define Win32_Winsock
a835ef8a
NIS
12#endif
13#include <windows.h>
a86d78b9
JD
14
15/* Too late to include winsock2.h if winsock.h has already been loaded */
16#ifndef _WINSOCKAPI_
f4257e4d
YO
17# if defined(UNDER_CE) && UNDER_CE <= 300
18 /* winsock2 only for 4.00+ */
19# include <winsock.h>
20# else
41ed632e
JD
21# include <winsock2.h>
22 /* We need to include ws2tcpip.h to get the IPv6 definitions.
23 * It will in turn include wspiapi.h. Later versions of that
24 * header in the Windows SDK generate C++ template code that
25 * can't be compiled with VC6 anymore. The _WSPIAPI_COUNTOF
26 * definition below prevents wspiapi.h from generating this
27 * incompatible code.
28 */
29# define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
30# include <ws2tcpip.h>
31# endif
f4257e4d 32#endif
0a753a76 33
8d3f517a
GS
34#include "win32.h"
35
41ed632e
JD
36#ifdef __cplusplus
37extern "C" {
38#endif
39
2a46176f
SH
40#ifndef ENOTSOCK
41#define ENOTSOCK WSAENOTSOCK
42#endif
0a753a76 43
55d25626
GS
44#ifdef USE_SOCKETS_AS_HANDLES
45
46#ifndef PERL_FD_SETSIZE
47#define PERL_FD_SETSIZE 64
48#endif
49
50#define PERL_BITS_PER_BYTE 8
51#define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
52
53typedef int Perl_fd_mask;
54
55typedef struct Perl_fd_set {
56 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
57} Perl_fd_set;
58
59#define PERL_FD_CLR(n,p) \
60 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
61
62#define PERL_FD_SET(n,p) \
63 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
64
65#define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
66
67#define PERL_FD_ISSET(n,p) \
68 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
69
70#else /* USE_SOCKETS_AS_HANDLES */
71
72#define Perl_fd_set fd_set
73#define PERL_FD_SET(n,p) FD_SET(n,p)
74#define PERL_FD_CLR(n,p) FD_CLR(n,p)
75#define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
76#define PERL_FD_ZERO(p) FD_ZERO(p)
77
78#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76
PP
79
80SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
81int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
82int win32_closesocket (SOCKET s);
83int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
84int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
85int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
86int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
87int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
88u_long win32_htonl (u_long hostlong);
89u_short win32_htons (u_short hostshort);
90unsigned long win32_inet_addr (const char * cp);
91char * win32_inet_ntoa (struct in_addr in);
92int win32_listen (SOCKET s, int backlog);
93u_long win32_ntohl (u_long netlong);
94u_short win32_ntohs (u_short netshort);
95int win32_recv (SOCKET s, char * buf, int len, int flags);
96int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
97 struct sockaddr *from, int * fromlen);
55d25626
GS
98int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
99 const struct timeval *timeout);
0a753a76
PP
100int win32_send (SOCKET s, const char * buf, int len, int flags);
101int win32_sendto (SOCKET s, const char * buf, int len, int flags,
102 const struct sockaddr *to, int tolen);
103int win32_setsockopt (SOCKET s, int level, int optname,
104 const char * optval, int optlen);
105SOCKET win32_socket (int af, int type, int protocol);
106int win32_shutdown (SOCKET s, int how);
107
108/* Database function prototypes */
109
110struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
111struct hostent * win32_gethostbyname(const char * name);
112int win32_gethostname (char * name, int namelen);
113struct servent * win32_getservbyport(int port, const char * proto);
114struct servent * win32_getservbyname(const char * name, const char * proto);
115struct protoent * win32_getprotobynumber(int proto);
116struct protoent * win32_getprotobyname(const char * name);
117struct protoent *win32_getprotoent(void);
118struct servent *win32_getservent(void);
119void win32_sethostent(int stayopen);
120void win32_setnetent(int stayopen);
3e3baf6d
TB
121struct netent * win32_getnetent(void);
122struct netent * win32_getnetbyname(char *name);
123struct netent * win32_getnetbyaddr(long net, int type);
0a753a76
PP
124void win32_setprotoent(int stayopen);
125void win32_setservent(int stayopen);
3e3baf6d
TB
126void win32_endhostent(void);
127void win32_endnetent(void);
128void win32_endprotoent(void);
129void win32_endservent(void);
0a753a76 130
55d25626 131#ifndef WIN32SCK_IS_STDSCK
cb69f87a
MB
132
133/* direct to our version */
134
0a753a76
PP
135#define htonl win32_htonl
136#define htons win32_htons
137#define ntohl win32_ntohl
138#define ntohs win32_ntohs
139#define inet_addr win32_inet_addr
140#define inet_ntoa win32_inet_ntoa
141
142#define socket win32_socket
143#define bind win32_bind
144#define listen win32_listen
145#define accept win32_accept
146#define connect win32_connect
147#define send win32_send
148#define sendto win32_sendto
149#define recv win32_recv
150#define recvfrom win32_recvfrom
151#define shutdown win32_shutdown
3a25acb4 152#define closesocket win32_closesocket
0a753a76
PP
153#define ioctlsocket win32_ioctlsocket
154#define setsockopt win32_setsockopt
155#define getsockopt win32_getsockopt
156#define getpeername win32_getpeername
157#define getsockname win32_getsockname
158#define gethostname win32_gethostname
159#define gethostbyname win32_gethostbyname
160#define gethostbyaddr win32_gethostbyaddr
161#define getprotobyname win32_getprotobyname
162#define getprotobynumber win32_getprotobynumber
163#define getservbyname win32_getservbyname
164#define getservbyport win32_getservbyport
165#define select win32_select
166#define endhostent win32_endhostent
167#define endnetent win32_endnetent
168#define endprotoent win32_endprotoent
169#define endservent win32_endservent
170#define getnetent win32_getnetent
171#define getnetbyname win32_getnetbyname
172#define getnetbyaddr win32_getnetbyaddr
173#define getprotoent win32_getprotoent
174#define getservent win32_getservent
175#define sethostent win32_sethostent
176#define setnetent win32_setnetent
177#define setprotoent win32_setprotoent
178#define setservent win32_setservent
179
55d25626
GS
180#ifdef USE_SOCKETS_AS_HANDLES
181#undef fd_set
182#undef FD_SET
183#undef FD_CLR
184#undef FD_ISSET
185#undef FD_ZERO
186#define fd_set Perl_fd_set
187#define FD_SET(n,p) PERL_FD_SET(n,p)
188#define FD_CLR(n,p) PERL_FD_CLR(n,p)
189#define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
190#define FD_ZERO(p) PERL_FD_ZERO(p)
191#endif /* USE_SOCKETS_AS_HANDLES */
192
193#endif /* WIN32SCK_IS_STDSCK */
194
0a753a76
PP
195#ifdef __cplusplus
196}
197#endif
198
cb69f87a 199#endif /* _INC_SYS_SOCKET */