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