OSDN Git Service

Clean up winsock default version selection stratagem.
[mingw/mingw-org-wsl.git] / w32api / include / winsock.h
1 /*
2  * winsock.h
3  *
4  * Definitions for WinSock Version 1.1 API; also includes a subset of the
5  * definitions which become applicable for WinSock Version 2, filtered such
6  * that they are exposed only when this file is included by <winsock2.h>
7  *
8  *
9  * $Id$
10  *
11  * Adaptation by Anders Norlander <anorland@hem2.passagen.se>
12  * Copyright (C) 1998-2004, 2012, 2016, 2017, 2019, MinGW.org Project.
13  *
14  * Portions Copyright (C) 1980, 1983, 1988, 1993
15  * The Regents of the University of California.  All rights reserved.
16  *
17  * Portions Copyright (C) 1993 by Digital Equipment Corporation.
18  *
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  * 1. Redistributions of source code must retain the above copyright
24  *    notices, this list of conditions and the following disclaimer.
25  * 2. Redistributions in binary form must reproduce the above copyright
26  *    notice, this list of conditions and the following disclaimer in the
27  *    documentation and/or other materials provided with the distribution.
28  * 3. Neither the name of the University nor the names of its contributors
29  *    may be used to endorse or promote products derived from this software
30  *    without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42  * SUCH DAMAGE.
43  *
44  */
45 #ifndef _WINSOCK_H
46 #pragma GCC system_header
47
48 #ifdef __USE_MINGW_WINSOCK_DEFAULT
49 /* This is default inclusion of <winsock.h> by <windows.h>, (or some other
50  * W32API header; there is no sane reason for __USE_MINGW_WINSOCK_DEFAULT to
51  * have been defined, otherwise).  Whereas Microsoft would simply default to
52  * using WinSock v1.1, MinGW may choose an alternative default.
53  */
54 #include <sdkddkver.h>
55 #if _WIN32_WINNT >= _WIN32_WINNT_NT4
56 /* When the target operating system is WinNT4, or later, we prefer to support
57  * the WinSock v2 API, by default; (this is consistent with the default choice
58  * which was traditionally specified within MinGW.org's <windows.h>).
59  */
60 #include "winsock2.h"
61
62 #endif  /* __USE_MINGW_WINSOCK_DEFAULT for Win-NT4 and later */
63 #endif  /* __USE_MINGW_WINSOCK_DEFAULT (any Windows version) */
64
65 /* If "winsock2.h" was included, to satisfy the __USE_MINGW_WINSOCK_DEFAULT
66  * condition, then the remainder of this file has already been processed, due
67  * to reinclusion by "winsock2.h"; test _WINSOCK_H again to prevent redundant
68  * reprocessing, (which may be potentially harmful)...
69  */
70 #ifndef _WINSOCK_H
71 /* ...but, when _WINSOCK_H hasn't been defined yet, then this is our first
72  * opportunity to process this <winsock.h> content; activate the guard, and
73  * proceed to process it now.
74  */
75 #define _WINSOCK_H
76 #define _GNU_H_WINDOWS32_SOCKETS
77 #define __WINSOCK_H_SOURCED__ 1
78
79 #include <windows.h>
80 #include <winerror.h>
81 #include <sys/bsdtypes.h>
82 #include <sys/time.h>
83
84 #ifndef WINSOCK_API_LINKAGE
85 /* Historically, this was defined (and used) within <winsock2.h>, but not
86  * <winsock.h>, to qualify function declarations which are common to both;
87  * for consistency, we now define, (and subsequently use it here), while
88  * preserving the effect of its previous absence, within <winsock.h>, by
89  * ensuring that it expands to nothing in this context.
90  *
91  * FIXME: Is this logical?  Perhaps <winsock.h> should adopt the effect,
92  * exactly as it was previously implemented exclusively in <winsock2.h>?
93  */
94 #if defined _WINSOCK2_H && defined __W32API_USE_DLLIMPORT__
95 /* To preserve backward compatibility, DECLSPEC_IMPORT option is
96  * available only to WinSock v2 clients, which request it...
97  */
98 #define WINSOCK_API_LINKAGE  DECLSPEC_IMPORT
99
100 #else
101 /* ...whereas WinSock v1.1 clients, and those WinSock v2 clients which
102  * do not request DECLSPEC_IMPORT, will always use default linkage.
103  */
104 #define WINSOCK_API_LINKAGE
105 #endif
106 #endif
107
108 #if ! defined _USE_SYS_TYPES_FD_SET && defined USE_SYS_TYPES_FD_SET
109 /* Originally defined by the deprecated name, USE_SYS_TYPES_FD_SET, users
110  * may specify this to suppress warnings, in the event that (incompatible)
111  * fd_set manipulation macros may have been inherited from <sys/types.h>;
112  * accommodate use of the deprecated feature test name.
113  */
114 #warning "Feature test macro USE_SYS_TYPES_FD_SET is deprecated."
115 #warning "Use the _USE_SYS_TYPES_FD_SET feature test macro instead."
116 #define _USE_SYS_TYPES_FD_SET  1
117 #endif
118
119 #ifndef __WINSOCK2_DEPRECATED
120 /* Some of the WinSock v1.1 declarations have become deprecated in
121  * WinSock v2.  If <winsock2.h> has been included, this deprecation
122  * attribute macro should already have been defined; if not, we now
123  * define it to do nothing.
124  */
125 #define __WINSOCK2_DEPRECATED
126 #endif
127
128 _BEGIN_C_DECLS
129
130 typedef u_int  SOCKET;
131
132 #ifndef FD_SETSIZE
133 #define FD_SETSIZE                                64
134 #endif
135
136 /* shutdown() how types */
137 #define SD_RECEIVE                              0x00
138 #define SD_SEND                                 0x01
139 #define SD_BOTH                                 0x02
140
141 #ifndef _SYS_TYPES_FD_SET
142 /* fd_set may have been defined by the newlib <sys/types.h>, if the
143  * internal __USE_W32_SOCKETS feature test has not been enabled.
144  */
145 #undef fd_set
146 typedef
147 struct fd_set
148 { u_int         fd_count;
149   SOCKET        fd_array[FD_SETSIZE];
150 } fd_set;
151
152 #ifndef FD_ISSET
153 int FD_ISSET (SOCKET, fd_set *);
154 #define FD_ISSET( __fd, __set )  __FD_ISSET ((__fd), (__set))
155
156 /* Microsoft provide this library function equivalent of the FD_ISSET
157  * macro, and erroneously claim that it is neccessary to implement the
158  * macro.  We could just as easily implement it entirely inline...
159  */
160 int PASCAL __WSAFDIsSet (SOCKET, fd_set *);
161 /* ...but, given the availability of the library function, we may just
162  * as well use it.
163  */
164 __CRT_ALIAS int __FD_ISSET( SOCKET __fd, fd_set *__set )
165 { return __WSAFDIsSet (__fd, __set); }
166 #endif  /* ! defined FD_ISSET */
167
168 #ifndef FD_SET
169 #if !_WINSOCK_ANOMALOUS_TYPEDEFS
170 /* WinSock is intended to mimic the Berkeley Sockets API, for which
171  * POSIX.1 provides a reference specification; this states that FD_SET
172  * may be implemented as either a macro, or as a function.  The reference
173  * <winsock.h> implementation at http://www.sockets.com/winsock.htm#WinsockH
174  * includes a typedef for FD_SET, which a) conflicts with the latter POSIX.1
175  * provision, and b) creates potential confusion with the former.  Thus, we
176  * prefer to conform with POSIX.1 functional semantics, and recommend that
177  * users avoid the potentially confusing FD_SET typedefs, so allowing us
178  * to provide this function prototype:
179  */
180 void FD_SET (SOCKET, fd_set *);
181
182 #else   /* _WINSOCK_ANOMALOUS_TYPEDEFS */
183 /* However, for users who insist on eschewing standard C/C++ syntax, and
184  * for whatever reason must use FD_SET as a data type, instead of correctly
185  * referring to fd_set, or for pointer references, use PFD_SET or LPFD_SET
186  * instead of standard fd_set * references, we make these anomalous types
187  * visible, when the _WINSOCK_ANOMALOUS_TYPEDEFS feature test macro is
188  * defined with a non-zero value.
189  */
190 #warning "FD_SET, PFD_SET, and LPFD_SET data types are non-portable."
191 #warning "Use portable fd_set, and fd_set * type references instead."
192
193 typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
194 #endif
195 #define FD_SET( __fd, __set )  __FD_SET ((__fd), (__set))
196 __CRT_ALIAS void __FD_SET (SOCKET __fd, fd_set *__set)
197 { if( (__set->fd_count < FD_SETSIZE) && ! FD_ISSET (__fd, __set) )
198     __set->fd_array[__set->fd_count++] = __fd;
199 }
200 #endif  /* ! defined FD_SET */
201
202 #ifndef FD_CLR
203 void FD_CLR (SOCKET, fd_set *);
204 #define FD_CLR( __fd, __set )  __FD_CLR ((__fd), (__set))
205 __CRT_ALIAS void __FD_CLR (SOCKET __fd, fd_set *__set)
206 { u_int __m, __n; for (__m = __n = 0; __n < __set->fd_count; __n++)
207   { if (__fd != __set->fd_array[__n])
208     { if (__m < __n) __set->fd_array[__m] = __set->fd_array[__n];
209       ++__m;
210     }
211   } __set->fd_count = __m;
212 }
213 #endif  /* ! defined FD_CLR */
214
215 #ifndef FD_ZERO
216 void FD_ZERO (fd_set *);
217 #define FD_ZERO( __set )  __FD_ZERO (__set)
218 __CRT_ALIAS void __FD_ZERO (fd_set *__set)
219 { __set->fd_count = 0; }
220 #endif  /* ! defined FD_ZERO */
221
222 #elif ! defined _USE_SYS_TYPES_FD_SET
223 /* Definitions from <sys/types.h> probably aren't what the user wants;
224  * if they know what they are doing, and they are sure that this really
225  * is what they want, then they may enable the _USE_SYS_TYPES_FD_SET
226  * feature test macro, to suppress this warning.
227  */
228 #warning "fd_set and associated macros have been defined in <sys/types.h>"
229 #warning "Your <sys/types.h> may cause runtime problems with W32 sockets."
230 #endif  /* !_SYS_TYPES_FD_SET */
231
232 #ifndef __INSIDE_MSYS__
233
234 struct hostent
235 { char           *h_name;
236   char          **h_aliases;
237   short           h_addrtype;
238   short           h_length;
239 # define          h_addr  h_addr_list[0]
240   char          **h_addr_list;
241 };
242
243 struct linger
244 { u_short         l_onoff;
245   u_short         l_linger;
246 };
247
248 #endif  /* !__INSIDE_MSYS__ */
249
250 #define IOCPARM_MASK                          0x7F
251 #define IOC_VOID                        0x20000000
252 #define IOC_OUT                         0x40000000
253 #define IOC_IN                          0x80000000
254 #define IOC_INOUT                   (IOC_IN | IOC_OUT)
255
256 #ifndef __INSIDE_MSYS__
257
258 #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
259 #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
260 #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
261
262 #define FIONBIO                 _IOW('f', 126, u_long)
263
264 #endif  /* !__INSIDE_MSYS__ */
265
266 #define FIONREAD                _IOR('f', 127, u_long)
267 #define FIOASYNC                _IOW('f', 125, u_long)
268 #define SIOCSHIWAT              _IOW('s',  0, u_long)
269 #define SIOCGHIWAT              _IOR('s',  1, u_long)
270 #define SIOCSLOWAT              _IOW('s',  2, u_long)
271 #define SIOCGLOWAT              _IOR('s',  3, u_long)
272 #define SIOCATMARK              _IOR('s',  7, u_long)
273
274 #ifndef __INSIDE_MSYS__
275
276 struct netent
277 { char           *n_name;
278   char          **n_aliases;
279   short           n_addrtype;
280   u_long          n_net;
281 };
282
283 struct servent
284 { char           *s_name;
285   char          **s_aliases;
286   short           s_port;
287   char           *s_proto;
288 };
289
290 struct protoent
291 { char           *p_name;
292   char          **p_aliases;
293   short           p_proto;
294 };
295
296 #endif  /* !__INSIDE_MSYS__ */
297
298 #define IPPROTO_IP                                 0
299 #define IPPROTO_ICMP                               1
300 #define IPPROTO_IGMP                               2
301 #define IPPROTO_GGP                                3
302 #define IPPROTO_TCP                                6
303 #define IPPROTO_PUP                               12
304 #define IPPROTO_UDP                               17
305 #define IPPROTO_IDP                               22
306 #define IPPROTO_ND                                77
307
308 #define IPPROTO_RAW                              255
309 #define IPPROTO_MAX                              256
310
311 #define IPPORT_ECHO                                7
312 #define IPPORT_DISCARD                             9
313 #define IPPORT_SYSTAT                             11
314 #define IPPORT_DAYTIME                            13
315 #define IPPORT_NETSTAT                            15
316 #define IPPORT_FTP                                21
317 #define IPPORT_TELNET                             23
318 #define IPPORT_SMTP                               25
319 #define IPPORT_TIMESERVER                         37
320 #define IPPORT_NAMESERVER                         42
321 #define IPPORT_WHOIS                              43
322 #define IPPORT_MTP                                57
323 #define IPPORT_TFTP                               69
324 #define IPPORT_RJE                                77
325 #define IPPORT_FINGER                             79
326 #define IPPORT_TTYLINK                            87
327 #define IPPORT_SUPDUP                             95
328 #define IPPORT_EXECSERVER                        512
329 #define IPPORT_LOGINSERVER                       513
330 #define IPPORT_CMDSERVER                         514
331 #define IPPORT_EFSSERVER                         520
332 #define IPPORT_BIFFUDP                           512
333 #define IPPORT_WHOSERVER                         513
334 #define IPPORT_ROUTESERVER                       520
335 #define IPPORT_RESERVED                         1024
336
337 #define IMPLINK_IP                               155
338 #define IMPLINK_LOWEXPER                         156
339 #define IMPLINK_HIGHEXPER                        158
340
341 struct in_addr
342 #define s_addr                                S_un.S_addr
343 #define s_host                                S_un.S_un_b.s_b2
344 #define s_net                                 S_un.S_un_b.s_b1
345 #define s_imp                                 S_un.S_un_w.s_w2
346 #define s_impno                               S_un.S_un_b.s_b4
347 #define s_lh                                  S_un.S_un_b.s_b3
348 { union
349   { struct { u_char s_b1,s_b2,s_b3,s_b4; }      S_un_b;
350     struct { u_short s_w1,s_w2; }               S_un_w;
351     u_long                                      S_addr;
352   }                                           S_un;
353 };
354
355 #define IN_CLASSA(i)        (((long)(i) & 0x80000000) == 0)
356 #define IN_CLASSA_NET                     0xFF000000
357 #define IN_CLASSA_NSHIFT                          24
358 #define IN_CLASSA_HOST                    0x00FFFFFF
359 #define IN_CLASSA_MAX                            128
360 #define IN_CLASSB(i)        (((long)(i) & 0xC0000000) == 0x80000000)
361 #define IN_CLASSB_NET                     0xFFFF0000
362 #define IN_CLASSB_NSHIFT                          16
363 #define IN_CLASSB_HOST                    0x0000FFFF
364 #define IN_CLASSB_MAX                          65536
365 #define IN_CLASSC(i)        (((long)(i) & 0xE0000000) == 0xC0000000)
366 #define IN_CLASSC_NET                     0xFFFFFF00
367 #define IN_CLASSC_NSHIFT                           8
368 #define IN_CLASSC_HOST                          0xFF
369 #define INADDR_ANY                        (u_long)(0)
370 #define INADDR_LOOPBACK                   0x7F000001
371 #define INADDR_BROADCAST         (u_long)(0xFFFFFFFF)
372 #define INADDR_NONE                       0xFFFFFFFF
373
374 struct sockaddr_in
375 { short                  sin_family;
376   u_short                sin_port;
377   struct in_addr         sin_addr;
378   char                   sin_zero[8];
379 };
380
381 #define WSADESCRIPTION_LEN                       256
382 #define WSASYS_STATUS_LEN                        128
383
384 typedef
385 struct WSAData
386 { WORD                   wVersion;
387   WORD                   wHighVersion;
388   char                   szDescription[WSADESCRIPTION_LEN+1];
389   char                   szSystemStatus[WSASYS_STATUS_LEN+1];
390   unsigned short         iMaxSockets;
391   unsigned short         iMaxUdpDg;
392   char                  *lpVendorInfo;
393 } WSADATA, *LPWSADATA;
394
395 #ifndef __INSIDE_MSYS__
396
397 #define IP_OPTIONS                                 1
398 #define SO_DEBUG                                   1
399 #define SO_ACCEPTCONN                              2
400 #define SO_REUSEADDR                               4
401 #define SO_KEEPALIVE                               8
402 #define SO_DONTROUTE                              16
403 #define SO_BROADCAST                              32
404 #define SO_USELOOPBACK                            64
405 #define SO_LINGER                                128
406 #define SO_OOBINLINE                             256
407
408 #define SO_DONTLINGER                    (u_int)(~SO_LINGER)
409
410 #define SO_SNDBUF                             0x1001
411 #define SO_RCVBUF                             0x1002
412 #define SO_SNDLOWAT                           0x1003
413 #define SO_RCVLOWAT                           0x1004
414 #define SO_SNDTIMEO                           0x1005
415 #define SO_RCVTIMEO                           0x1006
416 #define SO_ERROR                              0x1007
417 #define SO_TYPE                               0x1008
418
419 #endif  /* !__INSIDE_MSYS__ */
420
421 #ifndef _WINSOCK2_H
422 /* The following IP defines are specific to WinSock v1.1 (wsock32.dll).
423  * They may cause errors, or produce unexpected results, if exposed when
424  * compiling application code which is intended to use the getsockopts(),
425  * or setsockopts() APIs, as exported from the WinSock v2 system library,
426  * ws2_32.dll.  Please refer to <ws2tcpip.h> for further information.
427  */
428 #define IP_MULTICAST_IF                            2
429 #define IP_MULTICAST_TTL                           3
430 #define IP_MULTICAST_LOOP                          4
431 #define IP_ADD_MEMBERSHIP                          5
432 #define IP_DROP_MEMBERSHIP                         6
433
434 #define IP_DEFAULT_MULTICAST_TTL                   1
435 #define IP_DEFAULT_MULTICAST_LOOP                  1
436 #define IP_MAX_MEMBERSHIPS                        20
437
438 struct ip_mreq
439 { struct in_addr         imr_multiaddr;
440   struct in_addr         imr_interface;
441 };
442 #endif  /* !_WINSOCK2_H */
443
444 #define INVALID_SOCKET                   (SOCKET)(~0)
445 #define SOCKET_ERROR                             (-1)
446 #define SOCK_STREAM                                1
447 #define SOCK_DGRAM                                 2
448 #define SOCK_RAW                                   3
449 #define SOCK_RDM                                   4
450 #define SOCK_SEQPACKET                             5
451 #define TCP_NODELAY                           0x0001
452 #define AF_UNSPEC                                  0
453 #define AF_UNIX                                    1
454 #define AF_INET                                    2
455 #define AF_IMPLINK                                 3
456 #define AF_PUP                                     4
457 #define AF_CHAOS                                   5
458 #define AF_IPX                                     6
459 #define AF_NS                                      6
460 #define AF_ISO                                     7
461
462 #define AF_OSI                                AF_ISO
463
464 #define AF_ECMA                                    8
465 #define AF_DATAKIT                                 9
466 #define AF_CCITT                                  10
467 #define AF_SNA                                    11
468 #define AF_DECnet                                 12
469 #define AF_DLI                                    13
470 #define AF_LAT                                    14
471 #define AF_HYLINK                                 15
472 #define AF_APPLETALK                              16
473 #define AF_NETBIOS                                17
474 #define AF_VOICEVIEW                              18
475 #define AF_FIREFOX                                19
476 #define AF_UNKNOWN1                               20
477 #define AF_BAN                                    21
478 #define AF_ATM                                    22
479 #define AF_INET6                                  23
480
481 #ifndef __INSIDE_MSYS__
482
483 #define AF_MAX                                    24
484
485 struct sockaddr
486 { u_short                sa_family;
487   char                   sa_data[14];
488 };
489
490 #endif  /* !__INSIDE_MSYS__ */
491
492 struct sockproto
493 { u_short                sp_family;
494   u_short                sp_protocol;
495 };
496
497 #define PF_UNSPEC                          AF_UNSPEC
498 #define PF_UNIX                              AF_UNIX
499 #define PF_INET                              AF_INET
500 #define PF_IMPLINK                        AF_IMPLINK
501 #define PF_PUP                                AF_PUP
502 #define PF_CHAOS                            AF_CHAOS
503 #define PF_NS                                  AF_NS
504 #define PF_IPX                                AF_IPX
505 #define PF_ISO                                AF_ISO
506 #define PF_OSI                                AF_OSI
507 #define PF_ECMA                              AF_ECMA
508 #define PF_DATAKIT                        AF_DATAKIT
509 #define PF_CCITT                            AF_CCITT
510 #define PF_SNA                                AF_SNA
511 #define PF_DECnet                          AF_DECnet
512 #define PF_DLI                                AF_DLI
513 #define PF_LAT                                AF_LAT
514 #define PF_HYLINK                          AF_HYLINK
515 #define PF_APPLETALK                    AF_APPLETALK
516 #define PF_VOICEVIEW                    AF_VOICEVIEW
517 #define PF_FIREFOX                        AF_FIREFOX
518 #define PF_UNKNOWN1                      AF_UNKNOWN1
519 #define PF_BAN                                AF_BAN
520 #define PF_ATM                                AF_ATM
521 #define PF_INET6                            AF_INET6
522 #define PF_MAX                                AF_MAX
523
524 #define SOL_SOCKET                            0xFFFF
525
526 #ifndef __INSIDE_MSYS__
527
528 /* This definition of SOMAXCONN is correct for WinSock v1.1, but not
529  * for WinSock v2; we define it thus here, but note that, if included
530  * by <winsock2.h>, it will subsequently be overridden by the correct
531  * WinSock v2 definition.
532  */
533 #define SOMAXCONN                                  5
534
535 #define MSG_OOB                                    1
536 #define MSG_PEEK                                   2
537 #define MSG_DONTROUTE                              4
538
539 #endif  /* !__INSIDE_MSYS__ */
540
541 #define MSG_MAXIOVLEN                             16
542 #define MSG_PARTIAL                           0x8000
543 #define MAXGETHOSTSTRUCT                        1024
544
545 enum
546 { /* Enumerate the flags used to represent the events which may be
547    * detected on any socket, when monitored via an fd_set array.
548    */
549   FD_READ_BIT = 0,
550 # define FD_READ                      (1 << FD_READ_BIT)
551
552   FD_WRITE_BIT,
553 # define FD_WRITE                     (1 << FD_WRITE_BIT)
554
555   FD_OOB_BIT,
556 # define FD_OOB                       (1 << FD_OOB_BIT)
557
558   FD_ACCEPT_BIT,
559 # define FD_ACCEPT                    (1 << FD_ACCEPT_BIT)
560
561   FD_CONNECT_BIT,
562 # define FD_CONNECT                   (1 << FD_CONNECT_BIT)
563
564   FD_CLOSE_BIT,
565 # define FD_CLOSE                     (1 << FD_CLOSE_BIT)
566
567 # ifdef _WINSOCK2_H
568 /* WinSock v1.1 defines no further events, beyond FD_CLOSE (1 << 5 = 32).
569  * The following are specific to WinSock v2; for convenience, they may be
570  * enumerated here, but they are exposed only when <winsock.h> is included
571  * indirectly, by way of including <winsock2.h>
572  */
573   FD_QOS_BIT,
574 # define FD_QOS                       (1 << FD_QOS_BIT)
575
576   FD_GROUP_QOS_BIT,
577 # define FD_GROUP_QOS                 (1 << FD_GROUP_QOS_BIT)
578
579   FD_ROUTING_INTERFACE_CHANGE_BIT,
580 # define FD_ROUTING_INTERFACE_CHANGE  (1 << FD_ROUTING_INTERFACE_CHANGE_BIT)
581
582   FD_ADDRESS_LIST_CHANGE_BIT,
583 # define FD_ADDRESS_LIST_CHANGE       (1 << FD_ADDRESS_LIST_CHANGE_BIT)
584
585 # endif /* _WINSOCK2_H */
586   /* Regardless of WinSock version, FD_MAX_EVENTS represents the first
587    * unused flag bit, whence we may deduce FD_ALL_EVENTS, as a mask for
588    * all supported event flags, specific to the WinSock version in use.
589    */
590   FD_MAX_EVENTS,
591 # define FD_ALL_EVENTS                  ((1 << FD_MAX_EVENTS) - 1)
592 };
593
594 #define WSANO_ADDRESS                   WSANO_DATA
595
596 #ifndef __INSIDE_MSYS__
597
598 #define h_errno                         WSAGetLastError()
599 #define HOST_NOT_FOUND                  WSAHOST_NOT_FOUND
600 #define TRY_AGAIN                       WSATRY_AGAIN
601 #define NO_RECOVERY                     WSANO_RECOVERY
602 #define NO_DATA                         WSANO_DATA
603 #define NO_ADDRESS                      WSANO_ADDRESS
604
605 #endif  /* !__INSIDE_MSYS__ */
606
607 WINSOCK_API_LINKAGE SOCKET PASCAL accept (SOCKET, struct sockaddr *, int *);
608
609 WINSOCK_API_LINKAGE int PASCAL bind (SOCKET, const struct sockaddr *, int);
610 WINSOCK_API_LINKAGE int PASCAL closesocket (SOCKET);
611 WINSOCK_API_LINKAGE int PASCAL connect (SOCKET, const struct sockaddr *, int);
612 WINSOCK_API_LINKAGE int PASCAL ioctlsocket (SOCKET, long, u_long *);
613 WINSOCK_API_LINKAGE int PASCAL getpeername (SOCKET, struct sockaddr *, int *);
614 WINSOCK_API_LINKAGE int PASCAL getsockname (SOCKET, struct sockaddr *, int *);
615 WINSOCK_API_LINKAGE int PASCAL getsockopt (SOCKET, int, int, char *, int *);
616
617 WINSOCK_API_LINKAGE unsigned long PASCAL inet_addr (const char *);
618
619 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (char *) inet_ntoa (struct in_addr);
620
621 WINSOCK_API_LINKAGE int PASCAL listen (SOCKET, int);
622 WINSOCK_API_LINKAGE int PASCAL recv (SOCKET, char *, int, int);
623 WINSOCK_API_LINKAGE int PASCAL recvfrom (SOCKET, char *, int, int, struct sockaddr *, int *);
624 WINSOCK_API_LINKAGE int PASCAL send (SOCKET, const char *, int, int);
625 WINSOCK_API_LINKAGE int PASCAL sendto (SOCKET, const char *, int, int, const struct sockaddr *, int);
626 WINSOCK_API_LINKAGE int PASCAL setsockopt (SOCKET, int, int, const char *, int);
627 WINSOCK_API_LINKAGE int PASCAL shutdown (SOCKET, int);
628
629 WINSOCK_API_LINKAGE SOCKET PASCAL socket (int, int, int);
630
631 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct hostent *)  gethostbyaddr (const char *, int, int);
632 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct hostent *)  gethostbyname (const char *);
633 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct servent *)  getservbyport (int, const char *);
634 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct servent *)  getservbyname (const char *, const char *);
635 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct protoent *) getprotobynumber (int);
636 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct protoent *) getprotobyname (const char *);
637
638 WINSOCK_API_LINKAGE int PASCAL WSAStartup (WORD, LPWSADATA);
639 WINSOCK_API_LINKAGE int PASCAL WSACleanup (void);
640 WINSOCK_API_LINKAGE void PASCAL WSASetLastError (int);
641 WINSOCK_API_LINKAGE int PASCAL WSAGetLastError (void);
642
643 /* The following four pseudo-blocking functions are provided
644  * to support WinSock v1.1, but have been marked as deprecated
645  * in WinSock v2; they remain available, but it is recommended
646  * that threads should be used instead!
647  */
648 WINSOCK_API_LINKAGE BOOL PASCAL WSAIsBlocking (void) __WINSOCK2_DEPRECATED;
649 WINSOCK_API_LINKAGE int PASCAL WSAUnhookBlockingHook (void) __WINSOCK2_DEPRECATED;
650 WINSOCK_API_LINKAGE FARPROC PASCAL WSASetBlockingHook (FARPROC) __WINSOCK2_DEPRECATED;
651 WINSOCK_API_LINKAGE int PASCAL WSACancelBlockingCall (void) __WINSOCK2_DEPRECATED;
652
653 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetServByName (HWND, u_int, const char *, const char *, char *, int);
654 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetServByPort (HWND, u_int, int, const char *, char *, int);
655 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetProtoByName (HWND, u_int, const char *, char *, int);
656 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetProtoByNumber (HWND, u_int, int, char *, int);
657 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetHostByName (HWND, u_int, const char *, char *, int);
658 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetHostByAddr (HWND, u_int, const char *, int, int, char *, int);
659
660 WINSOCK_API_LINKAGE int PASCAL WSACancelAsyncRequest (HANDLE);
661 WINSOCK_API_LINKAGE int PASCAL WSAAsyncSelect (SOCKET, HWND, u_int, long);
662
663 #ifndef __INSIDE_MSYS__
664
665 WINSOCK_API_LINKAGE u_long PASCAL htonl (u_long);
666 WINSOCK_API_LINKAGE u_long PASCAL ntohl (u_long);
667 WINSOCK_API_LINKAGE u_short PASCAL htons (u_short);
668 WINSOCK_API_LINKAGE u_short PASCAL ntohs (u_short);
669 WINSOCK_API_LINKAGE int PASCAL select (int nfds, fd_set *, fd_set *, fd_set *, const struct timeval *);
670
671 #endif  /* !__INSIDE_MSYS__ */
672
673 WINSOCK_API_LINKAGE int PASCAL gethostname (char *, int);
674
675 #define WSAMAKEASYNCREPLY(b,e)                  MAKELONG(b,e)
676 #define WSAMAKESELECTREPLY(e,error)             MAKELONG(e,error)
677 #define WSAGETASYNCBUFLEN(l)                    LOWORD(l)
678 #define WSAGETASYNCERROR(l)                     HIWORD(l)
679 #define WSAGETSELECTEVENT(l)                    LOWORD(l)
680 #define WSAGETSELECTERROR(l)                    HIWORD(l)
681
682 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
683 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
684 typedef struct linger LINGER, *PLINGER, *LPLINGER;
685 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
686 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
687 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
688 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
689 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
690
691 _END_C_DECLS
692
693 #ifndef _WINSOCK2_H
694 /* MSDN documentation indicates that the MS-specific extensions exported
695  * from mswsock.dll, (i.e. the AcceptEx(), TransmitFile(), WSARecEx(), and
696  * GetAcceptExSockaddrs() functions), are declared in <mswsock.h>.  These
697  * extensions are not supported on Win9x or WinCE.  However, WinSock v1.1
698  * dependent code may expect that the declarations and associated defines
699  * will be in this header; thus we include <mswsock.h> here.
700  *
701  * When linking against the WinSock v1.1 library, wsock32.dll, the mswsock
702  * functions are automatically routed to mswsock.dll (on platforms which
703  * support it).  The WinSock v2 library, ws2_32.dll, does not contain any
704  * references to the mswsock extensions.
705  */
706 #include <mswsock.h>
707
708 #endif  /* !_WINSOCK2_H */
709 #endif  /* !_WINSOCK_H redundancy check */
710
711 #undef  __WINSOCK_H_SOURCED__
712 #endif  /* _WINSOCK_H: $RCSfile$: end of file */