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