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 # if defined(UNDER_CE) && UNDER_CE <= 300
18 /* winsock2 only for 4.00+ */
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
29 # define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
30 # include <ws2tcpip.h>
32 # ifndef SIO_GET_INTERFACE_LIST_EX
35 # define MSG_WAITALL 0x8
38 /* The ws2tcpip.h header included in VC6 doesn't define the
39 * sin6_scope_id member of sockaddr_in6. We define our own
40 * version and redefine sockaddr_in6 to point to this one
41 * instead for compiling e.g. Socket.xs.
44 struct my_sockaddr_in6 {
45 short sin6_family; /* AF_INET6 */
46 u_short sin6_port; /* Transport level port number */
47 u_long sin6_flowinfo; /* IPv6 flow information */
48 struct in_addr6 sin6_addr; /* IPv6 address */
49 u_long sin6_scope_id; /* set of interfaces for a scope */
51 # define sockaddr_in6 my_sockaddr_in6
53 /* Provide implementations of IN6ADDR_SETANY() and IN6ADDR_SETLOOPBACK
54 * that also initialize the sin6_scope_id field.
56 # undef IN6ADDR_SETANY
57 # define IN6ADDR_SETANY(x) {\
58 (x)->sin6_family = AF_INET6; \
60 (x)->sin6_flowinfo = 0; \
61 *((u_long *)((x)->sin6_addr.s6_addr) ) = 0; \
62 *((u_long *)((x)->sin6_addr.s6_addr) + 1) = 0; \
63 *((u_long *)((x)->sin6_addr.s6_addr) + 2) = 0; \
64 *((u_long *)((x)->sin6_addr.s6_addr) + 3) = 0; \
65 (x)->sin6_scope_id = 0; \
68 # undef IN6ADDR_SETLOOPBACK
69 # define IN6ADDR_SETLOOPBACK(x) {\
70 (x)->sin6_family = AF_INET6; \
72 (x)->sin6_flowinfo = 0; \
73 *((u_long *)((x)->sin6_addr.s6_addr) ) = 0; \
74 *((u_long *)((x)->sin6_addr.s6_addr) + 1) = 0; \
75 *((u_long *)((x)->sin6_addr.s6_addr) + 2) = 0; \
76 *((u_long *)((x)->sin6_addr.s6_addr) + 3) = 1; \
77 (x)->sin6_scope_id = 0; \
81 # define IPV6_HDRINCL 2
83 # ifndef IPV6_UNICAST_HOPS
84 # define IPV6_UNICAST_HOPS 4
86 # ifndef IPV6_MULTICAST_IF
87 # define IPV6_MULTICAST_IF 9
89 # ifndef IPV6_MULTICAST_HOPS
90 # define IPV6_MULTICAST_HOPS 10
92 # ifndef IPV6_MULTICAST_LOOP
93 # define IPV6_MULTICAST_LOOP 11
95 # ifndef IPV6_ADD_MEMBERSHIP
96 # define IPV6_ADD_MEMBERSHIP 12
98 # ifndef IPV6_DROP_MEMBERSHIP
99 # define IPV6_DROP_MEMBERSHIP 13
101 # ifndef IPV6_JOIN_GROUP
102 # define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
104 # ifndef IPV6_LEAVE_GROUP
105 # define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
107 # ifndef IPV6_PKTINFO
108 # define IPV6_PKTINFO 19
110 # ifndef IPV6_HOPLIMIT
111 # define IPV6_HOPLIMIT 21
113 # ifndef IPV6_PROTECTION_LEVEL
114 # define IPV6_PROTECTION_LEVEL 23
117 /* The ws2tcpip.h header included in MinGW includes ipv6_mreq already */
119 typedef struct ipv6_mreq {
120 struct in_addr6 ipv6mr_multiaddr;
121 unsigned int ipv6mr_interface;
126 # define EAI_AGAIN WSATRY_AGAIN
128 # ifndef EAI_BADFLAGS
129 # define EAI_BADFLAGS WSAEINVAL
132 # define EAI_FAIL WSANO_RECOVERY
135 # define EAI_FAMILY WSAEAFNOSUPPORT
138 # define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
141 # define EAI_NODATA WSANO_DATA
144 # define EAI_NONAME WSAHOST_NOT_FOUND
147 # define EAI_SERVICE WSATYPE_NOT_FOUND
149 # ifndef EAI_SOCKTYPE
150 # define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
154 # define NI_NOFQDN 0x01
156 # ifndef NI_NUMERICHOST
157 # define NI_NUMERICHOST 0x02
160 # define NI_NAMEREQD 0x04
162 # ifndef NI_NUMERICSERV
163 # define NI_NUMERICSERV 0x08
166 # define NI_DGRAM 0x10
174 /* Early Platform SDKs have an incorrect definition of EAI_NODATA */
175 #if (EAI_NODATA == EAI_NONAME)
177 # define EAI_NODATA WSANO_DATA
187 #define ENOTSOCK WSAENOTSOCK
190 #define ECONNABORTED WSAECONNABORTED
193 #define ECONNRESET WSAECONNRESET
196 #define EAFNOSUPPORT WSAEAFNOSUPPORT
198 #ifdef USE_SOCKETS_AS_HANDLES
200 #ifndef PERL_FD_SETSIZE
201 #define PERL_FD_SETSIZE 64
204 #define PERL_BITS_PER_BYTE 8
205 #define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
207 typedef int Perl_fd_mask;
209 typedef struct Perl_fd_set {
210 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
213 #define PERL_FD_CLR(n,p) \
214 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
216 #define PERL_FD_SET(n,p) \
217 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
219 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
221 #define PERL_FD_ISSET(n,p) \
222 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
224 #else /* USE_SOCKETS_AS_HANDLES */
226 #define Perl_fd_set fd_set
227 #define PERL_FD_SET(n,p) FD_SET(n,p)
228 #define PERL_FD_CLR(n,p) FD_CLR(n,p)
229 #define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
230 #define PERL_FD_ZERO(p) FD_ZERO(p)
232 #endif /* USE_SOCKETS_AS_HANDLES */
234 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
235 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
236 int win32_closesocket (SOCKET s);
237 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
238 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
239 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
240 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
241 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
242 u_long win32_htonl (u_long hostlong);
243 u_short win32_htons (u_short hostshort);
244 unsigned long win32_inet_addr (const char * cp);
245 char * win32_inet_ntoa (struct in_addr in);
246 int win32_listen (SOCKET s, int backlog);
247 u_long win32_ntohl (u_long netlong);
248 u_short win32_ntohs (u_short netshort);
249 int win32_recv (SOCKET s, char * buf, int len, int flags);
250 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
251 struct sockaddr *from, int * fromlen);
252 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
253 const struct timeval *timeout);
254 int win32_send (SOCKET s, const char * buf, int len, int flags);
255 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
256 const struct sockaddr *to, int tolen);
257 int win32_setsockopt (SOCKET s, int level, int optname,
258 const char * optval, int optlen);
259 SOCKET win32_socket (int af, int type, int protocol);
260 int win32_shutdown (SOCKET s, int how);
262 /* Database function prototypes */
264 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
265 struct hostent * win32_gethostbyname(const char * name);
266 int win32_gethostname (char * name, int namelen);
267 struct servent * win32_getservbyport(int port, const char * proto);
268 struct servent * win32_getservbyname(const char * name, const char * proto);
269 struct protoent * win32_getprotobynumber(int proto);
270 struct protoent * win32_getprotobyname(const char * name);
271 struct protoent *win32_getprotoent(void);
272 struct servent *win32_getservent(void);
273 void win32_sethostent(int stayopen);
274 void win32_setnetent(int stayopen);
275 struct netent * win32_getnetent(void);
276 struct netent * win32_getnetbyname(char *name);
277 struct netent * win32_getnetbyaddr(long net, int type);
278 void win32_setprotoent(int stayopen);
279 void win32_setservent(int stayopen);
280 void win32_endhostent(void);
281 void win32_endnetent(void);
282 void win32_endprotoent(void);
283 void win32_endservent(void);
285 #ifndef WIN32SCK_IS_STDSCK
287 /* direct to our version */
289 #define htonl win32_htonl
290 #define htons win32_htons
291 #define ntohl win32_ntohl
292 #define ntohs win32_ntohs
293 #define inet_addr win32_inet_addr
294 #define inet_ntoa win32_inet_ntoa
296 #define socket win32_socket
297 #define bind win32_bind
298 #define listen win32_listen
299 #define accept win32_accept
300 #define connect win32_connect
301 #define send win32_send
302 #define sendto win32_sendto
303 #define recv win32_recv
304 #define recvfrom win32_recvfrom
305 #define shutdown win32_shutdown
306 #define closesocket win32_closesocket
307 #define ioctlsocket win32_ioctlsocket
308 #define setsockopt win32_setsockopt
309 #define getsockopt win32_getsockopt
310 #define getpeername win32_getpeername
311 #define getsockname win32_getsockname
312 #define gethostname win32_gethostname
313 #define gethostbyname win32_gethostbyname
314 #define gethostbyaddr win32_gethostbyaddr
315 #define getprotobyname win32_getprotobyname
316 #define getprotobynumber win32_getprotobynumber
317 #define getservbyname win32_getservbyname
318 #define getservbyport win32_getservbyport
319 #define select win32_select
320 #define endhostent win32_endhostent
321 #define endnetent win32_endnetent
322 #define endprotoent win32_endprotoent
323 #define endservent win32_endservent
324 #define getnetent win32_getnetent
325 #define getnetbyname win32_getnetbyname
326 #define getnetbyaddr win32_getnetbyaddr
327 #define getprotoent win32_getprotoent
328 #define getservent win32_getservent
329 #define sethostent win32_sethostent
330 #define setnetent win32_setnetent
331 #define setprotoent win32_setprotoent
332 #define setservent win32_setservent
334 #ifdef USE_SOCKETS_AS_HANDLES
340 #define fd_set Perl_fd_set
341 #define FD_SET(n,p) PERL_FD_SET(n,p)
342 #define FD_CLR(n,p) PERL_FD_CLR(n,p)
343 #define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
344 #define FD_ZERO(p) PERL_FD_ZERO(p)
345 #endif /* USE_SOCKETS_AS_HANDLES */
347 #endif /* WIN32SCK_IS_STDSCK */
353 #endif /* _INC_SYS_SOCKET */