OSDN Git Service

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