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