This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add files and tweak others to get 'native' Mingw32 gcc port as
[perl5.git] / win32 / include / sys / socket.h
CommitLineData
0a753a76 1// sys/socket.h
2
3// djl
4// Provide UNIX compatibility
5
0a753a76 6#ifndef _INC_SYS_SOCKET
7#define _INC_SYS_SOCKET
8
7bac28a0 9#ifdef __cplusplus
10extern "C" {
11#endif
0a753a76 12
13#ifndef _WINDOWS_
a835ef8a
NIS
14#ifdef __GNUC__
15#define WIN32_LEAN_AND_MEAN
16#ifdef __GNUC__
17#define Win32_Winsock
18#endif
19#include <windows.h>
20#else
0a753a76 21#define _WINDOWS_
22
23#define FAR
24#define PASCAL __stdcall
25#define WINAPI __stdcall
26
27#undef WORD
28typedef int BOOL;
29typedef unsigned short WORD;
30typedef void* HANDLE;
31typedef void* HWND;
32typedef int (FAR WINAPI *FARPROC)();
33
34typedef unsigned long DWORD;
35typedef void *PVOID;
36
37#define IN
38#define OUT
39
40typedef struct _OVERLAPPED {
41 DWORD Internal;
42 DWORD InternalHigh;
43 DWORD Offset;
44 DWORD OffsetHigh;
45 HANDLE hEvent;
46} OVERLAPPED, *LPOVERLAPPED;
47
a835ef8a 48#endif
0a753a76 49#endif //_WINDOWS_
a835ef8a 50#ifndef __GNUC__
0a753a76 51#include <winsock.h>
a835ef8a 52#endif
0a753a76 53
54#define ENOTSOCK WSAENOTSOCK
55#undef HOST_NOT_FOUND
56
55d25626
GS
57#ifdef USE_SOCKETS_AS_HANDLES
58
59#ifndef PERL_FD_SETSIZE
60#define PERL_FD_SETSIZE 64
61#endif
62
63#define PERL_BITS_PER_BYTE 8
64#define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
65
66typedef int Perl_fd_mask;
67
68typedef struct Perl_fd_set {
69 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
70} Perl_fd_set;
71
72#define PERL_FD_CLR(n,p) \
73 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
74
75#define PERL_FD_SET(n,p) \
76 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
77
78#define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
79
80#define PERL_FD_ISSET(n,p) \
81 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
82
83#else /* USE_SOCKETS_AS_HANDLES */
84
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)
90
91#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76 92
93SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
94int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
95int win32_closesocket (SOCKET s);
96int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
97int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
98int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
99int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
100int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
101u_long win32_htonl (u_long hostlong);
102u_short win32_htons (u_short hostshort);
103unsigned long win32_inet_addr (const char * cp);
104char * win32_inet_ntoa (struct in_addr in);
105int win32_listen (SOCKET s, int backlog);
106u_long win32_ntohl (u_long netlong);
107u_short win32_ntohs (u_short netshort);
108int win32_recv (SOCKET s, char * buf, int len, int flags);
109int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
110 struct sockaddr *from, int * fromlen);
55d25626
GS
111int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
112 const struct timeval *timeout);
0a753a76 113int win32_send (SOCKET s, const char * buf, int len, int flags);
114int win32_sendto (SOCKET s, const char * buf, int len, int flags,
115 const struct sockaddr *to, int tolen);
116int win32_setsockopt (SOCKET s, int level, int optname,
117 const char * optval, int optlen);
118SOCKET win32_socket (int af, int type, int protocol);
119int win32_shutdown (SOCKET s, int how);
120
121/* Database function prototypes */
122
123struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
124struct hostent * win32_gethostbyname(const char * name);
125int win32_gethostname (char * name, int namelen);
126struct servent * win32_getservbyport(int port, const char * proto);
127struct servent * win32_getservbyname(const char * name, const char * proto);
128struct protoent * win32_getprotobynumber(int proto);
129struct protoent * win32_getprotobyname(const char * name);
130struct protoent *win32_getprotoent(void);
131struct servent *win32_getservent(void);
132void win32_sethostent(int stayopen);
133void win32_setnetent(int stayopen);
3e3baf6d
TB
134struct netent * win32_getnetent(void);
135struct netent * win32_getnetbyname(char *name);
136struct netent * win32_getnetbyaddr(long net, int type);
0a753a76 137void win32_setprotoent(int stayopen);
138void win32_setservent(int stayopen);
3e3baf6d
TB
139void win32_endhostent(void);
140void win32_endnetent(void);
141void win32_endprotoent(void);
142void win32_endservent(void);
0a753a76 143
55d25626 144#ifndef WIN32SCK_IS_STDSCK
0a753a76 145//
146// direct to our version
147//
148#define htonl win32_htonl
149#define htons win32_htons
150#define ntohl win32_ntohl
151#define ntohs win32_ntohs
152#define inet_addr win32_inet_addr
153#define inet_ntoa win32_inet_ntoa
154
155#define socket win32_socket
156#define bind win32_bind
157#define listen win32_listen
158#define accept win32_accept
159#define connect win32_connect
160#define send win32_send
161#define sendto win32_sendto
162#define recv win32_recv
163#define recvfrom win32_recvfrom
164#define shutdown win32_shutdown
3a25acb4 165#define closesocket win32_closesocket
0a753a76 166#define ioctlsocket win32_ioctlsocket
167#define setsockopt win32_setsockopt
168#define getsockopt win32_getsockopt
169#define getpeername win32_getpeername
170#define getsockname win32_getsockname
171#define gethostname win32_gethostname
172#define gethostbyname win32_gethostbyname
173#define gethostbyaddr win32_gethostbyaddr
174#define getprotobyname win32_getprotobyname
175#define getprotobynumber win32_getprotobynumber
176#define getservbyname win32_getservbyname
177#define getservbyport win32_getservbyport
178#define select win32_select
179#define endhostent win32_endhostent
180#define endnetent win32_endnetent
181#define endprotoent win32_endprotoent
182#define endservent win32_endservent
183#define getnetent win32_getnetent
184#define getnetbyname win32_getnetbyname
185#define getnetbyaddr win32_getnetbyaddr
186#define getprotoent win32_getprotoent
187#define getservent win32_getservent
188#define sethostent win32_sethostent
189#define setnetent win32_setnetent
190#define setprotoent win32_setprotoent
191#define setservent win32_setservent
192
55d25626
GS
193#ifdef USE_SOCKETS_AS_HANDLES
194#undef fd_set
195#undef FD_SET
196#undef FD_CLR
197#undef FD_ISSET
198#undef FD_ZERO
199#define fd_set Perl_fd_set
200#define FD_SET(n,p) PERL_FD_SET(n,p)
201#define FD_CLR(n,p) PERL_FD_CLR(n,p)
202#define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
203#define FD_ZERO(p) PERL_FD_ZERO(p)
204#endif /* USE_SOCKETS_AS_HANDLES */
205
206#endif /* WIN32SCK_IS_STDSCK */
207
0a753a76 208#ifdef __cplusplus
209}
210#endif
211
212#endif // _INC_SYS_SOCKET