4 /* Provide UNIX compatibility */
6 #ifndef _INC_SYS_SOCKET
7 #define _INC_SYS_SOCKET
9 #define WIN32_LEAN_AND_MEAN
11 # define Win32_Winsock
15 /* Too late to include winsock2.h if winsock.h has already been loaded */
17 # include <winsock2.h>
18 /* We need to include ws2tcpip.h to get the IPv6 definitions.
19 * It will in turn include wspiapi.h. Later versions of that
20 * header in the Windows SDK generate C++ template code that
21 * can't be compiled with VC6 anymore. The _WSPIAPI_COUNTOF
22 * definition below prevents wspiapi.h from generating this
25 # define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
26 # include <ws2tcpip.h>
28 # ifndef SIO_GET_INTERFACE_LIST_EX
31 # define MSG_WAITALL 0x8
34 /* The ws2tcpip.h header included in VC6 doesn't define the
35 * sin6_scope_id member of sockaddr_in6. We define our own
36 * version and redefine sockaddr_in6 to point to this one
37 * instead for compiling e.g. Socket.xs.
40 struct my_sockaddr_in6 {
41 short sin6_family; /* AF_INET6 */
42 u_short sin6_port; /* Transport level port number */
43 u_long sin6_flowinfo; /* IPv6 flow information */
44 struct in_addr6 sin6_addr; /* IPv6 address */
45 u_long sin6_scope_id; /* set of interfaces for a scope */
47 # define sockaddr_in6 my_sockaddr_in6
49 /* Provide implementations of IN6ADDR_SETANY() and IN6ADDR_SETLOOPBACK
50 * that also initialize the sin6_scope_id field.
52 # undef IN6ADDR_SETANY
53 # define IN6ADDR_SETANY(x) {\
54 (x)->sin6_family = AF_INET6; \
56 (x)->sin6_flowinfo = 0; \
57 *((u_long *)((x)->sin6_addr.s6_addr) ) = 0; \
58 *((u_long *)((x)->sin6_addr.s6_addr) + 1) = 0; \
59 *((u_long *)((x)->sin6_addr.s6_addr) + 2) = 0; \
60 *((u_long *)((x)->sin6_addr.s6_addr) + 3) = 0; \
61 (x)->sin6_scope_id = 0; \
64 # undef IN6ADDR_SETLOOPBACK
65 # define IN6ADDR_SETLOOPBACK(x) {\
66 (x)->sin6_family = AF_INET6; \
68 (x)->sin6_flowinfo = 0; \
69 *((u_long *)((x)->sin6_addr.s6_addr) ) = 0; \
70 *((u_long *)((x)->sin6_addr.s6_addr) + 1) = 0; \
71 *((u_long *)((x)->sin6_addr.s6_addr) + 2) = 0; \
72 *((u_long *)((x)->sin6_addr.s6_addr) + 3) = 1; \
73 (x)->sin6_scope_id = 0; \
77 # define IPV6_HDRINCL 2
79 # ifndef IPV6_UNICAST_HOPS
80 # define IPV6_UNICAST_HOPS 4
82 # ifndef IPV6_MULTICAST_IF
83 # define IPV6_MULTICAST_IF 9
85 # ifndef IPV6_MULTICAST_HOPS
86 # define IPV6_MULTICAST_HOPS 10
88 # ifndef IPV6_MULTICAST_LOOP
89 # define IPV6_MULTICAST_LOOP 11
91 # ifndef IPV6_ADD_MEMBERSHIP
92 # define IPV6_ADD_MEMBERSHIP 12
94 # ifndef IPV6_DROP_MEMBERSHIP
95 # define IPV6_DROP_MEMBERSHIP 13
97 # ifndef IPV6_JOIN_GROUP
98 # define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
100 # ifndef IPV6_LEAVE_GROUP
101 # define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
103 # ifndef IPV6_PKTINFO
104 # define IPV6_PKTINFO 19
106 # ifndef IPV6_HOPLIMIT
107 # define IPV6_HOPLIMIT 21
109 # ifndef IPV6_PROTECTION_LEVEL
110 # define IPV6_PROTECTION_LEVEL 23
113 /* The ws2tcpip.h header included in MinGW includes ipv6_mreq already */
115 typedef struct ipv6_mreq {
116 struct in_addr6 ipv6mr_multiaddr;
117 unsigned int ipv6mr_interface;
122 # define EAI_AGAIN WSATRY_AGAIN
124 # ifndef EAI_BADFLAGS
125 # define EAI_BADFLAGS WSAEINVAL
128 # define EAI_FAIL WSANO_RECOVERY
131 # define EAI_FAMILY WSAEAFNOSUPPORT
134 # define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
137 # define EAI_NODATA WSANO_DATA
140 # define EAI_NONAME WSAHOST_NOT_FOUND
143 # define EAI_SERVICE WSATYPE_NOT_FOUND
145 # ifndef EAI_SOCKTYPE
146 # define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
150 # define NI_NOFQDN 0x01
152 # ifndef NI_NUMERICHOST
153 # define NI_NUMERICHOST 0x02
156 # define NI_NAMEREQD 0x04
158 # ifndef NI_NUMERICSERV
159 # define NI_NUMERICSERV 0x08
162 # define NI_DGRAM 0x10
169 /* Early Platform SDKs have an incorrect definition of EAI_NODATA */
170 #if (EAI_NODATA == EAI_NONAME)
172 # define EAI_NODATA WSANO_DATA
181 #ifndef PERL_FD_SETSIZE
182 #define PERL_FD_SETSIZE 64
185 #define PERL_BITS_PER_BYTE 8
186 #define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
188 typedef int Perl_fd_mask;
190 typedef struct Perl_fd_set {
191 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
194 #define PERL_FD_CLR(n,p) \
195 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
197 #define PERL_FD_SET(n,p) \
198 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
200 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
202 #define PERL_FD_ISSET(n,p) \
203 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
205 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
206 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
207 int win32_closesocket (SOCKET s);
208 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
209 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
210 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
211 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
212 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
213 u_long win32_htonl (u_long hostlong);
214 u_short win32_htons (u_short hostshort);
215 unsigned long win32_inet_addr (const char * cp);
216 char * win32_inet_ntoa (struct in_addr in);
217 int win32_listen (SOCKET s, int backlog);
218 u_long win32_ntohl (u_long netlong);
219 u_short win32_ntohs (u_short netshort);
220 int win32_recv (SOCKET s, char * buf, int len, int flags);
221 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
222 struct sockaddr *from, int * fromlen);
223 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
224 const struct timeval *timeout);
225 int win32_send (SOCKET s, const char * buf, int len, int flags);
226 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
227 const struct sockaddr *to, int tolen);
228 int win32_setsockopt (SOCKET s, int level, int optname,
229 const char * optval, int optlen);
230 SOCKET win32_socket (int af, int type, int protocol);
231 int win32_shutdown (SOCKET s, int how);
233 /* Database function prototypes */
235 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
236 struct hostent * win32_gethostbyname(const char * name);
237 int win32_gethostname (char * name, int namelen);
238 struct servent * win32_getservbyport(int port, const char * proto);
239 struct servent * win32_getservbyname(const char * name, const char * proto);
240 struct protoent * win32_getprotobynumber(int proto);
241 struct protoent * win32_getprotobyname(const char * name);
242 struct protoent *win32_getprotoent(void);
243 struct servent *win32_getservent(void);
244 void win32_sethostent(int stayopen);
245 void win32_setnetent(int stayopen);
246 struct netent * win32_getnetent(void);
247 struct netent * win32_getnetbyname(char *name);
248 struct netent * win32_getnetbyaddr(long net, int type);
249 void win32_setprotoent(int stayopen);
250 void win32_setservent(int stayopen);
251 void win32_endhostent(void);
252 void win32_endnetent(void);
253 void win32_endprotoent(void);
254 void win32_endservent(void);
256 #ifndef WIN32SCK_IS_STDSCK
258 /* direct to our version */
260 #define htonl win32_htonl
261 #define htons win32_htons
262 #define ntohl win32_ntohl
263 #define ntohs win32_ntohs
264 #define inet_addr win32_inet_addr
265 #define inet_ntoa win32_inet_ntoa
267 #define socket win32_socket
268 #define bind win32_bind
269 #define listen win32_listen
270 #define accept win32_accept
271 #define connect win32_connect
272 #define send win32_send
273 #define sendto win32_sendto
274 #define recv win32_recv
275 #define recvfrom win32_recvfrom
276 #define shutdown win32_shutdown
277 #define closesocket win32_closesocket
278 #define ioctlsocket win32_ioctlsocket
279 #define setsockopt win32_setsockopt
280 #define getsockopt win32_getsockopt
281 #define getpeername win32_getpeername
282 #define getsockname win32_getsockname
283 #define gethostname win32_gethostname
284 #define gethostbyname win32_gethostbyname
285 #define gethostbyaddr win32_gethostbyaddr
286 #define getprotobyname win32_getprotobyname
287 #define getprotobynumber win32_getprotobynumber
288 #define getservbyname win32_getservbyname
289 #define getservbyport win32_getservbyport
290 #define select win32_select
291 #define endhostent win32_endhostent
292 #define endnetent win32_endnetent
293 #define endprotoent win32_endprotoent
294 #define endservent win32_endservent
295 #define getnetent win32_getnetent
296 #define getnetbyname win32_getnetbyname
297 #define getnetbyaddr win32_getnetbyaddr
298 #define getprotoent win32_getprotoent
299 #define getservent win32_getservent
300 #define sethostent win32_sethostent
301 #define setnetent win32_setnetent
302 #define setprotoent win32_setprotoent
303 #define setservent win32_setservent
310 #define fd_set Perl_fd_set
311 #define FD_SET(n,p) PERL_FD_SET(n,p)
312 #define FD_CLR(n,p) PERL_FD_CLR(n,p)
313 #define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
314 #define FD_ZERO(p) PERL_FD_ZERO(p)
316 #endif /* WIN32SCK_IS_STDSCK */
322 #endif /* _INC_SYS_SOCKET */