4 /* Provide UNIX compatibility */
6 #ifndef _INC_SYS_SOCKET
7 #define _INC_SYS_SOCKET
15 #define WIN32_LEAN_AND_MEAN
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;
54 #endif /* _WINDOWS_ */
55 /* #ifndef __GNUC__ */
59 #define ENOTSOCK WSAENOTSOCK
62 #ifdef USE_SOCKETS_AS_HANDLES
64 #ifndef PERL_FD_SETSIZE
65 #define PERL_FD_SETSIZE 64
68 #define PERL_BITS_PER_BYTE 8
69 #define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
71 typedef int Perl_fd_mask;
73 typedef struct Perl_fd_set {
74 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
77 #define PERL_FD_CLR(n,p) \
78 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
80 #define PERL_FD_SET(n,p) \
81 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
83 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
85 #define PERL_FD_ISSET(n,p) \
86 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
88 #else /* USE_SOCKETS_AS_HANDLES */
90 #define Perl_fd_set fd_set
91 #define PERL_FD_SET(n,p) FD_SET(n,p)
92 #define PERL_FD_CLR(n,p) FD_CLR(n,p)
93 #define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
94 #define PERL_FD_ZERO(p) FD_ZERO(p)
96 #endif /* USE_SOCKETS_AS_HANDLES */
98 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
99 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
100 int win32_closesocket (SOCKET s);
101 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
102 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
103 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
104 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
105 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
106 u_long win32_htonl (u_long hostlong);
107 u_short win32_htons (u_short hostshort);
108 unsigned long win32_inet_addr (const char * cp);
109 char * win32_inet_ntoa (struct in_addr in);
110 int win32_listen (SOCKET s, int backlog);
111 u_long win32_ntohl (u_long netlong);
112 u_short win32_ntohs (u_short netshort);
113 int win32_recv (SOCKET s, char * buf, int len, int flags);
114 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
115 struct sockaddr *from, int * fromlen);
116 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
117 const struct timeval *timeout);
118 int win32_send (SOCKET s, const char * buf, int len, int flags);
119 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
120 const struct sockaddr *to, int tolen);
121 int win32_setsockopt (SOCKET s, int level, int optname,
122 const char * optval, int optlen);
123 SOCKET win32_socket (int af, int type, int protocol);
124 int win32_shutdown (SOCKET s, int how);
126 /* Database function prototypes */
128 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
129 struct hostent * win32_gethostbyname(const char * name);
130 int win32_gethostname (char * name, int namelen);
131 struct servent * win32_getservbyport(int port, const char * proto);
132 struct servent * win32_getservbyname(const char * name, const char * proto);
133 struct protoent * win32_getprotobynumber(int proto);
134 struct protoent * win32_getprotobyname(const char * name);
135 struct protoent *win32_getprotoent(void);
136 struct servent *win32_getservent(void);
137 void win32_sethostent(int stayopen);
138 void win32_setnetent(int stayopen);
139 struct netent * win32_getnetent(void);
140 struct netent * win32_getnetbyname(char *name);
141 struct netent * win32_getnetbyaddr(long net, int type);
142 void win32_setprotoent(int stayopen);
143 void win32_setservent(int stayopen);
144 void win32_endhostent(void);
145 void win32_endnetent(void);
146 void win32_endprotoent(void);
147 void win32_endservent(void);
149 #ifndef WIN32SCK_IS_STDSCK
151 /* direct to our version */
153 #define htonl win32_htonl
154 #define htons win32_htons
155 #define ntohl win32_ntohl
156 #define ntohs win32_ntohs
157 #define inet_addr win32_inet_addr
158 #define inet_ntoa win32_inet_ntoa
160 #define socket win32_socket
161 #define bind win32_bind
162 #define listen win32_listen
163 #define accept win32_accept
164 #define connect win32_connect
165 #define send win32_send
166 #define sendto win32_sendto
167 #define recv win32_recv
168 #define recvfrom win32_recvfrom
169 #define shutdown win32_shutdown
170 #define closesocket win32_closesocket
171 #define ioctlsocket win32_ioctlsocket
172 #define setsockopt win32_setsockopt
173 #define getsockopt win32_getsockopt
174 #define getpeername win32_getpeername
175 #define getsockname win32_getsockname
176 #define gethostname win32_gethostname
177 #define gethostbyname win32_gethostbyname
178 #define gethostbyaddr win32_gethostbyaddr
179 #define getprotobyname win32_getprotobyname
180 #define getprotobynumber win32_getprotobynumber
181 #define getservbyname win32_getservbyname
182 #define getservbyport win32_getservbyport
183 #define select win32_select
184 #define endhostent win32_endhostent
185 #define endnetent win32_endnetent
186 #define endprotoent win32_endprotoent
187 #define endservent win32_endservent
188 #define getnetent win32_getnetent
189 #define getnetbyname win32_getnetbyname
190 #define getnetbyaddr win32_getnetbyaddr
191 #define getprotoent win32_getprotoent
192 #define getservent win32_getservent
193 #define sethostent win32_sethostent
194 #define setnetent win32_setnetent
195 #define setprotoent win32_setprotoent
196 #define setservent win32_setservent
198 #ifdef USE_SOCKETS_AS_HANDLES
204 #define fd_set Perl_fd_set
205 #define FD_SET(n,p) PERL_FD_SET(n,p)
206 #define FD_CLR(n,p) PERL_FD_CLR(n,p)
207 #define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
208 #define FD_ZERO(p) PERL_FD_ZERO(p)
209 #endif /* USE_SOCKETS_AS_HANDLES */
211 #endif /* WIN32SCK_IS_STDSCK */
217 #endif /* _INC_SYS_SOCKET */