Merge WinCE and Win32 directories -- Initial patch
[p5sagit/p5-mst-13.2.git] / win32 / include / sys / socket.h
CommitLineData
cb69f87a 1/* sys/socket.h */
0a753a76 2
cb69f87a 3/* djl */
4/* Provide UNIX compatibility */
0a753a76 5
0a753a76 6#ifndef _INC_SYS_SOCKET
7#define _INC_SYS_SOCKET
8
7bac28a0 9#ifdef __cplusplus
10extern "C" {
11#endif
0a753a76 12
7bd379e8 13#ifndef _WINCE
14
a835ef8a 15#define WIN32_LEAN_AND_MEAN
16#ifdef __GNUC__
32ce4731 17# define Win32_Winsock
a835ef8a 18#endif
19#include <windows.h>
a86d78b9 20
7bd379e8 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
31typedef int BOOL;
32typedef unsigned short WORD;
33typedef void* HANDLE;
34typedef void* HWND;
35typedef int (FAR WINAPI *FARPROC)();
36
37typedef unsigned long DWORD;
38typedef void *PVOID;
39
40#define IN
41#define OUT
42
43#ifndef UNDER_CE
44typedef 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
a86d78b9 57/* Too late to include winsock2.h if winsock.h has already been loaded */
58#ifndef _WINSOCKAPI_
59# include <winsock2.h>
60#endif
0a753a76 61
8d3f517a 62#include "win32.h"
63
0a753a76 64#define ENOTSOCK WSAENOTSOCK
0a753a76 65
55d25626 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
75typedef int Perl_fd_mask;
76
77typedef 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 */
0a753a76 101
102SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
103int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
104int win32_closesocket (SOCKET s);
105int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
106int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
107int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
108int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
109int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
110u_long win32_htonl (u_long hostlong);
111u_short win32_htons (u_short hostshort);
112unsigned long win32_inet_addr (const char * cp);
113char * win32_inet_ntoa (struct in_addr in);
114int win32_listen (SOCKET s, int backlog);
115u_long win32_ntohl (u_long netlong);
116u_short win32_ntohs (u_short netshort);
117int win32_recv (SOCKET s, char * buf, int len, int flags);
118int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
119 struct sockaddr *from, int * fromlen);
55d25626 120int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
121 const struct timeval *timeout);
0a753a76 122int win32_send (SOCKET s, const char * buf, int len, int flags);
123int win32_sendto (SOCKET s, const char * buf, int len, int flags,
124 const struct sockaddr *to, int tolen);
125int win32_setsockopt (SOCKET s, int level, int optname,
126 const char * optval, int optlen);
127SOCKET win32_socket (int af, int type, int protocol);
128int win32_shutdown (SOCKET s, int how);
129
130/* Database function prototypes */
131
132struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
133struct hostent * win32_gethostbyname(const char * name);
134int win32_gethostname (char * name, int namelen);
135struct servent * win32_getservbyport(int port, const char * proto);
136struct servent * win32_getservbyname(const char * name, const char * proto);
137struct protoent * win32_getprotobynumber(int proto);
138struct protoent * win32_getprotobyname(const char * name);
139struct protoent *win32_getprotoent(void);
140struct servent *win32_getservent(void);
141void win32_sethostent(int stayopen);
142void win32_setnetent(int stayopen);
3e3baf6d 143struct netent * win32_getnetent(void);
144struct netent * win32_getnetbyname(char *name);
145struct netent * win32_getnetbyaddr(long net, int type);
0a753a76 146void win32_setprotoent(int stayopen);
147void win32_setservent(int stayopen);
3e3baf6d 148void win32_endhostent(void);
149void win32_endnetent(void);
150void win32_endprotoent(void);
151void win32_endservent(void);
0a753a76 152
55d25626 153#ifndef WIN32SCK_IS_STDSCK
cb69f87a 154
155/* direct to our version */
156
0a753a76 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
3a25acb4 174#define closesocket win32_closesocket
0a753a76 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
55d25626 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
0a753a76 217#ifdef __cplusplus
218}
219#endif
220
cb69f87a 221#endif /* _INC_SYS_SOCKET */