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