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