This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
from the non-ANSI comment police (was: it won't compile on win32)
[perl5.git] / wince / 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  _WINDOWS_
14 #ifdef   __GNUC__
15 #define WIN32_LEAN_AND_MEAN
16 #ifdef __GNUC__
17 #define Win32_Winsock
18 #endif
19 #include <windows.h>
20 #else
21 #define  _WINDOWS_
22
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 #endif
54 #endif /* _WINDOWS_ */
55 /* #ifndef __GNUC__ */
56 #include <winsock.h>
57 /* #endif */
58
59 #define  ENOTSOCK       WSAENOTSOCK
60 #undef   HOST_NOT_FOUND
61
62 #ifdef USE_SOCKETS_AS_HANDLES
63
64 #ifndef PERL_FD_SETSIZE
65 #define PERL_FD_SETSIZE         64
66 #endif
67
68 #define PERL_BITS_PER_BYTE      8
69 #define PERL_NFDBITS            (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
70
71 typedef int                     Perl_fd_mask;
72
73 typedef struct  Perl_fd_set {
74     Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
75 }                               Perl_fd_set;
76
77 #define PERL_FD_CLR(n,p) \
78     ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
79
80 #define PERL_FD_SET(n,p) \
81     ((p)->bits[(n)/PERL_NFDBITS] |=  ((unsigned)1 << ((n)%PERL_NFDBITS)))
82
83 #define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
84
85 #define PERL_FD_ISSET(n,p) \
86     ((p)->bits[(n)/PERL_NFDBITS] &   ((unsigned)1 << ((n)%PERL_NFDBITS)))
87
88 #else   /* USE_SOCKETS_AS_HANDLES */
89
90 #define Perl_fd_set     fd_set
91 #define PERL_FD_SET(n,p)        FD_SET(n,p)
92 #define PERL_FD_CLR(n,p)        FD_CLR(n,p)
93 #define PERL_FD_ISSET(n,p)      FD_ISSET(n,p)
94 #define PERL_FD_ZERO(p)         FD_ZERO(p)
95
96 #endif  /* USE_SOCKETS_AS_HANDLES */
97
98 SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
99 int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
100 int win32_closesocket (SOCKET s);
101 int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
102 int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
103 int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
104 int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
105 int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
106 u_long win32_htonl (u_long hostlong);
107 u_short win32_htons (u_short hostshort);
108 unsigned long win32_inet_addr (const char * cp);
109 char * win32_inet_ntoa (struct in_addr in);
110 int win32_listen (SOCKET s, int backlog);
111 u_long win32_ntohl (u_long netlong);
112 u_short win32_ntohs (u_short netshort);
113 int win32_recv (SOCKET s, char * buf, int len, int flags);
114 int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
115                          struct sockaddr *from, int * fromlen);
116 int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
117                   const struct timeval *timeout);
118 int win32_send (SOCKET s, const char * buf, int len, int flags);
119 int win32_sendto (SOCKET s, const char * buf, int len, int flags,
120                        const struct sockaddr *to, int tolen);
121 int win32_setsockopt (SOCKET s, int level, int optname,
122                            const char * optval, int optlen);
123 SOCKET win32_socket (int af, int type, int protocol);
124 int win32_shutdown (SOCKET s, int how);
125
126 /* Database function prototypes */
127
128 struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
129 struct hostent * win32_gethostbyname(const char * name);
130 int win32_gethostname (char * name, int namelen);
131 struct servent * win32_getservbyport(int port, const char * proto);
132 struct servent * win32_getservbyname(const char * name, const char * proto);
133 struct protoent * win32_getprotobynumber(int proto);
134 struct protoent * win32_getprotobyname(const char * name);
135 struct protoent *win32_getprotoent(void);
136 struct servent *win32_getservent(void);
137 void win32_sethostent(int stayopen);
138 void win32_setnetent(int stayopen);
139 struct netent * win32_getnetent(void);
140 struct netent * win32_getnetbyname(char *name);
141 struct netent * win32_getnetbyaddr(long net, int type);
142 void win32_setprotoent(int stayopen);
143 void win32_setservent(int stayopen);
144 void win32_endhostent(void);
145 void win32_endnetent(void);
146 void win32_endprotoent(void);
147 void win32_endservent(void);
148
149 #ifndef WIN32SCK_IS_STDSCK
150
151 /* direct to our version */
152
153 #define htonl           win32_htonl
154 #define htons           win32_htons
155 #define ntohl           win32_ntohl
156 #define ntohs           win32_ntohs
157 #define inet_addr       win32_inet_addr
158 #define inet_ntoa       win32_inet_ntoa
159
160 #define socket          win32_socket
161 #define bind            win32_bind
162 #define listen          win32_listen
163 #define accept          win32_accept
164 #define connect         win32_connect
165 #define send            win32_send
166 #define sendto          win32_sendto
167 #define recv            win32_recv
168 #define recvfrom        win32_recvfrom
169 #define shutdown        win32_shutdown
170 #define closesocket     win32_closesocket
171 #define ioctlsocket     win32_ioctlsocket
172 #define setsockopt      win32_setsockopt
173 #define getsockopt      win32_getsockopt
174 #define getpeername     win32_getpeername
175 #define getsockname     win32_getsockname
176 #define gethostname     win32_gethostname
177 #define gethostbyname   win32_gethostbyname
178 #define gethostbyaddr   win32_gethostbyaddr
179 #define getprotobyname  win32_getprotobyname
180 #define getprotobynumber win32_getprotobynumber
181 #define getservbyname   win32_getservbyname
182 #define getservbyport   win32_getservbyport
183 #define select          win32_select
184 #define endhostent      win32_endhostent
185 #define endnetent       win32_endnetent
186 #define endprotoent     win32_endprotoent
187 #define endservent      win32_endservent
188 #define getnetent       win32_getnetent
189 #define getnetbyname    win32_getnetbyname
190 #define getnetbyaddr    win32_getnetbyaddr
191 #define getprotoent     win32_getprotoent
192 #define getservent      win32_getservent
193 #define sethostent      win32_sethostent
194 #define setnetent       win32_setnetent
195 #define setprotoent     win32_setprotoent
196 #define setservent      win32_setservent
197
198 #ifdef USE_SOCKETS_AS_HANDLES
199 #undef fd_set
200 #undef FD_SET
201 #undef FD_CLR
202 #undef FD_ISSET
203 #undef FD_ZERO
204 #define fd_set          Perl_fd_set
205 #define FD_SET(n,p)     PERL_FD_SET(n,p)
206 #define FD_CLR(n,p)     PERL_FD_CLR(n,p)
207 #define FD_ISSET(n,p)   PERL_FD_ISSET(n,p)
208 #define FD_ZERO(p)      PERL_FD_ZERO(p)
209 #endif  /* USE_SOCKETS_AS_HANDLES */
210
211 #endif  /* WIN32SCK_IS_STDSCK */
212
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif  /* _INC_SYS_SOCKET */