4 /* Provide UNIX compatibility */
6 #ifndef _INC_SYS_SOCKET
7 #define _INC_SYS_SOCKET
15 #define WIN32_LEAN_AND_MEAN
17 # define Win32_Winsock
27 #define PASCAL __stdcall
28 #define WINAPI __stdcall
32 typedef unsigned short WORD;
35 typedef int (FAR WINAPI *FARPROC)();
37 typedef unsigned long DWORD;
44 typedef struct _OVERLAPPED {
50 } OVERLAPPED, *LPOVERLAPPED;
57 /* Too late to include winsock2.h if winsock.h has already been loaded */
59 # include <winsock2.h>
64 #define ENOTSOCK WSAENOTSOCK
66 #ifdef USE_SOCKETS_AS_HANDLES
68 #ifndef PERL_FD_SETSIZE
69 #define PERL_FD_SETSIZE 64
72 #define PERL_BITS_PER_BYTE 8
73 #define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
75 typedef int Perl_fd_mask;
77 typedef struct Perl_fd_set {
78 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
81 #define PERL_FD_CLR(n,p) \
82 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
84 #define PERL_FD_SET(n,p) \
85 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
87 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
89 #define PERL_FD_ISSET(n,p) \
90 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
92 #else /* USE_SOCKETS_AS_HANDLES */
94 #define Perl_fd_set fd_set
95 #define PERL_FD_SET(n,p) FD_SET(n,p)
96 #define PERL_FD_CLR(n,p) FD_CLR(n,p)
97 #define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
98 #define PERL_FD_ZERO(p) FD_ZERO(p)
100 #endif /* USE_SOCKETS_AS_HANDLES */
102 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
103 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
104 int win32_closesocket (SOCKET s);
105 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
106 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
107 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
108 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
109 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
110 u_long win32_htonl (u_long hostlong);
111 u_short win32_htons (u_short hostshort);
112 unsigned long win32_inet_addr (const char * cp);
113 char * win32_inet_ntoa (struct in_addr in);
114 int win32_listen (SOCKET s, int backlog);
115 u_long win32_ntohl (u_long netlong);
116 u_short win32_ntohs (u_short netshort);
117 int win32_recv (SOCKET s, char * buf, int len, int flags);
118 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
119 struct sockaddr *from, int * fromlen);
120 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
121 const struct timeval *timeout);
122 int win32_send (SOCKET s, const char * buf, int len, int flags);
123 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
124 const struct sockaddr *to, int tolen);
125 int win32_setsockopt (SOCKET s, int level, int optname,
126 const char * optval, int optlen);
127 SOCKET win32_socket (int af, int type, int protocol);
128 int win32_shutdown (SOCKET s, int how);
130 /* Database function prototypes */
132 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
133 struct hostent * win32_gethostbyname(const char * name);
134 int win32_gethostname (char * name, int namelen);
135 struct servent * win32_getservbyport(int port, const char * proto);
136 struct servent * win32_getservbyname(const char * name, const char * proto);
137 struct protoent * win32_getprotobynumber(int proto);
138 struct protoent * win32_getprotobyname(const char * name);
139 struct protoent *win32_getprotoent(void);
140 struct servent *win32_getservent(void);
141 void win32_sethostent(int stayopen);
142 void win32_setnetent(int stayopen);
143 struct netent * win32_getnetent(void);
144 struct netent * win32_getnetbyname(char *name);
145 struct netent * win32_getnetbyaddr(long net, int type);
146 void win32_setprotoent(int stayopen);
147 void win32_setservent(int stayopen);
148 void win32_endhostent(void);
149 void win32_endnetent(void);
150 void win32_endprotoent(void);
151 void win32_endservent(void);
153 #ifndef WIN32SCK_IS_STDSCK
155 /* direct to our version */
157 #define htonl win32_htonl
158 #define htons win32_htons
159 #define ntohl win32_ntohl
160 #define ntohs win32_ntohs
161 #define inet_addr win32_inet_addr
162 #define inet_ntoa win32_inet_ntoa
164 #define socket win32_socket
165 #define bind win32_bind
166 #define listen win32_listen
167 #define accept win32_accept
168 #define connect win32_connect
169 #define send win32_send
170 #define sendto win32_sendto
171 #define recv win32_recv
172 #define recvfrom win32_recvfrom
173 #define shutdown win32_shutdown
174 #define closesocket win32_closesocket
175 #define ioctlsocket win32_ioctlsocket
176 #define setsockopt win32_setsockopt
177 #define getsockopt win32_getsockopt
178 #define getpeername win32_getpeername
179 #define getsockname win32_getsockname
180 #define gethostname win32_gethostname
181 #define gethostbyname win32_gethostbyname
182 #define gethostbyaddr win32_gethostbyaddr
183 #define getprotobyname win32_getprotobyname
184 #define getprotobynumber win32_getprotobynumber
185 #define getservbyname win32_getservbyname
186 #define getservbyport win32_getservbyport
187 #define select win32_select
188 #define endhostent win32_endhostent
189 #define endnetent win32_endnetent
190 #define endprotoent win32_endprotoent
191 #define endservent win32_endservent
192 #define getnetent win32_getnetent
193 #define getnetbyname win32_getnetbyname
194 #define getnetbyaddr win32_getnetbyaddr
195 #define getprotoent win32_getprotoent
196 #define getservent win32_getservent
197 #define sethostent win32_sethostent
198 #define setnetent win32_setnetent
199 #define setprotoent win32_setprotoent
200 #define setservent win32_setservent
202 #ifdef USE_SOCKETS_AS_HANDLES
208 #define fd_set Perl_fd_set
209 #define FD_SET(n,p) PERL_FD_SET(n,p)
210 #define FD_CLR(n,p) PERL_FD_CLR(n,p)
211 #define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
212 #define FD_ZERO(p) PERL_FD_ZERO(p)
213 #endif /* USE_SOCKETS_AS_HANDLES */
215 #endif /* WIN32SCK_IS_STDSCK */
221 #endif /* _INC_SYS_SOCKET */