e13e872fe1082da6c15b9dd0a52319b64d48d280
[p5sagit/p5-mst-13.2.git] / win32 / include / sys / socket.h
1 /* sys/socket.h */
2
3 /* djl */
4 /* Provide UNIX compatibility */
5
6 #ifndef  _INC_SYS_SOCKET
7 #define  _INC_SYS_SOCKET
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 #ifndef   _WINCE
14
15 #define WIN32_LEAN_AND_MEAN
16 #ifdef __GNUC__
17 #  define Win32_Winsock
18 #endif
19 #include <windows.h>
20
21 #else
22 /*_WINCE*/
23 #ifndef FAR
24 #define  FAR
25 #endif
26
27 #define  PASCAL     __stdcall
28 #define  WINAPI     __stdcall
29
30 #undef WORD
31 typedef  int        BOOL;
32 typedef  unsigned short WORD;
33 typedef  void*      HANDLE;
34 typedef  void*      HWND;
35 typedef  int (FAR WINAPI *FARPROC)();
36
37 typedef unsigned long       DWORD;
38 typedef void *PVOID;
39
40 #define IN
41 #define OUT
42
43 #ifndef UNDER_CE
44 typedef struct _OVERLAPPED {
45    DWORD   Internal;
46    DWORD   InternalHigh;
47    DWORD   Offset;
48    DWORD   OffsetHigh;
49    HANDLE  hEvent;
50 } OVERLAPPED, *LPOVERLAPPED;
51 #endif
52
53 #undef   HOST_NOT_FOUND
54
55 #endif  /*_WINCE*/
56
57 /* Too late to include winsock2.h if winsock.h has already been loaded */
58 #ifndef _WINSOCKAPI_
59 #  include <winsock2.h>
60 #endif
61
62 #include "win32.h"
63
64 #define  ENOTSOCK       WSAENOTSOCK
65
66 #ifdef USE_SOCKETS_AS_HANDLES
67
68 #ifndef PERL_FD_SETSIZE
69 #define PERL_FD_SETSIZE         64
70 #endif
71
72 #define PERL_BITS_PER_BYTE      8
73 #define PERL_NFDBITS            (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
74
75 typedef int                     Perl_fd_mask;
76
77 typedef struct  Perl_fd_set {
78     Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
79 }                               Perl_fd_set;
80
81 #define PERL_FD_CLR(n,p) \
82     ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
83
84 #define PERL_FD_SET(n,p) \
85     ((p)->bits[(n)/PERL_NFDBITS] |=  ((unsigned)1 << ((n)%PERL_NFDBITS)))
86
87 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
88
89 #define PERL_FD_ISSET(n,p) \
90     ((p)->bits[(n)/PERL_NFDBITS] &   ((unsigned)1 << ((n)%PERL_NFDBITS)))
91
92 #else   /* USE_SOCKETS_AS_HANDLES */
93
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)
99
100 #endif  /* USE_SOCKETS_AS_HANDLES */
101
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);
129
130 /* Database function prototypes */
131
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);
152
153 #ifndef WIN32SCK_IS_STDSCK
154
155 /* direct to our version */
156
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
163
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
201
202 #ifdef USE_SOCKETS_AS_HANDLES
203 #undef fd_set
204 #undef FD_SET
205 #undef FD_CLR
206 #undef FD_ISSET
207 #undef FD_ZERO
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 */
214
215 #endif  /* WIN32SCK_IS_STDSCK */
216
217 #ifdef __cplusplus
218 }
219 #endif
220
221 #endif  /* _INC_SYS_SOCKET */