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