Added support for mappings with no associated file.
[wine] / include / winsock.h
1 /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
2  *
3  * This header file corresponds to version 1.1 of the Windows Sockets
4  * specification.
5  */
6
7 #ifndef _WINSOCKAPI_
8 #define _WINSOCKAPI_
9
10 #include <netinet/in.h>
11 #include <arpa/inet.h>
12 #include <sys/types.h>
13 #include <sys/time.h>
14 #include <fcntl.h>
15 #include <netdb.h>
16 #include <sys/socket.h>
17
18 #ifdef HAVE_IPX_GNU
19 # include <netipx/ipx.h>
20 # define HAVE_IPX
21 #endif
22
23 #ifdef HAVE_IPX_LINUX
24 # include <asm/types.h>
25 # include <linux/ipx.h>
26 # define HAVE_IPX
27 #endif
28
29 #include "wintypes.h"
30 #include "task.h"
31
32 #pragma pack(1)
33
34 /* Win16 socket-related types */
35
36 typedef UINT16          SOCKET16;
37 typedef UINT            SOCKET;
38
39 typedef struct ws_hostent
40 {
41         SEGPTR  h_name;         /* official name of host */
42         SEGPTR  h_aliases;      /* alias list */
43         INT16   h_addrtype;     /* host address type */
44         INT16   h_length;       /* length of address */
45         SEGPTR  h_addr_list;    /* list of addresses from name server */
46 } _ws_hostent;
47
48 typedef struct ws_protoent
49 {
50         SEGPTR  p_name;         /* official protocol name */
51         SEGPTR  p_aliases;      /* alias list */
52         INT16   p_proto;        /* protocol # */
53 } _ws_protoent;
54
55 typedef struct ws_servent 
56 {
57         SEGPTR  s_name;         /* official service name */
58         SEGPTR  s_aliases;      /* alias list */
59         INT16   s_port;         /* port # */
60         SEGPTR  s_proto;        /* protocol to use */
61 } _ws_servent;
62
63 typedef struct ws_netent
64 {
65         SEGPTR  n_name;         /* official name of net */
66         SEGPTR  n_aliases;      /* alias list */
67         INT16   n_addrtype;     /* net address type */
68         INT   n_net;          /* network # */
69 } _ws_netent;
70
71 typedef struct sockaddr         ws_sockaddr;
72
73 typedef struct
74 {
75         UINT16    fd_count;               /* how many are SET? */
76         SOCKET16  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
77 } ws_fd_set16;
78
79 typedef struct
80 {
81         UINT    fd_count;               /* how many are SET? */
82         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
83 } ws_fd_set32;
84
85 /* ws_fd_set operations */
86
87 INT16 WINAPI __WSAFDIsSet16( SOCKET16, ws_fd_set16 * );
88 INT WINAPI __WSAFDIsSet( SOCKET, ws_fd_set32 * );
89
90 #define __WS_FD_CLR(fd, set, cast) do { \
91     UINT16 __i; \
92     for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
93     { \
94         if (((cast*)(set))->fd_array[__i] == fd) \
95         { \
96             while (__i < ((cast*)(set))->fd_count-1) \
97             { \
98                 ((cast*)(set))->fd_array[__i] = \
99                     ((cast*)(set))->fd_array[__i+1]; \
100                 __i++; \
101             } \
102             ((cast*)(set))->fd_count--; \
103             break; \
104         } \
105     } \
106 } while(0)
107 #define WS_FD_CLR16(fd, set)    __WS_FD_CLR((fd),(set), ws_fd_set16)
108 #define WS_FD_CLR(fd, set)      __WS_FD_CLR((fd),(set), ws_fd_set32)
109
110 #define __WS_FD_SET(fd, set, cast) do { \
111     if (((cast*)(set))->fd_count < FD_SETSIZE) \
112         ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd);\
113 } while(0)
114 #define WS_FD_SET16(fd, set)    __WS_FD_SET((fd),(set), ws_fd_set16)
115 #define WS_FD_SET(fd, set)    __WS_FD_SET((fd),(set), ws_fd_set32)
116
117 #define WS_FD_ZERO16(set) (((ws_fd_set16*)(set))->fd_count=0)
118 #define WS_FD_ZERO(set) (((ws_fd_set32*)(set))->fd_count=0)
119
120 #define WS_FD_ISSET16(fd, set) __WSAFDIsSet16((SOCKET16)(fd), (ws_fd_set16*)(set))
121 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (ws_fd_set32*)(set))
122
123 /* 
124  * Internet address (old style... should be updated) 
125  */
126
127 struct ws_in_addr
128 {
129         union {
130                 struct { BYTE   s_b1,s_b2,s_b3,s_b4; } S_un_b;
131                 struct { UINT16 s_w1,s_w2; } S_un_w;
132                 UINT S_addr;
133         } S_un;
134 #define ws_addr  S_un.S_addr            /* can be used for most tcp & ip code */
135 #define ws_host  S_un.S_un_b.s_b2       /* host on imp */
136 #define ws_net   S_un.S_un_b.s_b1       /* network */
137 #define ws_imp   S_un.S_un_w.s_w2       /* imp */
138 #define ws_impno S_un.S_un_b.s_b4       /* imp # */
139 #define ws_lh    S_un.S_un_b.s_b3       /* logical host */
140 };
141
142 struct ws_sockaddr_in
143 {
144         INT16           sin_family;
145         UINT16          sin_port;
146         struct ws_in_addr sin_addr;
147         BYTE            sin_zero[8];
148 };
149
150 #define WSADESCRIPTION_LEN      256
151 #define WSASYS_STATUS_LEN       128
152
153 typedef struct WSAData {
154         WORD                    wVersion;
155         WORD                    wHighVersion;
156         char                    szDescription[WSADESCRIPTION_LEN+1];
157         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
158         UINT16                  iMaxSockets;
159         UINT16                  iMaxUdpDg;
160         SEGPTR                  lpVendorInfo;
161 } WSADATA, *LPWSADATA;
162
163 #pragma pack(4)
164
165 /* ----------------------------------- no Win16 structure defs beyond this line! */
166
167 /*
168  * This is used instead of -1, since the
169  * SOCKET type is unsigned.
170  */
171 #define INVALID_SOCKET16           (~0)
172 #define INVALID_SOCKET     (~0)
173 #define SOCKET_ERROR               (-1)
174
175
176 /*
177  * Types
178  */
179 #define WS_SOCK_STREAM     1               /* stream socket */
180 #define WS_SOCK_DGRAM      2               /* datagram socket */
181 #define WS_SOCK_RAW        3               /* raw-protocol interface */
182 #define WS_SOCK_RDM        4               /* reliably-delivered message */
183 #define WS_SOCK_SEQPACKET  5               /* sequenced packet stream */
184
185 #define WS_SOL_SOCKET           0xffff
186 #define WS_IPPROTO_TCP          6
187
188 /*
189  * Option flags per-socket.
190  */
191 #define WS_SO_DEBUG        0x0001          /* turn on debugging info recording */
192 #define WS_SO_ACCEPTCONN   0x0002          /* socket has had listen() */
193 #define WS_SO_REUSEADDR    0x0004          /* allow local address reuse */
194 #define WS_SO_KEEPALIVE    0x0008          /* keep connections alive */
195 #define WS_SO_DONTROUTE    0x0010          /* just use interface addresses */
196 #define WS_SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
197 #define WS_SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
198 #define WS_SO_LINGER       0x0080          /* linger on close if data present */
199 #define WS_SO_OOBINLINE    0x0100          /* leave received OOB data in line */
200
201 #define WS_SO_DONTLINGER   (UINT)(~WS_SO_LINGER)
202
203 /*
204  * Additional options.
205  */
206 #define WS_SO_SNDBUF       0x1001          /* send buffer size */
207 #define WS_SO_RCVBUF       0x1002          /* receive buffer size */
208 #define WS_SO_SNDLOWAT     0x1003          /* send low-water mark */
209 #define WS_SO_RCVLOWAT     0x1004          /* receive low-water mark */
210 #define WS_SO_SNDTIMEO     0x1005          /* send timeout */
211 #define WS_SO_RCVTIMEO     0x1006          /* receive timeout */
212 #define WS_SO_ERROR        0x1007          /* get error status and clear */
213 #define WS_SO_TYPE         0x1008          /* get socket type */
214
215 #define WS_IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
216 #define WS_IOC_VOID        0x20000000      /* no parameters */
217 #define WS_IOC_OUT         0x40000000      /* copy out parameters */
218 #define WS_IOC_IN          0x80000000      /* copy in parameters */
219 #define WS_IOC_INOUT       (WS_IOC_IN|WS_IOC_OUT)
220 #define WS_IOR(x,y,t)      (WS_IOC_OUT|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
221 #define WS_IOW(x,y,t)      (WS_IOC_IN|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
222
223 /*
224  * Socket I/O flags (supported by spec 1.1)
225  */
226
227 #define WS_FIONREAD    WS_IOR('f', 127, u_long)
228 #define WS_FIONBIO     WS_IOW('f', 126, u_long)
229
230 #define WS_SIOCATMARK  WS_IOR('s',  7, u_long)
231
232 /*
233  * Maximum queue length specifiable by listen.
234  */
235 #ifdef SOMAXCONN
236 #undef SOMAXCONN
237 #endif
238 #define SOMAXCONN       5
239
240 #ifndef MSG_DONTROUTE
241 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
242 #endif
243 #define MSG_MAXIOVLEN   16
244
245 /*
246  * Define constant based on rfc883, used by gethostbyxxxx() calls.
247  */
248 #define MAXGETHOSTSTRUCT        1024
249
250 /*
251  * Define flags to be used with the WSAAsyncSelect() call.
252  */
253 #define WS_FD_READ         0x0001
254 #define WS_FD_WRITE        0x0002
255 #define WS_FD_OOB          0x0004
256 #define WS_FD_ACCEPT       0x0008
257 #define WS_FD_CONNECT      0x0010
258 #define WS_FD_CLOSE        0x0020
259
260 #define WS_FD_LISTENING    0x10000000   /* internal per-socket flags */
261 #define WS_FD_INACTIVE     0x20000000
262 #define WS_FD_CONNECTED    0x40000000
263 #define WS_FD_RAW          0x80000000
264 #define WS_FD_INTERNAL     0xFFFF0000
265
266 /*
267  * All Windows Sockets error constants are biased by WSABASEERR from
268  * the "normal"
269  */
270 #define WSABASEERR              10000
271 /*
272  * Windows Sockets definitions of regular Microsoft C error constants
273  */
274 #define WSAEINTR                (WSABASEERR+4)
275 #define WSAEBADF                (WSABASEERR+9)
276 #define WSAEACCES               (WSABASEERR+13)
277 #define WSAEFAULT               (WSABASEERR+14)
278 #define WSAEINVAL               (WSABASEERR+22)
279 #define WSAEMFILE               (WSABASEERR+24)
280
281 /*
282  * Windows Sockets definitions of regular Berkeley error constants
283  */
284 #define WSAEWOULDBLOCK          (WSABASEERR+35)
285 #define WSAEINPROGRESS          (WSABASEERR+36)
286 #define WSAEALREADY             (WSABASEERR+37)
287 #define WSAENOTSOCK             (WSABASEERR+38)
288 #define WSAEDESTADDRREQ         (WSABASEERR+39)
289 #define WSAEMSGSIZE             (WSABASEERR+40)
290 #define WSAEPROTOTYPE           (WSABASEERR+41)
291 #define WSAENOPROTOOPT          (WSABASEERR+42)
292 #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
293 #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
294 #define WSAEOPNOTSUPP           (WSABASEERR+45)
295 #define WSAEPFNOSUPPORT         (WSABASEERR+46)
296 #define WSAEAFNOSUPPORT         (WSABASEERR+47)
297 #define WSAEADDRINUSE           (WSABASEERR+48)
298 #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
299 #define WSAENETDOWN             (WSABASEERR+50)
300 #define WSAENETUNREACH          (WSABASEERR+51)
301 #define WSAENETRESET            (WSABASEERR+52)
302 #define WSAECONNABORTED         (WSABASEERR+53)
303 #define WSAECONNRESET           (WSABASEERR+54)
304 #define WSAENOBUFS              (WSABASEERR+55)
305 #define WSAEISCONN              (WSABASEERR+56)
306 #define WSAENOTCONN             (WSABASEERR+57)
307 #define WSAESHUTDOWN            (WSABASEERR+58)
308 #define WSAETOOMANYREFS         (WSABASEERR+59)
309 #define WSAETIMEDOUT            (WSABASEERR+60)
310 #define WSAECONNREFUSED         (WSABASEERR+61)
311 #define WSAELOOP                (WSABASEERR+62)
312 #define WSAENAMETOOLONG         (WSABASEERR+63)
313 #define WSAEHOSTDOWN            (WSABASEERR+64)
314 #define WSAEHOSTUNREACH         (WSABASEERR+65)
315 #define WSAENOTEMPTY            (WSABASEERR+66)
316 #define WSAEPROCLIM             (WSABASEERR+67)
317 #define WSAEUSERS               (WSABASEERR+68)
318 #define WSAEDQUOT               (WSABASEERR+69)
319 #define WSAESTALE               (WSABASEERR+70)
320 #define WSAEREMOTE              (WSABASEERR+71)
321
322 /*
323  * Extended Windows Sockets error constant definitions
324  */
325 #define WSASYSNOTREADY          (WSABASEERR+91)
326 #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
327 #define WSANOTINITIALISED       (WSABASEERR+93)
328
329 /*
330  * Error return codes from gethostbyname() and gethostbyaddr()
331  * (when using the resolver). Note that these errors are
332  * retrieved via WSAGetLastError() and must therefore follow
333  * the rules for avoiding clashes with error numbers from
334  * specific implementations or language run-time systems.
335  * For this reason the codes are based at WSABASEERR+1001.
336  * Note also that [WSA]NO_ADDRESS is defined only for
337  * compatibility purposes.
338  */
339
340 /* #define h_errno         WSAGetLastError() */
341
342 /* Authoritative Answer: Host not found */
343 #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
344
345 /* Non-Authoritative: Host not found, or SERVERFAIL */
346 #define WSATRY_AGAIN            (WSABASEERR+1002)
347
348 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
349 #define WSANO_RECOVERY          (WSABASEERR+1003)
350
351 /* Valid name, no data record of requested type */
352 #define WSANO_DATA              (WSABASEERR+1004)
353
354 /* no address, look for MX record */
355 #define WSANO_ADDRESS           WSANO_DATA
356
357 /* Socket function prototypes */
358
359 #ifdef __cplusplus
360 extern "C" {
361 #endif
362
363 /* Microsoft Windows Extension function prototypes */
364
365 INT16     WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA lpWSAData);
366 INT     WINAPI WSAStartup(UINT wVersionRequired, LPWSADATA lpWSAData);
367 void      WINAPI WSASetLastError16(INT16 iError);
368 void      WINAPI WSASetLastError(INT iError);
369 INT     WINAPI WSACleanup(void);
370 INT     WINAPI WSAGetLastError(void);
371 BOOL    WINAPI WSAIsBlocking(void);
372 INT     WINAPI WSACancelBlockingCall(void);
373 INT16     WINAPI WSAUnhookBlockingHook16(void);
374 INT     WINAPI WSAUnhookBlockingHook(void);
375 FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc);
376 FARPROC WINAPI WSASetBlockingHook(FARPROC lpBlockFunc);
377
378 HANDLE16  WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 wMsg, LPCSTR name, LPCSTR proto,
379                                          SEGPTR buf, INT16 buflen);
380 HANDLE  WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, LPCSTR proto,
381                                          LPSTR sbuf, INT buflen);
382
383 HANDLE16  WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 wMsg, INT16 port,
384                                          LPCSTR proto, SEGPTR buf, INT16 buflen);
385 HANDLE  WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
386                                          LPCSTR proto, LPSTR sbuf, INT buflen);
387
388 HANDLE16  WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 wMsg,
389                                           LPCSTR name, SEGPTR buf, INT16 buflen);
390 HANDLE  WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg,
391                                           LPCSTR name, LPSTR sbuf, INT buflen);
392
393 HANDLE16  WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd, UINT16 wMsg,
394                                             INT16 number, SEGPTR buf, INT16 buflen);
395 HANDLE  WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg,
396                                             INT number, LPSTR sbuf, INT buflen);
397
398 HANDLE16  WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 wMsg,
399                                          LPCSTR name, SEGPTR buf, INT16 buflen);
400 HANDLE  WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg,
401                                          LPCSTR name, LPSTR sbuf, INT buflen);
402
403 HANDLE16  WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 wMsg, LPCSTR addr,
404                               INT16 len, INT16 type, SEGPTR buf, INT16 buflen);
405 HANDLE  WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
406                               INT len, INT type, LPSTR sbuf, INT buflen);
407
408 INT16     WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle);
409 INT     WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
410
411 INT16     WINAPI WSAAsyncSelect16(SOCKET16 s, HWND16 hWnd, UINT16 wMsg, UINT lEvent);
412 INT     WINAPI WSAAsyncSelect(SOCKET s, HWND hWnd, UINT uMsg, UINT lEvent);
413
414
415 /*
416  * Address families
417  */
418 #define WS_AF_UNSPEC       0               /* unspecified */
419 #define WS_AF_UNIX         1               /* local to host (pipes, portals) */
420 #define WS_AF_INET         2               /* internetwork: UDP, TCP, etc. */
421 #define WS_AF_IMPLINK      3               /* arpanet imp addresses */
422 #define WS_AF_PUP          4               /* pup protocols: e.g. BSP */
423 #define WS_AF_CHAOS        5               /* mit CHAOS protocols */
424 #define WS_AF_NS           6               /* XEROX NS protocols */
425 #define WS_AF_IPX          WS_AF_NS        /* IPX protocols: IPX, SPX, etc. */
426 #define WS_AF_ISO          7               /* ISO protocols */
427 #define WS_AF_OSI          AF_ISO          /* OSI is ISO */
428 #define WS_AF_ECMA         8               /* european computer manufacturers */
429 #define WS_AF_DATAKIT      9               /* datakit protocols */
430 #define WS_AF_CCITT        10              /* CCITT protocols, X.25 etc */
431 #define WS_AF_SNA          11              /* IBM SNA */
432 #define WS_AF_DECnet       12              /* DECnet */
433 #define WS_AF_DLI          13              /* Direct data link interface */
434 #define WS_AF_LAT          14              /* LAT */
435 #define WS_AF_HYLINK       15              /* NSC Hyperchannel */
436 #define WS_AF_APPLETALK    16              /* AppleTalk */
437 #define WS_AF_NETBIOS      17              /* NetBios-style addresses */
438 #define WS_AF_VOICEVIEW    18              /* VoiceView */
439 #define WS_AF_FIREFOX      19              /* Protocols from Firefox */
440 #define WS_AF_UNKNOWN1     20              /* Somebody is using this! */
441 #define WS_AF_BAN          21              /* Banyan */
442 #define WS_AF_ATM          22              /* Native ATM Services */
443 #define WS_AF_INET6        23              /* Internetwork Version 6 */
444 #define WS_AF_CLUSTER      24              /* Microsoft Wolfpack */
445 #define WS_AF_12844        25              /* IEEE 1284.4 WG AF */
446 #define WS_AF_IRDA         26              /* IrDA */
447
448 #define WS_AF_MAX          27
449
450 struct ws_sockaddr_ipx
451 {
452         INT16           sipx_family     __attribute__((packed));
453         UINT            sipx_network    __attribute__((packed));
454         CHAR            sipx_node[6]    __attribute__((packed));
455         UINT16          sipx_port       __attribute__((packed));
456 };
457
458 #ifdef __cplusplus
459 }
460 #endif
461
462 /* Microsoft Windows Extended data types */
463 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
464 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
465 typedef struct linger LINGER, *PLINGER, *LPLINGER;
466 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
467 typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
468 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
469 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
470 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
471 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
472
473 /*
474  * Windows message parameter composition and decomposition
475  * macros.
476  *
477  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
478  * when constructing the response to a WSAAsyncGetXByY() routine.
479  */
480 #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
481 /*
482  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
483  * when constructing the response to WSAAsyncSelect().
484  */
485 #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
486 /*
487  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
488  * to extract the buffer length from the lParam in the response
489  * to a WSAGetXByY().
490  */
491 #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
492 /*
493  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
494  * to extract the error code from the lParam in the response
495  * to a WSAGetXByY().
496  */
497 #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
498 /*
499  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
500  * to extract the event code from the lParam in the response
501  * to a WSAAsyncSelect().
502  */
503 #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
504 /*
505  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
506  * to extract the error code from the lParam in the response
507  * to a WSAAsyncSelect().
508  */
509 #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
510
511 /* ----------------------------------- internal structures */
512
513 /* ws_... struct conversion flags */
514
515 #define WS_DUP_LINEAR           0x0001
516 #define WS_DUP_NATIVE           0x0000          /* not used anymore */
517 #define WS_DUP_OFFSET           0x0002          /* internal pointers are offsets */
518 #define WS_DUP_SEGPTR           0x0004          /* internal pointers are SEGPTRs */
519                                                 /* by default, internal pointers are linear */
520 /* async DNS op flags */
521
522 #define AOP_IO                  0x0000001       /* aop_control paramaters */
523
524 #define AOP_CONTROL_REMOVE      0x0000000       /* aop_control return values */
525 #define AOP_CONTROL_KEEP        0x0000001
526
527 typedef struct  __aop
528 {
529   /* AOp header */
530
531   struct __aop *next, *prev;
532   int           fd[2];                          /* pipe */
533   int   (*aop_control)(struct __aop*, int);     /* SIGIO handler */
534   pid_t         pid;                            /* child process pid */
535
536   /* custom data */
537
538   HWND        hWnd;                             /* hWnd to post */ 
539   UINT        uMsg;                             /* uMsg message to. */
540
541   union 
542   {
543     SEGPTR seg_base;
544     LPSTR  lin_base;
545     void*  ptr_base;
546   }             b;                              /* buffer to copy result to */
547
548   UINT        buflen;
549   UINT  flags;                          /* WSMSG_ASYNC_... */
550 } ws_async_op;
551
552 #define WSMSG_ASYNC_HOSTBYNAME  0x0001
553 #define WSMSG_ASYNC_HOSTBYADDR  0x0002
554 #define WSMSG_ASYNC_PROTOBYNAME 0x0010
555 #define WSMSG_ASYNC_PROTOBYNUM  0x0020
556 #define WSMSG_ASYNC_SERVBYNAME  0x0100
557 #define WSMSG_ASYNC_SERVBYPORT  0x0200
558 #define WSMSG_ASYNC_RQMASK      0x0fff
559
560 #define WSMSG_WIN32_AOP         0x1000
561 #define WSMSG_DEAD_AOP          0x8000
562
563 typedef struct __sop    /* WSAAsyncSelect() control struct */
564 {
565   struct __sop *next, *prev;
566
567   struct __ws*  pws;
568   HWND        hWnd;
569   UINT        uMsg;
570 } ws_select_op;
571
572 typedef struct  __ws    /* socket */
573 {
574   int           fd;
575   unsigned      flags;
576   ws_select_op* psop;
577 } ws_socket;
578
579 #define WS_MAX_SOCKETS_PER_PROCESS      16
580 #define WS_MAX_UDP_DATAGRAM             1024
581
582 #define WSI_BLOCKINGCALL        0x00000001      /* per-thread info flags */
583 #define WSI_BLOCKINGHOOK        0x00000002      /* 32-bit callback */
584
585 typedef struct _WSINFO
586 {
587   struct _WSINFO*       prev,*next;
588
589   unsigned              flags;
590   INT                   err;                    /* WSAGetLastError() return value */
591   INT16                 num_startup;            /* reference counter */
592   INT16                 num_async_rq;
593   INT16                 last_free;              /* entry in the socket table */
594   UINT16                buflen;
595   char*                 buffer;                 /* allocated from SEGPTR heap */
596   struct ws_hostent     *he;
597   int                   helen;
598   struct ws_servent     *se;
599   int                   selen;
600   struct ws_protoent    *pe;
601   int                   pelen;
602   char*                 dbuffer;                /* buffer for dummies (32 bytes) */
603
604   ws_socket             sock[WS_MAX_SOCKETS_PER_PROCESS];
605   DWORD                 blocking_hook;
606   HTASK16               tid;                    /* owning task id - process might be better */
607 } WSINFO, *LPWSINFO;
608
609 /* function prototypes */
610 int WS_dup_he(LPWSINFO pwsi, struct hostent* p_he, int flag);
611 int WS_dup_pe(LPWSINFO pwsi, struct protoent* p_pe, int flag);
612 int WS_dup_se(LPWSINFO pwsi, struct servent* p_se, int flag);
613
614 void WS_do_async_gethost(LPWSINFO, unsigned);
615 void WS_do_async_getproto(LPWSINFO, unsigned);
616 void WS_do_async_getserv(LPWSINFO, unsigned);
617
618 /* winsock_dns.c */
619 extern HANDLE16 __WSAsyncDBQuery(LPWSINFO pwsi, HWND hWnd, UINT uMsg, 
620     INT type, LPCSTR init, INT len, LPCSTR proto, void* sbuf, 
621     INT buflen, UINT flag);
622
623 int WINSOCK_async_io(int fd, int async);
624 int WINSOCK_unblock_io(int fd, int noblock);
625
626 int  WINSOCK_check_async_op(ws_async_op* p_aop);
627 void WINSOCK_link_async_op(ws_async_op* p_aop);
628 void WINSOCK_unlink_async_op(ws_async_op* p_aop);
629 int  WINSOCK_cancel_async_op(ws_async_op* p_aop);
630
631 void WINSOCK_cancel_task_aops(HTASK16, void (*__memfree)(void*) );
632
633 BOOL WINSOCK_HandleIO(int* fd_max, int num_pending, fd_set pending_set[3], fd_set master_set[3] );
634 void   WINSOCK_Shutdown(void);
635 UINT16 wsaErrno(void);
636 UINT16 wsaHerrno(void);
637
638 extern INT WINSOCK_DeleteTaskWSI( TDB* pTask, struct _WSINFO* );
639
640 #endif  /* _WINSOCKAPI_ */
641