4 * Definitions for WinSock Version 1.1 API.
9 * Adaptation by Anders Norlander <anorland@hem2.passagen.se>
10 * Copyright (C) 1998-2004, 2012, 2016, 2017, MinGW.org Project.
12 * Portions Copyright (C) 1980, 1983, 1988, 1993
13 * The Regents of the University of California. All rights reserved.
15 * Portions Copyright (C) 1993 by Digital Equipment Corporation.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notices, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #pragma GCC system_header
47 #define _GNU_H_WINDOWS32_SOCKETS
48 #define __WINSOCK_H_SOURCED__ 1
52 #include <sys/bsdtypes.h>
55 #ifndef WINSOCK_API_LINKAGE
56 /* Historically, this was defined (and used) within <winsock2.h>, but not
57 * <winsock.h>, to qualify function declarations which are common to both;
58 * for consistency, we now define, (and subsequently use it here), while
59 * preserving the effect of its previous absence, within <winsock.h>, by
60 * ensuring that it expands to nothing in this context.
62 * FIXME: Is this logical? Perhaps <winsock.h> should adopt the effect,
63 * exactly as it was previously implemented exclusively in <winsock2.h>?
65 #if defined _WINSOCK2_H && defined __W32API_USE_DLLIMPORT__
66 /* To preserve backward compatibility, DECLSPEC_IMPORT option is
67 * available only to WinSock v2 clients, which request it...
69 #define WINSOCK_API_LINKAGE DECLSPEC_IMPORT
72 /* ...whereas WinSock v1.1 clients, and those WinSock v2 clients which
73 * do not request DECLSPEC_IMPORT, will always use default linkage.
75 #define WINSOCK_API_LINKAGE
79 #if ! defined _USE_SYS_TYPES_FD_SET && defined USE_SYS_TYPES_FD_SET
80 /* Originally defined by the deprecated name, USE_SYS_TYPES_FD_SET, users
81 * may specify this to suppress warnings, in the event that (incompatible)
82 * fd_set manipulation macros may have been inherited from <sys/types.h>;
83 * accommodate use of the deprecated feature test name.
85 #warning "Feature test macro USE_SYS_TYPES_FD_SET is deprecated."
86 #warning "Use the _USE_SYS_TYPES_FD_SET feature test macro instead."
87 #define _USE_SYS_TYPES_FD_SET 1
98 /* shutdown() how types */
99 #define SD_RECEIVE 0x00
103 #ifndef _SYS_TYPES_FD_SET
104 /* fd_set may have been defined by the newlib <sys/types.h>, if the
105 * internal __USE_W32_SOCKETS feature test has not been enabled.
111 SOCKET fd_array[FD_SETSIZE];
114 int PASCAL __WSAFDIsSet (SOCKET, fd_set *);
117 #define FD_CLR( fd, set ) do \
119 for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) \
120 { if (((fd_set *)(set))->fd_array[__i] == (fd)) \
121 { while (__i < ((fd_set *)(set))->fd_count-1) \
122 { ((fd_set *)(set))->fd_array[__i] \
123 = ((fd_set *)(set))->fd_array[__i + 1]; __i++; \
125 ((fd_set *)(set))->fd_count--; \
130 #endif /* ! defined FD_CLR */
133 #define FD_SET( fd, set ) do \
134 { if (((fd_set *)(set))->fd_count < FD_SETSIZE) \
135 ((fd_set *)(set))->fd_array[((fd_set *)(set))->fd_count++] = (fd); \
137 #endif /* ! defined FD_SET */
140 #define FD_ZERO( set ) (((fd_set *)(set))->fd_count = 0)
141 #endif /* ! defined FD_ZERO */
144 #define FD_ISSET( fd, set ) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set))
145 #endif /* ! defined FD_ISSET */
147 #elif ! defined _USE_SYS_TYPES_FD_SET
148 /* Definitions from <sys/types.h> probably aren't what the user wants;
149 * if they know what they are doing, and they are sure that this really
150 * is what they want, then they may enable the _USE_SYS_TYPES_FD_SET
151 * feature test macro, to suppress this warning.
153 #warning "fd_set and associated macros have been defined in <sys/types.h>"
154 #warning "Your <sys/types.h> may cause runtime problems with W32 sockets."
155 #endif /* !_SYS_TYPES_FD_SET */
157 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
164 # define h_addr h_addr_list[0]
173 #endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
175 #define IOCPARM_MASK 0x7F
176 #define IOC_VOID 0x20000000
177 #define IOC_OUT 0x40000000
178 #define IOC_IN 0x80000000
179 #define IOC_INOUT (IOC_IN | IOC_OUT)
181 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
183 #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
184 #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
185 #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
187 #define FIONBIO _IOW('f', 126, u_long)
189 #endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
191 #define FIONREAD _IOR('f', 127, u_long)
192 #define FIOASYNC _IOW('f', 125, u_long)
193 #define SIOCSHIWAT _IOW('s', 0, u_long)
194 #define SIOCGHIWAT _IOR('s', 1, u_long)
195 #define SIOCSLOWAT _IOW('s', 2, u_long)
196 #define SIOCGLOWAT _IOR('s', 3, u_long)
197 #define SIOCATMARK _IOR('s', 7, u_long)
199 #if ! ( defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
221 #endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
224 #define IPPROTO_ICMP 1
225 #define IPPROTO_IGMP 2
226 #define IPPROTO_GGP 3
227 #define IPPROTO_TCP 6
228 #define IPPROTO_PUP 12
229 #define IPPROTO_UDP 17
230 #define IPPROTO_IDP 22
231 #define IPPROTO_ND 77
233 #define IPPROTO_RAW 255
234 #define IPPROTO_MAX 256
236 #define IPPORT_ECHO 7
237 #define IPPORT_DISCARD 9
238 #define IPPORT_SYSTAT 11
239 #define IPPORT_DAYTIME 13
240 #define IPPORT_NETSTAT 15
241 #define IPPORT_FTP 21
242 #define IPPORT_TELNET 23
243 #define IPPORT_SMTP 25
244 #define IPPORT_TIMESERVER 37
245 #define IPPORT_NAMESERVER 42
246 #define IPPORT_WHOIS 43
247 #define IPPORT_MTP 57
248 #define IPPORT_TFTP 69
249 #define IPPORT_RJE 77
250 #define IPPORT_FINGER 79
251 #define IPPORT_TTYLINK 87
252 #define IPPORT_SUPDUP 95
253 #define IPPORT_EXECSERVER 512
254 #define IPPORT_LOGINSERVER 513
255 #define IPPORT_CMDSERVER 514
256 #define IPPORT_EFSSERVER 520
257 #define IPPORT_BIFFUDP 512
258 #define IPPORT_WHOSERVER 513
259 #define IPPORT_ROUTESERVER 520
260 #define IPPORT_RESERVED 1024
262 #define IMPLINK_IP 155
263 #define IMPLINK_LOWEXPER 156
264 #define IMPLINK_HIGHEXPER 158
267 #define s_addr S_un.S_addr
268 #define s_host S_un.S_un_b.s_b2
269 #define s_net S_un.S_un_b.s_b1
270 #define s_imp S_un.S_un_w.s_w2
271 #define s_impno S_un.S_un_b.s_b4
272 #define s_lh S_un.S_un_b.s_b3
274 { struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
275 struct { u_short s_w1,s_w2; } S_un_w;
280 #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
281 #define IN_CLASSA_NET 0xFF000000
282 #define IN_CLASSA_NSHIFT 24
283 #define IN_CLASSA_HOST 0x00FFFFFF
284 #define IN_CLASSA_MAX 128
285 #define IN_CLASSB(i) (((long)(i) & 0xC0000000) == 0x80000000)
286 #define IN_CLASSB_NET 0xFFFF0000
287 #define IN_CLASSB_NSHIFT 16
288 #define IN_CLASSB_HOST 0x0000FFFF
289 #define IN_CLASSB_MAX 65536
290 #define IN_CLASSC(i) (((long)(i) & 0xE0000000) == 0xC0000000)
291 #define IN_CLASSC_NET 0xFFFFFF00
292 #define IN_CLASSC_NSHIFT 8
293 #define IN_CLASSC_HOST 0xFF
294 #define INADDR_ANY (u_long)(0)
295 #define INADDR_LOOPBACK 0x7F000001
296 #define INADDR_BROADCAST (u_long)(0xFFFFFFFF)
297 #define INADDR_NONE 0xFFFFFFFF
302 struct in_addr sin_addr;
306 #define WSADESCRIPTION_LEN 256
307 #define WSASYS_STATUS_LEN 128
313 char szDescription[WSADESCRIPTION_LEN+1];
314 char szSystemStatus[WSASYS_STATUS_LEN+1];
315 unsigned short iMaxSockets;
316 unsigned short iMaxUdpDg;
318 } WSADATA, *LPWSADATA;
320 #ifndef __INSIDE_MSYS__
324 #define SO_ACCEPTCONN 2
325 #define SO_REUSEADDR 4
326 #define SO_KEEPALIVE 8
327 #define SO_DONTROUTE 16
328 #define SO_BROADCAST 32
329 #define SO_USELOOPBACK 64
330 #define SO_LINGER 128
331 #define SO_OOBINLINE 256
333 #define SO_DONTLINGER (u_int)(~SO_LINGER)
335 #define SO_SNDBUF 0x1001
336 #define SO_RCVBUF 0x1002
337 #define SO_SNDLOWAT 0x1003
338 #define SO_RCVLOWAT 0x1004
339 #define SO_SNDTIMEO 0x1005
340 #define SO_RCVTIMEO 0x1006
341 #define SO_ERROR 0x1007
342 #define SO_TYPE 0x1008
344 #endif /* !__INSIDE_MSYS__ */
346 /* The following IP defines are specific to WinSock v1.1 (wsock32.dll).
347 * They may cause errors, or produce unexpected results, if exposed when
348 * compiling application code which is intended to use the getsockopts(),
349 * or setsockopts() APIs, as exported from the WinSock v2 system library,
350 * ws2_32.dll. Please refer to <ws2tcpip.h> for further information.
352 #define IP_MULTICAST_IF 2
353 #define IP_MULTICAST_TTL 3
354 #define IP_MULTICAST_LOOP 4
355 #define IP_ADD_MEMBERSHIP 5
356 #define IP_DROP_MEMBERSHIP 6
358 #define IP_DEFAULT_MULTICAST_TTL 1
359 #define IP_DEFAULT_MULTICAST_LOOP 1
360 #define IP_MAX_MEMBERSHIPS 20
363 { struct in_addr imr_multiaddr;
364 struct in_addr imr_interface;
367 #define INVALID_SOCKET (SOCKET)(~0)
368 #define SOCKET_ERROR (-1)
369 #define SOCK_STREAM 1
373 #define SOCK_SEQPACKET 5
374 #define TCP_NODELAY 0x0001
385 #define AF_OSI AF_ISO
395 #define AF_APPLETALK 16
396 #define AF_NETBIOS 17
397 #define AF_VOICEVIEW 18
398 #define AF_FIREFOX 19
399 #define AF_UNKNOWN1 20
404 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
413 #endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
420 #define PF_UNSPEC AF_UNSPEC
421 #define PF_UNIX AF_UNIX
422 #define PF_INET AF_INET
423 #define PF_IMPLINK AF_IMPLINK
424 #define PF_PUP AF_PUP
425 #define PF_CHAOS AF_CHAOS
427 #define PF_IPX AF_IPX
428 #define PF_ISO AF_ISO
429 #define PF_OSI AF_OSI
430 #define PF_ECMA AF_ECMA
431 #define PF_DATAKIT AF_DATAKIT
432 #define PF_CCITT AF_CCITT
433 #define PF_SNA AF_SNA
434 #define PF_DECnet AF_DECnet
435 #define PF_DLI AF_DLI
436 #define PF_LAT AF_LAT
437 #define PF_HYLINK AF_HYLINK
438 #define PF_APPLETALK AF_APPLETALK
439 #define PF_VOICEVIEW AF_VOICEVIEW
440 #define PF_FIREFOX AF_FIREFOX
441 #define PF_UNKNOWN1 AF_UNKNOWN1
442 #define PF_BAN AF_BAN
443 #define PF_ATM AF_ATM
444 #define PF_INET6 AF_INET6
445 #define PF_MAX AF_MAX
447 #define SOL_SOCKET 0xFFFF
450 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
454 #define MSG_DONTROUTE 4
456 #endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
458 #define MSG_MAXIOVLEN 16
459 #define MSG_PARTIAL 0x8000
460 #define MAXGETHOSTSTRUCT 1024
466 #define FD_CONNECT 16
469 #define WSANO_ADDRESS WSANO_DATA
471 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
473 #define h_errno WSAGetLastError()
474 #define HOST_NOT_FOUND WSAHOST_NOT_FOUND
475 #define TRY_AGAIN WSATRY_AGAIN
476 #define NO_RECOVERY WSANO_RECOVERY
477 #define NO_DATA WSANO_DATA
478 #define NO_ADDRESS WSANO_ADDRESS
480 #endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
482 WINSOCK_API_LINKAGE SOCKET PASCAL accept (SOCKET, struct sockaddr *, int *);
484 WINSOCK_API_LINKAGE int PASCAL bind (SOCKET, const struct sockaddr *, int);
485 WINSOCK_API_LINKAGE int PASCAL closesocket (SOCKET);
486 WINSOCK_API_LINKAGE int PASCAL connect (SOCKET, const struct sockaddr *, int);
487 WINSOCK_API_LINKAGE int PASCAL ioctlsocket (SOCKET, long, u_long *);
488 WINSOCK_API_LINKAGE int PASCAL getpeername (SOCKET, struct sockaddr *, int *);
489 WINSOCK_API_LINKAGE int PASCAL getsockname (SOCKET, struct sockaddr *, int *);
490 WINSOCK_API_LINKAGE int PASCAL getsockopt (SOCKET, int, int, char *, int *);
492 WINSOCK_API_LINKAGE unsigned long PASCAL inet_addr (const char *);
494 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (char *) inet_ntoa (struct in_addr);
496 WINSOCK_API_LINKAGE int PASCAL listen (SOCKET, int);
497 WINSOCK_API_LINKAGE int PASCAL recv (SOCKET, char *, int, int);
498 WINSOCK_API_LINKAGE int PASCAL recvfrom (SOCKET, char *, int, int, struct sockaddr *, int *);
499 WINSOCK_API_LINKAGE int PASCAL send (SOCKET, const char *, int, int);
500 WINSOCK_API_LINKAGE int PASCAL sendto (SOCKET, const char *, int, int, const struct sockaddr *, int);
501 WINSOCK_API_LINKAGE int PASCAL setsockopt (SOCKET, int, int, const char *, int);
502 WINSOCK_API_LINKAGE int PASCAL shutdown (SOCKET, int);
504 WINSOCK_API_LINKAGE SOCKET PASCAL socket (int, int, int);
506 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct hostent *) gethostbyaddr (const char *, int, int);
507 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct hostent *) gethostbyname (const char *);
508 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct servent *) getservbyport (int, const char *);
509 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct servent *) getservbyname (const char *, const char *);
510 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct protoent *) getprotobynumber (int);
511 WINSOCK_API_LINKAGE DECLARE_STDCALL_P (struct protoent *) getprotobyname (const char *);
513 WINSOCK_API_LINKAGE int PASCAL WSAStartup (WORD, LPWSADATA);
514 WINSOCK_API_LINKAGE int PASCAL WSACleanup (void);
515 WINSOCK_API_LINKAGE void PASCAL WSASetLastError (int);
516 WINSOCK_API_LINKAGE int PASCAL WSAGetLastError (void);
518 WINSOCK_API_LINKAGE BOOL PASCAL WSAIsBlocking (void);
519 WINSOCK_API_LINKAGE int PASCAL WSAUnhookBlockingHook (void);
520 WINSOCK_API_LINKAGE FARPROC PASCAL WSASetBlockingHook (FARPROC);
521 WINSOCK_API_LINKAGE int PASCAL WSACancelBlockingCall (void);
523 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetServByName (HWND, u_int, const char *, const char *, char *, int);
524 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetServByPort (HWND, u_int, int, const char *, char *, int);
525 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetProtoByName (HWND, u_int, const char *, char *, int);
526 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetProtoByNumber (HWND, u_int, int, char *, int);
527 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetHostByName (HWND, u_int, const char *, char *, int);
528 WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetHostByAddr (HWND, u_int, const char *, int, int, char *, int);
530 WINSOCK_API_LINKAGE int PASCAL WSACancelAsyncRequest (HANDLE);
531 WINSOCK_API_LINKAGE int PASCAL WSAAsyncSelect (SOCKET, HWND, u_int, long);
533 #if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
535 WINSOCK_API_LINKAGE u_long PASCAL htonl (u_long);
536 WINSOCK_API_LINKAGE u_long PASCAL ntohl (u_long);
537 WINSOCK_API_LINKAGE u_short PASCAL htons (u_short);
538 WINSOCK_API_LINKAGE u_short PASCAL ntohs (u_short);
539 WINSOCK_API_LINKAGE int PASCAL select (int nfds, fd_set *, fd_set *, fd_set *, const struct timeval *);
540 int PASCAL gethostname (char *, int );
542 #endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
544 #define WSAMAKEASYNCREPLY(b,e) MAKELONG(b,e)
545 #define WSAMAKESELECTREPLY(e,error) MAKELONG(e,error)
546 #define WSAGETASYNCBUFLEN(l) LOWORD(l)
547 #define WSAGETASYNCERROR(l) HIWORD(l)
548 #define WSAGETSELECTEVENT(l) LOWORD(l)
549 #define WSAGETSELECTERROR(l) HIWORD(l)
551 typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
552 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
553 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
554 typedef struct linger LINGER, *PLINGER, *LPLINGER;
555 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
556 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
557 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
558 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
559 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
563 /* MSDN documentation indicates that the MS-specific extensions exported
564 * from mswsock.dll, (i.e. the AcceptEx(), TransmitFile(), WSARecEx(), and
565 * GetAcceptExSockaddrs() functions), are declared in <mswsock.h>. These
566 * extensions are not supported on Win9x or WinCE. However, WinSock v1.1
567 * dependent code may expect that the declarations and associated defines
568 * will be in this header; thus we include <mswsock.h> here.
570 * When linking against the WinSock v1.1 library, wsock32.dll, the mswsock
571 * functions are automatically routed to mswsock.dll (on platforms which
572 * support it). The WinSock v2 library, ws2_32.dll, does not contain any
573 * references to the mswsock extensions.
577 #undef __WINSOCK_H_SOURCED__
578 #endif /* _WINSOCK_H: $RCSfile$: end of file */