4 /* Provide UNIX compatibility */
6 #ifndef _INC_SYS_SOCKET
7 #define _INC_SYS_SOCKET
13 #define WIN32_LEAN_AND_MEAN
15 # define Win32_Winsock
20 /* Too late to include winsock2.h if winsock.h has already been loaded */
22 # if defined(UNDER_CE) && UNDER_CE <= 300
23 /* winsock2 only for 4.00+ */
26 # include <winsock2.h>
32 #define ENOTSOCK WSAENOTSOCK
34 #ifdef USE_SOCKETS_AS_HANDLES
36 #ifndef PERL_FD_SETSIZE
37 #define PERL_FD_SETSIZE 64
40 #define PERL_BITS_PER_BYTE 8
41 #define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
43 typedef int Perl_fd_mask;
45 typedef struct Perl_fd_set {
46 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
49 #define PERL_FD_CLR(n,p) \
50 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
52 #define PERL_FD_SET(n,p) \
53 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
55 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
57 #define PERL_FD_ISSET(n,p) \
58 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
60 #else /* USE_SOCKETS_AS_HANDLES */
62 #define Perl_fd_set fd_set
63 #define PERL_FD_SET(n,p) FD_SET(n,p)
64 #define PERL_FD_CLR(n,p) FD_CLR(n,p)
65 #define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
66 #define PERL_FD_ZERO(p) FD_ZERO(p)
68 #endif /* USE_SOCKETS_AS_HANDLES */
70 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
71 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
72 int win32_closesocket (SOCKET s);
73 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
74 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
75 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
76 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
77 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
78 u_long win32_htonl (u_long hostlong);
79 u_short win32_htons (u_short hostshort);
80 unsigned long win32_inet_addr (const char * cp);
81 char * win32_inet_ntoa (struct in_addr in);
82 int win32_listen (SOCKET s, int backlog);
83 u_long win32_ntohl (u_long netlong);
84 u_short win32_ntohs (u_short netshort);
85 int win32_recv (SOCKET s, char * buf, int len, int flags);
86 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
87 struct sockaddr *from, int * fromlen);
88 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
89 const struct timeval *timeout);
90 int win32_send (SOCKET s, const char * buf, int len, int flags);
91 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
92 const struct sockaddr *to, int tolen);
93 int win32_setsockopt (SOCKET s, int level, int optname,
94 const char * optval, int optlen);
95 SOCKET win32_socket (int af, int type, int protocol);
96 int win32_shutdown (SOCKET s, int how);
98 /* Database function prototypes */
100 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
101 struct hostent * win32_gethostbyname(const char * name);
102 int win32_gethostname (char * name, int namelen);
103 struct servent * win32_getservbyport(int port, const char * proto);
104 struct servent * win32_getservbyname(const char * name, const char * proto);
105 struct protoent * win32_getprotobynumber(int proto);
106 struct protoent * win32_getprotobyname(const char * name);
107 struct protoent *win32_getprotoent(void);
108 struct servent *win32_getservent(void);
109 void win32_sethostent(int stayopen);
110 void win32_setnetent(int stayopen);
111 struct netent * win32_getnetent(void);
112 struct netent * win32_getnetbyname(char *name);
113 struct netent * win32_getnetbyaddr(long net, int type);
114 void win32_setprotoent(int stayopen);
115 void win32_setservent(int stayopen);
116 void win32_endhostent(void);
117 void win32_endnetent(void);
118 void win32_endprotoent(void);
119 void win32_endservent(void);
121 #ifndef WIN32SCK_IS_STDSCK
123 /* direct to our version */
125 #define htonl win32_htonl
126 #define htons win32_htons
127 #define ntohl win32_ntohl
128 #define ntohs win32_ntohs
129 #define inet_addr win32_inet_addr
130 #define inet_ntoa win32_inet_ntoa
132 #define socket win32_socket
133 #define bind win32_bind
134 #define listen win32_listen
135 #define accept win32_accept
136 #define connect win32_connect
137 #define send win32_send
138 #define sendto win32_sendto
139 #define recv win32_recv
140 #define recvfrom win32_recvfrom
141 #define shutdown win32_shutdown
142 #define closesocket win32_closesocket
143 #define ioctlsocket win32_ioctlsocket
144 #define setsockopt win32_setsockopt
145 #define getsockopt win32_getsockopt
146 #define getpeername win32_getpeername
147 #define getsockname win32_getsockname
148 #define gethostname win32_gethostname
149 #define gethostbyname win32_gethostbyname
150 #define gethostbyaddr win32_gethostbyaddr
151 #define getprotobyname win32_getprotobyname
152 #define getprotobynumber win32_getprotobynumber
153 #define getservbyname win32_getservbyname
154 #define getservbyport win32_getservbyport
155 #define select win32_select
156 #define endhostent win32_endhostent
157 #define endnetent win32_endnetent
158 #define endprotoent win32_endprotoent
159 #define endservent win32_endservent
160 #define getnetent win32_getnetent
161 #define getnetbyname win32_getnetbyname
162 #define getnetbyaddr win32_getnetbyaddr
163 #define getprotoent win32_getprotoent
164 #define getservent win32_getservent
165 #define sethostent win32_sethostent
166 #define setnetent win32_setnetent
167 #define setprotoent win32_setprotoent
168 #define setservent win32_setservent
170 #ifdef USE_SOCKETS_AS_HANDLES
176 #define fd_set Perl_fd_set
177 #define FD_SET(n,p) PERL_FD_SET(n,p)
178 #define FD_CLR(n,p) PERL_FD_CLR(n,p)
179 #define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
180 #define FD_ZERO(p) PERL_FD_ZERO(p)
181 #endif /* USE_SOCKETS_AS_HANDLES */
183 #endif /* WIN32SCK_IS_STDSCK */
189 #endif /* _INC_SYS_SOCKET */