1/* sys/socket.h */
2
3/* djl */
4/* Provide UNIX compatibility */
5
6#ifndef  _INC_SYS_SOCKET
7#define  _INC_SYS_SOCKET
8
9#define WIN32_LEAN_AND_MEAN
10#ifdef __GNUC__
11#  define Win32_Winsock
12#endif
13#include <windows.h>
14
15/* Too late to include winsock2.h if winsock.h has already been loaded */
16#ifndef _WINSOCKAPI_
17#  include <winsock2.h>
18#  include <ws2tcpip.h>
19#endif
20
21/* Early Platform SDKs have an incorrect definition of EAI_NODATA */
22#if (EAI_NODATA == EAI_NONAME)
23#  undef EAI_NODATA
24#  define EAI_NODATA WSANO_DATA
25#endif
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include "errno2.h"
32
33#ifndef PERL_FD_SETSIZE
34#define PERL_FD_SETSIZE		64
35#endif
36
37#define PERL_BITS_PER_BYTE	8
38#define PERL_NFDBITS            (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
39
40typedef int			Perl_fd_mask;
41
42typedef struct	Perl_fd_set {
43    Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
44}				Perl_fd_set;
45
46#define PERL_FD_CLR(n,p) \
47    ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
48
49#define PERL_FD_SET(n,p) \
50    ((p)->bits[(n)/PERL_NFDBITS] |=  ((unsigned)1 << ((n)%PERL_NFDBITS)))
51
52#define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
53
54#define PERL_FD_ISSET(n,p) \
55    ((p)->bits[(n)/PERL_NFDBITS] &   ((unsigned)1 << ((n)%PERL_NFDBITS)))
56
57SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
58int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
59int win32_closesocket (SOCKET s);
60int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
61int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
62int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
63int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
64int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
65u_long win32_htonl (u_long hostlong);
66u_short win32_htons (u_short hostshort);
67unsigned long win32_inet_addr (const char * cp);
68char * win32_inet_ntoa (struct in_addr in);
69int win32_listen (SOCKET s, int backlog);
70u_long win32_ntohl (u_long netlong);
71u_short win32_ntohs (u_short netshort);
72int win32_recv (SOCKET s, char * buf, int len, int flags);
73int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
74                         struct sockaddr *from, int * fromlen);
75int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
76                  const struct timeval *timeout);
77int win32_send (SOCKET s, const char * buf, int len, int flags);
78int win32_sendto (SOCKET s, const char * buf, int len, int flags,
79                       const struct sockaddr *to, int tolen);
80int win32_setsockopt (SOCKET s, int level, int optname,
81                           const char * optval, int optlen);
82SOCKET win32_socket (int af, int type, int protocol);
83int win32_shutdown (SOCKET s, int how);
84
85/* Database function prototypes */
86
87struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
88struct hostent * win32_gethostbyname(const char * name);
89int win32_gethostname (char * name, int namelen);
90struct servent * win32_getservbyport(int port, const char * proto);
91struct servent * win32_getservbyname(const char * name, const char * proto);
92struct protoent * win32_getprotobynumber(int proto);
93struct protoent * win32_getprotobyname(const char * name);
94struct protoent *win32_getprotoent(void);
95struct servent *win32_getservent(void);
96void win32_sethostent(int stayopen);
97void win32_setnetent(int stayopen);
98struct netent * win32_getnetent(void);
99struct netent * win32_getnetbyname(char *name);
100struct netent * win32_getnetbyaddr(long net, int type);
101void win32_setprotoent(int stayopen);
102void win32_setservent(int stayopen);
103void win32_endhostent(void);
104void win32_endnetent(void);
105void win32_endprotoent(void);
106void win32_endservent(void);
107
108#ifndef WIN32SCK_IS_STDSCK
109
110/* direct to our version */
111
112#define htonl		win32_htonl
113#define htons		win32_htons
114#define ntohl		win32_ntohl
115#define ntohs		win32_ntohs
116#define inet_addr	win32_inet_addr
117#define inet_ntoa	win32_inet_ntoa
118
119#define socket		win32_socket
120#define bind		win32_bind
121#define listen		win32_listen
122#define accept		win32_accept
123#define connect		win32_connect
124#define send		win32_send
125#define sendto		win32_sendto
126#define recv		win32_recv
127#define recvfrom	win32_recvfrom
128#define shutdown	win32_shutdown
129#define closesocket	win32_closesocket
130#define ioctlsocket	win32_ioctlsocket
131#define setsockopt	win32_setsockopt
132#define getsockopt	win32_getsockopt
133#define getpeername	win32_getpeername
134#define getsockname	win32_getsockname
135#define gethostname	win32_gethostname
136#define gethostbyname	win32_gethostbyname
137#define gethostbyaddr	win32_gethostbyaddr
138#define getprotobyname	win32_getprotobyname
139#define getprotobynumber win32_getprotobynumber
140#define getservbyname	win32_getservbyname
141#define getservbyport	win32_getservbyport
142#define select		win32_select
143#define endhostent	win32_endhostent
144#define endnetent	win32_endnetent
145#define endprotoent	win32_endprotoent
146#define endservent	win32_endservent
147#define getnetent	win32_getnetent
148#define getnetbyname	win32_getnetbyname
149#define getnetbyaddr	win32_getnetbyaddr
150#define getprotoent	win32_getprotoent
151#define getservent	win32_getservent
152#define sethostent	win32_sethostent
153#define setnetent	win32_setnetent
154#define setprotoent	win32_setprotoent
155#define setservent	win32_setservent
156
157#undef fd_set
158#undef FD_SET
159#undef FD_CLR
160#undef FD_ISSET
161#undef FD_ZERO
162#define fd_set		Perl_fd_set
163#define FD_SET(n,p)	PERL_FD_SET(n,p)
164#define FD_CLR(n,p)	PERL_FD_CLR(n,p)
165#define FD_ISSET(n,p)	PERL_FD_ISSET(n,p)
166#define FD_ZERO(p)	PERL_FD_ZERO(p)
167
168#endif	/* WIN32SCK_IS_STDSCK */
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif	/* _INC_SYS_SOCKET */
175