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
186 #ifndef PERL_FD_SETSIZE
187 #define PERL_FD_SETSIZE 64
190 #define PERL_BITS_PER_BYTE 8
191 #define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
193 typedef int Perl_fd_mask;
195 typedef struct Perl_fd_set {
196 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
199 #define PERL_FD_CLR(n,p) \
200 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
202 #define PERL_FD_SET(n,p) \
203 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
205 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
207 #define PERL_FD_ISSET(n,p) \
208 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
210 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
211 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
212 int win32_closesocket (SOCKET s);
213 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
214 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
215 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
216 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
217 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
218 u_long win32_htonl (u_long hostlong);
219 u_short win32_htons (u_short hostshort);
220 unsigned long win32_inet_addr (const char * cp);
221 char * win32_inet_ntoa (struct in_addr in);
222 int win32_listen (SOCKET s, int backlog);
223 u_long win32_ntohl (u_long netlong);
224 u_short win32_ntohs (u_short netshort);
225 int win32_recv (SOCKET s, char * buf, int len, int flags);
226 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
227 struct sockaddr *from, int * fromlen);
228 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
229 const struct timeval *timeout);
230 int win32_send (SOCKET s, const char * buf, int len, int flags);
231 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
232 const struct sockaddr *to, int tolen);
233 int win32_setsockopt (SOCKET s, int level, int optname,
234 const char * optval, int optlen);
235 SOCKET win32_socket (int af, int type, int protocol);
236 int win32_shutdown (SOCKET s, int how);
238 /* Database function prototypes */
240 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
241 struct hostent * win32_gethostbyname(const char * name);
242 int win32_gethostname (char * name, int namelen);
243 struct servent * win32_getservbyport(int port, const char * proto);
244 struct servent * win32_getservbyname(const char * name, const char * proto);
245 struct protoent * win32_getprotobynumber(int proto);
246 struct protoent * win32_getprotobyname(const char * name);
247 struct protoent *win32_getprotoent(void);
248 struct servent *win32_getservent(void);
249 void win32_sethostent(int stayopen);
250 void win32_setnetent(int stayopen);
251 struct netent * win32_getnetent(void);
252 struct netent * win32_getnetbyname(char *name);
253 struct netent * win32_getnetbyaddr(long net, int type);
254 void win32_setprotoent(int stayopen);
255 void win32_setservent(int stayopen);
256 void win32_endhostent(void);
257 void win32_endnetent(void);
258 void win32_endprotoent(void);
259 void win32_endservent(void);
261 #ifndef WIN32SCK_IS_STDSCK
263 /* direct to our version */
265 #define htonl win32_htonl
266 #define htons win32_htons
267 #define ntohl win32_ntohl
268 #define ntohs win32_ntohs
269 #define inet_addr win32_inet_addr
270 #define inet_ntoa win32_inet_ntoa
272 #define socket win32_socket
273 #define bind win32_bind
274 #define listen win32_listen
275 #define accept win32_accept
276 #define connect win32_connect
277 #define send win32_send
278 #define sendto win32_sendto
279 #define recv win32_recv
280 #define recvfrom win32_recvfrom
281 #define shutdown win32_shutdown
282 #define closesocket win32_closesocket
283 #define ioctlsocket win32_ioctlsocket
284 #define setsockopt win32_setsockopt
285 #define getsockopt win32_getsockopt
286 #define getpeername win32_getpeername
287 #define getsockname win32_getsockname
288 #define gethostname win32_gethostname
289 #define gethostbyname win32_gethostbyname
290 #define gethostbyaddr win32_gethostbyaddr
291 #define getprotobyname win32_getprotobyname
292 #define getprotobynumber win32_getprotobynumber
293 #define getservbyname win32_getservbyname
294 #define getservbyport win32_getservbyport
295 #define select win32_select
296 #define endhostent win32_endhostent
297 #define endnetent win32_endnetent
298 #define endprotoent win32_endprotoent
299 #define endservent win32_endservent
300 #define getnetent win32_getnetent
301 #define getnetbyname win32_getnetbyname
302 #define getnetbyaddr win32_getnetbyaddr
303 #define getprotoent win32_getprotoent
304 #define getservent win32_getservent
305 #define sethostent win32_sethostent
306 #define setnetent win32_setnetent
307 #define setprotoent win32_setprotoent
308 #define setservent win32_setservent
315 #define fd_set Perl_fd_set
316 #define FD_SET(n,p) PERL_FD_SET(n,p)
317 #define FD_CLR(n,p) PERL_FD_CLR(n,p)
318 #define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
319 #define FD_ZERO(p) PERL_FD_ZERO(p)
321 #endif /* WIN32SCK_IS_STDSCK */
327 #endif /* _INC_SYS_SOCKET */