Use the right buffer size in SYSPARAMS_Load instead of some random
[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  * Copyright (C) the Wine project
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifdef __WINESRC__
24 # ifndef __WINE_WINSOCK2__
25 #  error Please use Winsock2 in Wine
26 # endif
27 #endif
28
29 #ifndef __WINESRC__
30 # include "windows.h"
31 #else
32 # include "windef.h"
33 #endif
34
35 #ifndef _WINSOCKAPI_
36 #define _WINSOCKAPI_
37
38 /*
39  * Setup phase
40  */
41
42 #ifdef USE_WS_PREFIX
43 # define WS(x)    WS_##x
44 #else
45 # define WS(x)    x
46 #endif
47
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif /* defined(__cplusplus) */
52
53 /* proper 4-byte packing */
54 #include "pshpack4.h"
55
56 /*
57  * This section defines the items that conflict with the Unix headers.
58  */
59
60 #include <sys/types.h>
61 /* On FreeBSD we may get macros and prototypes for htonl & co.
62  * This means the functions will not be called because of the macros.
63  * So this should not harm us too much unless we try to define our own
64  * prototypes (different calling convention).
65  */
66 #if defined(USE_WS_PREFIX) || !defined(htonl)
67 # define WS_DEFINE_HTONL
68 #endif /* htonl */
69
70
71
72 /*
73  * Address families
74  */
75 #ifndef USE_WS_PREFIX
76 #define AF_UNSPEC                  0
77 #define AF_UNIX                    1
78 #define AF_INET                    2
79 #define AF_IMPLINK                 3
80 #define AF_PUP                     4
81 #define AF_CHAOS                   5
82 #define AF_NS                      6
83 #define AF_IPX                     AF_NS
84 #define AF_ISO                     7
85 #define AF_OSI                     AF_ISO
86 #define AF_ECMA                    8
87 #define AF_DATAKIT                 9
88 #define AF_CCITT                   10
89 #define AF_SNA                     11
90 #define AF_DECnet                  12
91 #define AF_DLI                     13
92 #define AF_LAT                     14
93 #define AF_HYLINK                  15
94 #define AF_APPLETALK               16
95 #define AF_NETBIOS                 17
96 #define AF_VOICEVIEW               18
97 #define AF_FIREFOX                 19
98 #define AF_UNKNOWN1                20
99 #define AF_BAN                     21
100 #define AF_ATM                     22
101 #define AF_INET6                   23
102 #define AF_CLUSTER                 24
103 #define AF_12844                   25
104 #define AF_IRDA                    26
105 #define AF_MAX                     27
106 #define PF_UNSPEC                  AF_UNSPEC
107 #define PF_UNIX                    AF_UNIX
108 #define PF_INET                    AF_INET
109 #define PF_IMPLINK                 AF_IMPLINK
110 #define PF_PUP                     AF_PUP
111 #define PF_CHAOS                   AF_CHAOS
112 #define PF_NS                      AF_NS
113 #define PF_IPX                     AF_IPX
114 #define PF_ISO                     AF_ISO
115 #define PF_OSI                     AF_OSI
116 #define PF_ECMA                    AF_ECMA
117 #define PF_DATAKIT                 AF_DATAKIT
118 #define PF_CCITT                   AF_CCITT
119 #define PF_SNA                     AF_SNA
120 #define PF_DECnet                  AF_DECnet
121 #define PF_DLI                     AF_DLI
122 #define PF_LAT                     AF_LAT
123 #define PF_HYLINK                  AF_HYLINK
124 #define PF_APPLETALK               AF_APPLETALK
125 #define PF_VOICEVIEW               AF_VOICEVIEW
126 #define PF_FIREFOX                 AF_FIREFOX
127 #define PF_UNKNOWN1                AF_UNKNOWN1
128 #define PF_BAN                     AF_BAN
129 #define PF_MAX                     AF_MAX
130 #else /* USE_WS_PREFIX */
131 #define WS_AF_UNSPEC               0
132 #define WS_AF_UNIX                 1
133 #define WS_AF_INET                 2
134 #define WS_AF_IMPLINK              3
135 #define WS_AF_PUP                  4
136 #define WS_AF_CHAOS                5
137 #define WS_AF_NS                   6
138 #define WS_AF_IPX                  WS_AF_NS
139 #define WS_AF_ISO                  7
140 #define WS_AF_OSI                  AF_ISO
141 #define WS_AF_ECMA                 8
142 #define WS_AF_DATAKIT              9
143 #define WS_AF_CCITT                10
144 #define WS_AF_SNA                  11
145 #define WS_AF_DECnet               12
146 #define WS_AF_DLI                  13
147 #define WS_AF_LAT                  14
148 #define WS_AF_HYLINK               15
149 #define WS_AF_APPLETALK            16
150 #define WS_AF_NETBIOS              17
151 #define WS_AF_VOICEVIEW            18
152 #define WS_AF_FIREFOX              19
153 #define WS_AF_UNKNOWN1             20
154 #define WS_AF_BAN                  21
155 #define WS_AF_ATM                  22
156 #define WS_AF_INET6                23
157 #define WS_AF_CLUSTER              24
158 #define WS_AF_12844                25
159 #define WS_AF_IRDA                 26
160 #define WS_AF_MAX                  27
161 #endif /* USE_WS_PREFIX */
162
163 /*
164  * Types
165  */
166 #ifndef USE_WS_PREFIX
167 #define SOCK_STREAM                1
168 #define SOCK_DGRAM                 2
169 #define SOCK_RAW                   3
170 #define SOCK_RDM                   4
171 #define SOCK_SEQPACKET             5
172 #else /* USE_WS_PREFIX */
173 #define WS_SOCK_STREAM             1
174 #define WS_SOCK_DGRAM              2
175 #define WS_SOCK_RAW                3
176 #define WS_SOCK_RDM                4
177 #define WS_SOCK_SEQPACKET          5
178 #endif /* USE_WS_PREFIX */
179
180
181 /*
182  * Protocols
183  */
184 #ifndef USE_WS_PREFIX
185 #define IPPROTO_IP                 0
186 #define IPPROTO_ICMP               1
187 #define IPPROTO_IGMP               2
188 #define IPPROTO_GGP                3
189 #define IPPROTO_TCP                6
190 #define IPPROTO_UDP                17
191 #define IPPROTO_IDP                22
192 #define IPPROTO_ND                 77
193 #define IPPROTO_RAW                255
194 #define IPPROTO_MAX                256
195 #else /* USE_WS_PREFIX */
196 #define WS_IPPROTO_IP              0
197 #define WS_IPPROTO_ICMP            1
198 #define WS_IPPROTO_IGMP            2
199 #define WS_IPPROTO_GGP             3
200 #define WS_IPPROTO_TCP             6
201 #define WS_IPPROTO_UDP             17
202 #define WS_IPPROTO_IDP             22
203 #define WS_IPPROTO_ND              77
204 #define WS_IPPROTO_RAW             255
205 #define WS_IPPROTO_MAX             256
206 #endif /* USE_WS_PREFIX */
207
208 typedef struct WS(protoent)
209 {
210     char* p_name;
211     char** p_aliases;
212     short p_proto;
213 } PROTOENT, *PPROTOENT, *LPPROTOENT;
214
215
216
217 /*
218  * Networks
219  */
220 struct WS(netent)
221 {
222     char* n_name;                  /* official name of net */
223     char** n_aliases;              /* alias list */
224     short n_addrtype;              /* net address type */
225     u_long n_net;              /* network # */
226 };
227
228
229 /*
230  * Services
231  */
232 #ifndef USE_WS_PREFIX
233 #define IPPORT_ECHO                7
234 #define IPPORT_DISCARD             9
235 #define IPPORT_SYSTAT              11
236 #define IPPORT_DAYTIME             13
237 #define IPPORT_NETSTAT             15
238 #define IPPORT_FTP                 21
239 #define IPPORT_TELNET              23
240 #define IPPORT_SMTP                25
241 #define IPPORT_TIMESERVER          37
242 #define IPPORT_NAMESERVER          42
243 #define IPPORT_WHOIS               43
244 #define IPPORT_MTP                 57
245 #define IPPORT_TFTP                69
246 #define IPPORT_RJE                 77
247 #define IPPORT_FINGER              79
248 #define IPPORT_TTYLINK             87
249 #define IPPORT_SUPDUP              95
250 #define IPPORT_EXECSERVER          512
251 #define IPPORT_LOGINSERVER         513
252 #define IPPORT_CMDSERVER           514
253 #define IPPORT_EFSSERVER           520
254 #define IPPORT_BIFFUDP             512
255 #define IPPORT_WHOSERVER           513
256 #define IPPORT_ROUTESERVER         520
257 #define IPPORT_RESERVED            1024
258 #else /* USE_WS_PREFIX */
259 #define WS_IPPORT_ECHO             7
260 #define WS_IPPORT_DISCARD          9
261 #define WS_IPPORT_SYSTAT           11
262 #define WS_IPPORT_DAYTIME          13
263 #define WS_IPPORT_NETSTAT          15
264 #define WS_IPPORT_FTP              21
265 #define WS_IPPORT_TELNET           23
266 #define WS_IPPORT_SMTP             25
267 #define WS_IPPORT_TIMESERVER       37
268 #define WS_IPPORT_NAMESERVER       42
269 #define WS_IPPORT_WHOIS            43
270 #define WS_IPPORT_MTP              57
271 #define WS_IPPORT_TFTP             69
272 #define WS_IPPORT_RJE              77
273 #define WS_IPPORT_FINGER           79
274 #define WS_IPPORT_TTYLINK          87
275 #define WS_IPPORT_SUPDUP           95
276 #define WS_IPPORT_EXECSERVER       512
277 #define WS_IPPORT_LOGINSERVER      513
278 #define WS_IPPORT_CMDSERVER        514
279 #define WS_IPPORT_EFSSERVER        520
280 #define WS_IPPORT_BIFFUDP          512
281 #define WS_IPPORT_WHOSERVER        513
282 #define WS_IPPORT_ROUTESERVER      520
283 #define WS_IPPORT_RESERVED         1024
284 #endif /* USE_WS_PREFIX */
285
286 typedef struct WS(servent)
287 {
288     char* s_name;                  /* official service name */
289     char** s_aliases;              /* alias list */
290     short s_port;                  /* port # */
291     char* s_proto;                 /* protocol to use */
292 } SERVENT, *PSERVENT, *LPSERVENT;
293
294
295
296 /*
297  * Hosts
298  */
299
300 typedef struct WS(hostent)
301 {
302     char* h_name;                  /* official name of host */
303     char** h_aliases;              /* alias list */
304     short h_addrtype;              /* host address type */
305     short h_length;                /* length of address */
306     char** h_addr_list;            /* list of addresses from name server */
307 #define h_addr h_addr_list[0]      /* address, for backward compat */
308 } HOSTENT, *PHOSTENT, *LPHOSTENT;
309
310
311 /*
312  * Sockets
313  */
314
315 typedef UINT_PTR SOCKET;
316
317 /*
318  * This is used instead of -1, since the
319  * SOCKET type is unsigned.
320  */
321 #define INVALID_SOCKET             (~0)
322 #define SOCKET_ERROR               (-1)
323
324 typedef struct WS(sockaddr)
325 {
326         u_short sa_family;
327         char    sa_data[14];
328 } SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
329
330 typedef struct WS(linger)
331 {
332     u_short l_onoff;           /* option on/off */
333     u_short l_linger;          /* linger time */
334 } LINGER, *PLINGER, *LPLINGER;
335
336 /*
337  * Select
338  */
339
340 #if !defined(USE_WS_PREFIX) && !defined(__WINE_USE_MSVCRT)
341 /* We are not using the WS_ prefix and not using the MSVCRT either so we
342  * risk getting conflicts for everything related to select.
343  */
344 # ifdef FD_CLR
345 /* Too late, the Unix version of stdlib.h was included before winsock.h.
346  * This means select and all the related stuff is already defined and we
347  * cannot override types and function prototypes.
348  * All we can do is disable all these symbols so that they are not used
349  * inadvertantly.
350  */
351 #  undef FD_SETSIZE
352 #  undef FD_CLR
353 #  undef FD_SET
354 #  undef FD_ZERO
355 #  undef FD_ISSET
356
357 #  define FD_SETSIZE Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
358 #  define FD_CLR     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
359 #  define FD_SET     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
360 #  define FD_ZERO    Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
361 #  define FD_ISSET   Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
362 #  define fd_set     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
363 #  define select     Include_winsock_h_before_stdlib_h_or_use_the_MSVCRT_library
364 # else
365 /* stdlib.h has not been included yet so it's not too late. Include it now
366  * making sure that none of the select symbols is affected. Then we can
367  * define them with our own values.
368  */
369 #  define fd_set unix_fd_set
370 #  define timeval unix_timeval
371 #  define select unix_select
372 #  include <stdlib.h>
373 #  undef fd_set
374 #  undef timeval
375 #  undef select
376 #  undef FD_SETSIZE
377 #  undef FD_CLR
378 #  undef FD_SET
379 #  undef FD_ZERO
380 #  undef FD_ISSET
381
382 #  define WS_DEFINE_SELECT
383 # endif /* FD_CLR */
384
385 #else
386 # define WS_DEFINE_SELECT
387 #endif /* !USE_WS_PREFIX && !__WINE_USE_MSVCRT */
388
389 #ifdef WS_DEFINE_SELECT
390 /* Define our own version of select and the associated types and macros */
391
392 # ifndef USE_WS_PREFIX
393 #  ifndef FD_SETSIZE
394 #   define FD_SETSIZE              64
395 #  endif
396 # else
397 #  ifndef WS_FD_SETSIZE
398 #   define WS_FD_SETSIZE           64
399 #  endif
400 # endif
401
402 typedef struct WS(fd_set)
403 {
404     u_int fd_count;            /* how many are SET? */
405 # ifndef USE_WS_PREFIX
406     SOCKET fd_array[FD_SETSIZE];   /* an array of SOCKETs */
407 # else
408     SOCKET fd_array[WS_FD_SETSIZE];/* an array of SOCKETs */
409 # endif
410 } WS(fd_set), FD_SET, *PFD_SET, *LPFD_SET;
411
412 typedef struct WS(timeval)
413 {
414     long    tv_sec;                /* seconds */
415     long    tv_usec;               /* and microseconds */
416 } TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
417
418 #define WINE_FD_CLR(fd, set, cast) do { \
419     u_int __i; \
420     for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
421     { \
422         if (((cast*)(set))->fd_array[__i] == fd) \
423         { \
424             while (__i < ((cast*)(set))->fd_count-1) \
425             { \
426                 ((cast*)(set))->fd_array[__i] = \
427                     ((cast*)(set))->fd_array[__i+1]; \
428                 __i++; \
429             } \
430             ((cast*)(set))->fd_count--; \
431             break; \
432         } \
433     } \
434 } while(0)
435 #define __WS_FD_SET1(fd, set, cast) do { \
436     if (((cast*)(set))->fd_count < FD_SETSIZE) \
437         ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd); \
438 } while(0)
439 /* This version checks if the filedesc is already in the list, and appends it
440  * only if it's not the case
441  */
442 #define __WS_FD_SET2(fd, set, cast) do { \
443     u_int __i; \
444     for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
445     { \
446         if (((cast*)(set))->fd_array[__i]==(fd)) \
447             break; \
448     } \
449     if (__i == ((cast*)(set))->fd_count && ((cast*)(set))->fd_count < FD_SETSIZE) \
450     { \
451         ((cast*)(set))->fd_count++; \
452         ((cast*)(set))->fd_array[__i]=(fd);\
453     } \
454 } while(0)
455
456 #ifndef __WINE_WINSOCK2__
457 #define __WS_FD_SET(fd, set, cast) __WS_FD_SET1((fd),(set), cast)
458 #else
459 #define __WS_FD_SET(fd, set, cast) __WS_FD_SET2((fd),(set), cast)
460 #endif
461
462 #ifndef USE_WS_PREFIX
463 #define FD_CLR(fd, set)      __WS_FD_CLR((fd),(set), fd_set)
464 #define FD_SET(fd, set)      __WS_FD_SET((fd),(set), fd_set)
465 #define FD_ZERO(set)         (((fd_set*)(set))->fd_count=0)
466 #define FD_ISSET(fd, set)    __WSAFDIsSet((SOCKET)(fd), (fd_set*)(set))
467 #else
468 #define WS_FD_CLR(fd, set)   WINE_FD_CLR((fd),(set), WS_fd_set)
469 #define WS_FD_SET(fd, set)   WINE_FD_SET((fd),(set), WS_fd_set)
470 #define WS_FD_ZERO(set)      ((WS_fd_set*)(set))->fd_count=0)
471 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (WS_fd_set*)(set))
472 #endif
473 #endif /* WS_DEFINE_SELECT */
474
475
476 /*
477  * Internet address (old style... should be updated)
478  */
479
480 #ifndef USE_WS_PREFIX
481 #define IN_CLASSA_NSHIFT           24
482 #define IN_CLASSA_MAX              128
483 #define IN_CLASSA_NET              0xff000000
484 #define IN_CLASSA_HOST             0x00ffffff
485 #define IN_CLASSA(i)               (((long)(i) & 0x80000000) == 0)
486 #define IN_CLASSB_NSHIFT           16
487 #define IN_CLASSB_MAX              65536
488 #define IN_CLASSB_NET              0xffff0000
489 #define IN_CLASSB_HOST             0x0000ffff
490 #define IN_CLASSB(i)               (((long)(i) & 0xc0000000) == 0x80000000)
491 #define IN_CLASSC_NSHIFT           8
492 #define IN_CLASSC_NET              0xffffff00
493 #define IN_CLASSC_HOST             0x000000ff
494 #define IN_CLASSC(i)               (((long)(i) & 0xe0000000) == 0xc0000000)
495 #else
496 #define WS_IN_CLASSA_NSHIFT        24
497 #define WS_IN_CLASSA_MAX           128
498 #define WS_IN_CLASSA_NET           0xff000000
499 #define WS_IN_CLASSA_HOST          0x00ffffff
500 #define WS_IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
501 #define WS_IN_CLASSB_NSHIFT        16
502 #define WS_IN_CLASSB_MAX           65536
503 #define WS_IN_CLASSB_NET           0xffff0000
504 #define WS_IN_CLASSB_HOST          0x0000ffff
505 #define WS_IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
506 #define WS_IN_CLASSC_NSHIFT        8
507 #define WS_IN_CLASSC_NET           0xffffff00
508 #define WS_IN_CLASSC_HOST          0x000000ff
509 #define WS_IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
510 #endif /* USE_WS_PREFIX */
511
512 #ifndef USE_WS_PREFIX
513 #define INADDR_ANY                 (u_long)0x00000000
514 #define INADDR_LOOPBACK            0x7f000001
515 #define INADDR_BROADCAST           (u_long)0xffffffff
516 #define INADDR_NONE                0xffffffff
517 #else
518 #define WS_INADDR_ANY              (u_long)0x00000000
519 #define WS_INADDR_LOOPBACK         0x7f000001
520 #define WS_INADDR_BROADCAST        (u_long)0xffffffff
521 #define WS_INADDR_NONE             0xffffffff
522 #endif /* USE_WS_PREFIX */
523
524 typedef struct WS(in_addr)
525 {
526     union {
527         struct {
528             u_char s_b1,s_b2,s_b3,s_b4;
529         } S_un_b;
530         struct {
531             u_short s_w1,s_w2;
532         } S_un_w;
533         u_long S_addr;
534     } S_un;
535 #ifndef USE_WS_PREFIX
536 #define s_addr  S_un.S_addr
537 #define s_host  S_un.S_un_b.s_b2
538 #define s_net   S_un.S_un_b.s_b1
539 #define s_imp   S_un.S_un_w.s_w2
540 #define s_impno S_un.S_un_b.s_b4
541 #define s_lh    S_un.S_un_b.s_b3
542 #else
543 #define WS_s_addr  S_un.S_addr
544 #define WS_s_host  S_un.S_un_b.s_b2
545 #define WS_s_net   S_un.S_un_b.s_b1
546 #define WS_s_imp   S_un.S_un_w.s_w2
547 #define WS_s_impno S_un.S_un_b.s_b4
548 #define WS_s_lh    S_un.S_un_b.s_b3
549 #endif /* USE_WS_PREFIX */
550 } IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
551
552 typedef struct WS(sockaddr_in)
553 {
554     short              sin_family;
555     u_short               sin_port;
556     struct WS(in_addr) sin_addr;
557     char               sin_zero[8];
558 } SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
559
560
561 /*
562  * WSAStartup
563  */
564 #define WSADESCRIPTION_LEN      256
565 #define WSASYS_STATUS_LEN       128
566
567 typedef struct WS(WSAData)
568 {
569     WORD                    wVersion;
570     WORD                    wHighVersion;
571     char                    szDescription[WSADESCRIPTION_LEN+1];
572     char                    szSystemStatus[WSASYS_STATUS_LEN+1];
573     WORD                    iMaxSockets;
574     WORD                    iMaxUdpDg;
575     char                   *lpVendorInfo;
576 } WSADATA, *LPWSADATA;
577
578
579
580 /*
581  * {get,set}sockopt
582  */
583 #ifndef USE_WS_PREFIX
584 #define SOL_SOCKET                 0xffff
585 #define SO_DEBUG                   0x0001
586 #define SO_ACCEPTCONN              0x0002
587 #define SO_REUSEADDR               0x0004
588 #define SO_KEEPALIVE               0x0008
589 #define SO_DONTROUTE               0x0010
590 #define SO_BROADCAST               0x0020
591 #define SO_USELOOPBACK             0x0040
592 #define SO_LINGER                  0x0080
593 #define SO_OOBINLINE               0x0100
594 #define SO_DONTLINGER              (u_int)(~SO_LINGER)
595 #define SO_SNDBUF                  0x1001
596 #define SO_RCVBUF                  0x1002
597 #define SO_SNDLOWAT                0x1003
598 #define SO_RCVLOWAT                0x1004
599 #define SO_SNDTIMEO                0x1005
600 #define SO_RCVTIMEO                0x1006
601 #define SO_ERROR                   0x1007
602 #define SO_TYPE                    0x1008
603
604
605 #define IOCPARM_MASK               0x7f
606 #define IOC_VOID                   0x20000000
607 #define IOC_OUT                    0x40000000
608 #define IOC_IN                     0x80000000
609 #define IOC_INOUT                  (IOC_IN|IOC_OUT)
610
611 #define _IO(x,y)    (IOC_VOID|((x)<<8)|(y))
612 #define _IOR(x,y,t) (IOC_OUT|(((UINT)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
613 #define _IOW(x,y,t) (IOC_IN|(((UINT)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
614
615 #else
616
617 #define WS_SOL_SOCKET              0xffff
618 #define WS_SO_DEBUG                0x0001
619 #define WS_SO_ACCEPTCONN           0x0002
620 #define WS_SO_REUSEADDR            0x0004
621 #define WS_SO_KEEPALIVE            0x0008
622 #define WS_SO_DONTROUTE            0x0010
623 #define WS_SO_BROADCAST            0x0020
624 #define WS_SO_USELOOPBACK          0x0040
625 #define WS_SO_LINGER               0x0080
626 #define WS_SO_OOBINLINE            0x0100
627 #define WS_SO_DONTLINGER           (u_int)(~WS_SO_LINGER)
628 #define WS_SO_SNDBUF               0x1001
629 #define WS_SO_RCVBUF               0x1002
630 #define WS_SO_SNDLOWAT             0x1003
631 #define WS_SO_RCVLOWAT             0x1004
632 #define WS_SO_SNDTIMEO             0x1005
633 #define WS_SO_RCVTIMEO             0x1006
634 #define WS_SO_ERROR                0x1007
635 #define WS_SO_TYPE                 0x1008
636
637 #define WS_IOCPARM_MASK            0x7f
638 #define WS_IOC_VOID                0x20000000
639 #define WS_IOC_OUT                 0x40000000
640 #define WS_IOC_IN                  0x80000000
641 #define WS_IOC_INOUT               (WS_IOC_IN|WS_IOC_OUT)
642
643 #define WS__IO(x,y)    (WS_IOC_VOID|((x)<<8)|(y))
644 #define WS__IOR(x,y,t) (WS_IOC_OUT|(((long)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
645 #define WS__IOW(x,y,t) (WS_IOC_IN|(((long)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
646
647 #endif
648
649 /* IPPROTO_TCP options */
650 #ifndef USE_WS_PREFIX
651 #define TCP_NODELAY                1
652 #else
653 #define WS_TCP_NODELAY             1
654 #endif
655
656 /*
657  * Socket I/O flags (supported by spec 1.1)
658  */
659 #ifndef USE_WS_PREFIX
660 #define FIONREAD                   _IOR('f', 127, u_long)
661 #define FIONBIO                    _IOW('f', 126, u_long)
662 #define SIOCATMARK                 _IOR('s',  7, u_long)
663 #else
664 #define WS_FIONREAD                WS__IOR('f', 127, u_long)
665 #define WS_FIONBIO                 WS__IOW('f', 126, u_long)
666 #define WS_SIOCATMARK              WS__IOR('s',  7, u_long)
667 #endif
668
669 /*
670  * Maximum queue length specifiable by listen.
671  */
672 #ifndef USE_WS_PREFIX
673 #define SOMAXCONN                  5
674
675 #define MSG_OOB                    0x0001
676 #define MSG_PEEK                   0x0002
677 #define MSG_DONTROUTE              0x0004
678 #define MSG_MAXIOVLEN              0x000a
679 #define MSG_PARTIAL                0x8000
680 #else /* USE_WS_PREFIX */
681 #define WS_SOMAXCONN               5
682
683 #define WS_MSG_OOB                 0x0001
684 #define WS_MSG_PEEK                0x0002
685 #define WS_MSG_DONTROUTE           0x0004
686 #define WS_MSG_MAXIOVLEN           0x000a
687 #define WS_MSG_PARTIAL             0x8000
688 #endif /* USE_WS_PREFIX */
689
690 /*
691  * Define constant based on rfc883, used by gethostbyxxxx() calls.
692  */
693 #ifndef USE_WS_PREFIX
694 #define MAXGETHOSTSTRUCT           1024
695 #else
696 #define MAXGETHOSTSTRUCT           1024
697 #endif
698
699
700 /*
701  * Define flags to be used with the WSAAsyncSelect() call.
702  */
703 #define FD_READ                    0x00000001
704 #define FD_WRITE                   0x00000002
705 #define FD_OOB                     0x00000004
706 #define FD_ACCEPT                  0x00000008
707 #define FD_CONNECT                 0x00000010
708 #define FD_CLOSE                   0x00000020
709
710 /* internal per-socket flags */
711 #ifdef __WINESRC__
712 #define FD_WINE_LISTENING          0x10000000
713 #define FD_WINE_NONBLOCKING        0x20000000
714 #define FD_WINE_CONNECTED          0x40000000
715 #define FD_WINE_RAW                0x80000000
716 #define FD_WINE_INTERNAL           0xFFFF0000
717 #endif
718
719 /*
720  * All Windows Sockets error constants are biased by WSABASEERR from
721  * the "normal"
722  */
723 #define WSABASEERR                 10000
724 /*
725  * Windows Sockets definitions of regular Microsoft C error constants
726  */
727 #define WSAEINTR                   (WSABASEERR+4)
728 #define WSAEBADF                   (WSABASEERR+9)
729 #define WSAEACCES                  (WSABASEERR+13)
730 #define WSAEFAULT                  (WSABASEERR+14)
731 #define WSAEINVAL                  (WSABASEERR+22)
732 #define WSAEMFILE                  (WSABASEERR+24)
733
734 /*
735  * Windows Sockets definitions of regular Berkeley error constants
736  */
737 #define WSAEWOULDBLOCK             (WSABASEERR+35)
738 #define WSAEINPROGRESS             (WSABASEERR+36)
739 #define WSAEALREADY                (WSABASEERR+37)
740 #define WSAENOTSOCK                (WSABASEERR+38)
741 #define WSAEDESTADDRREQ            (WSABASEERR+39)
742 #define WSAEMSGSIZE                (WSABASEERR+40)
743 #define WSAEPROTOTYPE              (WSABASEERR+41)
744 #define WSAENOPROTOOPT             (WSABASEERR+42)
745 #define WSAEPROTONOSUPPORT         (WSABASEERR+43)
746 #define WSAESOCKTNOSUPPORT         (WSABASEERR+44)
747 #define WSAEOPNOTSUPP              (WSABASEERR+45)
748 #define WSAEPFNOSUPPORT            (WSABASEERR+46)
749 #define WSAEAFNOSUPPORT            (WSABASEERR+47)
750 #define WSAEADDRINUSE              (WSABASEERR+48)
751 #define WSAEADDRNOTAVAIL           (WSABASEERR+49)
752 #define WSAENETDOWN                (WSABASEERR+50)
753 #define WSAENETUNREACH             (WSABASEERR+51)
754 #define WSAENETRESET               (WSABASEERR+52)
755 #define WSAECONNABORTED            (WSABASEERR+53)
756 #define WSAECONNRESET              (WSABASEERR+54)
757 #define WSAENOBUFS                 (WSABASEERR+55)
758 #define WSAEISCONN                 (WSABASEERR+56)
759 #define WSAENOTCONN                (WSABASEERR+57)
760 #define WSAESHUTDOWN               (WSABASEERR+58)
761 #define WSAETOOMANYREFS            (WSABASEERR+59)
762 #define WSAETIMEDOUT               (WSABASEERR+60)
763 #define WSAECONNREFUSED            (WSABASEERR+61)
764 #define WSAELOOP                   (WSABASEERR+62)
765 #define WSAENAMETOOLONG            (WSABASEERR+63)
766 #define WSAEHOSTDOWN               (WSABASEERR+64)
767 #define WSAEHOSTUNREACH            (WSABASEERR+65)
768 #define WSAENOTEMPTY               (WSABASEERR+66)
769 #define WSAEPROCLIM                (WSABASEERR+67)
770 #define WSAEUSERS                  (WSABASEERR+68)
771 #define WSAEDQUOT                  (WSABASEERR+69)
772 #define WSAESTALE                  (WSABASEERR+70)
773 #define WSAEREMOTE                 (WSABASEERR+71)
774 #define WSAEDISCON                 (WSABASEERR+101)
775
776 /*
777  * Extended Windows Sockets error constant definitions
778  */
779 #define WSASYSNOTREADY             (WSABASEERR+91)
780 #define WSAVERNOTSUPPORTED         (WSABASEERR+92)
781 #define WSANOTINITIALISED          (WSABASEERR+93)
782
783 /*
784  * Error return codes from gethostbyname() and gethostbyaddr()
785  * (when using the resolver). Note that these errors are
786  * retrieved via WSAGetLastError() and must therefore follow
787  * the rules for avoiding clashes with error numbers from
788  * specific implementations or language run-time systems.
789  * For this reason the codes are based at WSABASEERR+1001.
790  * Note also that [WSA]NO_ADDRESS is defined only for
791  * compatibility purposes.
792  */
793
794 #ifndef USE_WS_PREFIX
795 #define h_errno                    WSAGetLastError()
796 #else
797 #define WS_h_errno                 WSAGetLastError()
798 #endif
799
800 /* Authoritative Answer: Host not found */
801 #define WSAHOST_NOT_FOUND          (WSABASEERR+1001)
802
803 /* Non-Authoritative: Host not found, or SERVERFAIL */
804 #define WSATRY_AGAIN               (WSABASEERR+1002)
805
806 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
807 #define WSANO_RECOVERY             (WSABASEERR+1003)
808
809 /* Valid name, no data record of requested type */
810 #define WSANO_DATA                 (WSABASEERR+1004)
811
812 /* no address, look for MX record */
813 #define WSANO_ADDRESS              WSANO_DATA
814
815 #ifndef USE_WS_PREFIX
816 #define HOST_NOT_FOUND             WSAHOST_NOT_FOUND
817 #define TRY_AGAIN                  WSATRY_AGAIN
818 #define NO_RECOVERY                WSANO_RECOVERY
819 #define NO_DATA                    WSANO_DATA
820 #define NO_ADDRESS                 WSANO_ADDRESS
821 #endif /* USE_WS_PREFIX */
822
823
824
825 /*
826  * Windows message parameter composition and decomposition
827  * macros.
828  */
829
830 /*
831  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
832  * when constructing the response to a WSAAsyncGetXByY() routine.
833  */
834 #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
835 /*
836  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
837  * when constructing the response to WSAAsyncSelect().
838  */
839 #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
840 /*
841  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
842  * to extract the buffer length from the lParam in the response
843  * to a WSAGetXByY().
844  */
845 #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
846 /*
847  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
848  * to extract the error code from the lParam in the response
849  * to a WSAGetXByY().
850  */
851 #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
852 /*
853  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
854  * to extract the event code from the lParam in the response
855  * to a WSAAsyncSelect().
856  */
857 #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
858 /*
859  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
860  * to extract the error code from the lParam in the response
861  * to a WSAAsyncSelect().
862  */
863 #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
864
865
866
867 /*
868  * Prototypes
869  *
870  * Remember to keep this section in sync with the
871  * "Winsock Function Typedefs" section in winsock2.h.
872  */
873 #if !defined(__WINE_WINSOCK2__) || WS_API_PROTOTYPES
874 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND,u_int,const char*,int,int,char*,int);
875 HANDLE WINAPI WSAAsyncGetHostByName(HWND,u_int,const char*,char*,int);
876 HANDLE WINAPI WSAAsyncGetProtoByName(HWND,u_int,const char*,char*,int);
877 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND,u_int,int,char*,int);
878 HANDLE WINAPI WSAAsyncGetServByName(HWND,u_int,const char*,const char*,char*,int);
879 HANDLE WINAPI WSAAsyncGetServByPort(HWND,u_int,int,const char*,char*,int);
880 int WINAPI WSAAsyncSelect(SOCKET,HWND,u_int,long);
881 int WINAPI WSACancelAsyncRequest(HANDLE);
882 int WINAPI WSACancelBlockingCall(void);
883 int WINAPI WSACleanup(void);
884 int WINAPI WSAGetLastError(void);
885 BOOL WINAPI WSAIsBlocking(void);
886 FARPROC WINAPI WSASetBlockingHook(FARPROC);
887 void WINAPI WSASetLastError(int);
888 int WINAPI WSAStartup(WORD,LPWSADATA);
889 int WINAPI WSAUnhookBlockingHook(void);
890
891 SOCKET WINAPI WS(accept)(SOCKET,struct WS(sockaddr)*,int*);
892 int WINAPI WS(bind)(SOCKET,const struct WS(sockaddr)*,int);
893 int WINAPI WS(closesocket)(SOCKET);
894 int WINAPI WS(connect)(SOCKET,const struct WS(sockaddr)*,int);
895 struct WS(hostent)* WINAPI WS(gethostbyaddr)(const char*,int,int);
896 struct WS(hostent)* WINAPI WS(gethostbyname)(const char*);
897 /* gethostname not defined because of conflicts with unistd.h */
898 int WINAPI WS(getpeername)(SOCKET,struct WS(sockaddr)*,int*);
899 struct WS(protoent)* WINAPI WS(getprotobyname)(const char*);
900 struct WS(protoent)* WINAPI WS(getprotobynumber)(int);
901 #ifdef WS_DEFINE_SELECT
902 int WINAPI WS(select)(int,WS(fd_set)*,WS(fd_set)*,WS(fd_set)*,const struct WS(timeval)*);
903 #endif
904 struct WS(servent)* WINAPI WS(getservbyname)(const char*,const char*);
905 struct WS(servent)* WINAPI WS(getservbyport)(int,const char*);
906 int WINAPI WS(getsockname)(SOCKET,struct WS(sockaddr)*,int*);
907 int WINAPI WS(getsockopt)(SOCKET,int,int,char*,int*);
908 unsigned long WINAPI WS(inet_addr)(const char*);
909 char* WINAPI WS(inet_ntoa)(struct WS(in_addr));
910 int WINAPI WS(ioctlsocket)(SOCKET,long,u_long*);
911 int WINAPI WS(listen)(SOCKET,int);
912 int WINAPI WS(recv)(SOCKET,char*,int,int);
913 int WINAPI WS(recvfrom)(SOCKET,char*,int,int,struct WS(sockaddr)*,int*);
914 int WINAPI WS(send)(SOCKET,const char*,int,int);
915 int WINAPI WS(sendto)(SOCKET,const char*,int,int,const struct WS(sockaddr)*,int);
916 int WINAPI WS(setsockopt)(SOCKET,int,int,const char*,int);
917 int WINAPI WS(shutdown)(SOCKET,int);
918 SOCKET WINAPI WS(socket)(int,int,int);
919
920 #ifdef WS_DEFINE_HTONL
921 u_long WINAPI WS(htonl)(u_long);
922 u_short WINAPI WS(htons)(u_short);
923 u_long WINAPI WS(ntohl)(u_long);
924 u_short WINAPI WS(ntohs)(u_short);
925 #endif
926
927 #if defined(__WINESRC__) || !defined(__WINE_WINSOCK2__)
928 /* Stuff specific to winsock.h */
929
930 #include "mswsock.h"
931
932 #endif /* __WINE_WINSOCK2__ */
933 #endif /* !defined(__WINE_WINSOCK2__) || WS_API_PROTOTYPES */
934
935
936 #include "poppack.h"
937
938 #ifdef __cplusplus
939 }
940 #endif
941
942 #ifndef __WINE_WINSOCK2__
943 #undef WS
944 #undef WS_API_PROTOTYPES
945 #undef WS_API_TYPEDEFS
946 #endif
947
948 #endif  /* _WINSOCKAPI_ */