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