GlobalObjects
Lade ...
Suche ...
Keine Treffer
winsock.h
gehe zur Dokumentation dieser Datei
1#include <winapifamily.h>
2
3
4/* WINSOCK.H--definitions to be used with the WINSOCK.DLL
5 * Copyright (c) Microsoft Corporation. All rights reserved.
6 *
7 * This header file corresponds to version 1.1 of the Windows Sockets specification.
8 *
9 * This file includes parts which are Copyright (c) 1982-1986 Regents
10 * of the University of California. All rights reserved. The
11 * Berkeley Software License Agreement specifies the terms and
12 * conditions for redistribution.
13 *
14 */
15
16#ifndef _WINSOCKAPI_
17#define _WINSOCKAPI_
18
19#if _MSC_VER > 1000
20#pragma once
21#endif
22
23#pragma region Desktop Family
24#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
25
26/*
27 * Pull in WINDOWS.H if necessary
28 */
29#ifndef _INC_WINDOWS
30#include <windows.h>
31#endif /* _INC_WINDOWS */
32
33#if _MSC_VER >= 1200
34#pragma warning(push)
35#pragma warning(disable:4820) // padding added after data member
36#endif
37
38/*
39 * Basic system type definitions, taken from the BSD file sys/types.h.
40 */
41typedef unsigned char u_char;
42typedef unsigned short u_short;
43typedef unsigned int u_int;
44typedef unsigned long u_long;
45
46/*
47 * The new type to be used in all
48 * instances which refer to sockets.
49 */
50
51typedef UINT_PTR SOCKET;
52
53/*
54 * Select uses arrays of SOCKETs. These macros manipulate such
55 * arrays. FD_SETSIZE may be defined by the user before including
56 * this file, but the default here should be >= 64.
57 *
58 * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
59 * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
60 */
61#ifndef FD_SETSIZE
62#define FD_SETSIZE 64
63#endif /* FD_SETSIZE */
64
65typedef struct fd_set {
66 u_int fd_count; /* how many are SET? */
67 SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
68} fd_set;
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
75
76#ifdef __cplusplus
77}
78#endif
79
80
81#define FD_CLR(fd, set) do { \
82 u_int __i; \
83 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
84 if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
85 while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
86 ((fd_set FAR *)(set))->fd_array[__i] = \
87 ((fd_set FAR *)(set))->fd_array[__i+1]; \
88 __i++; \
89 } \
90 ((fd_set FAR *)(set))->fd_count--; \
91 break; \
92 } \
93 } \
94} while(0)
95
96#define FD_SET(fd, set) do { \
97 if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
98 ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
99} while(0)
100
101#define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
102
103#define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))
104
105/*
106 * Structure used in select() call, taken from the BSD file sys/time.h.
107 */
108struct timeval {
109 long tv_sec; /* seconds */
110 long tv_usec; /* and microseconds */
111};
112
113/*
114 * Operations on timevals.
115 *
116 * NB: timercmp does not work for >= or <=.
117 */
118#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
119#define timercmp(tvp, uvp, cmp) \
120 ((tvp)->tv_sec cmp (uvp)->tv_sec || \
121 (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
122#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
123
124/*
125 * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
126 *
127 *
128 * Ioctl's have the command encoded in the lower word,
129 * and the size of any in or out parameters in the upper
130 * word. The high 2 bits of the upper word are used
131 * to encode the in/out status of the parameter; for now
132 * we restrict parameters to at most 128 bytes.
133 */
134#define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
135#define IOC_VOID 0x20000000 /* no parameters */
136#define IOC_OUT 0x40000000 /* copy out parameters */
137#define IOC_IN 0x80000000 /* copy in parameters */
138#define IOC_INOUT (IOC_IN|IOC_OUT)
139 /* 0x20000000 distinguishes new &
140 old ioctl's */
141#define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
142
143#define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
144
145#define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
146
147#define FIONREAD _IOR('f', 127, u_long) /* get # bytes to read */
148#define FIONBIO _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
149#define FIOASYNC _IOW('f', 125, u_long) /* set/clear async i/o */
150
151/* Socket I/O Controls */
152#define SIOCSHIWAT _IOW('s', 0, u_long) /* set high watermark */
153#define SIOCGHIWAT _IOR('s', 1, u_long) /* get high watermark */
154#define SIOCSLOWAT _IOW('s', 2, u_long) /* set low watermark */
155#define SIOCGLOWAT _IOR('s', 3, u_long) /* get low watermark */
156#define SIOCATMARK _IOR('s', 7, u_long) /* at oob mark? */
157
158/*
159 * Structures returned by network data base library, taken from the
160 * BSD file netdb.h. All addresses are supplied in host order, and
161 * returned in network order (suitable for use in system calls).
162 */
163
164struct hostent {
165 char FAR * h_name; /* official name of host */
166 char FAR * FAR * h_aliases; /* alias list */
167 short h_addrtype; /* host address type */
168 short h_length; /* length of address */
169 char FAR * FAR * h_addr_list; /* list of addresses */
170#define h_addr h_addr_list[0] /* address, for backward compat */
171};
172
173/*
174 * It is assumed here that a network number
175 * fits in 32 bits.
176 */
177struct netent {
178 char FAR * n_name; /* official name of net */
179 char FAR * FAR * n_aliases; /* alias list */
180 short n_addrtype; /* net address type */
181 u_long n_net; /* network # */
182};
183
184struct servent {
185 char FAR * s_name; /* official service name */
186 char FAR * FAR * s_aliases; /* alias list */
187#ifdef _WIN64
188 char FAR * s_proto; /* protocol to use */
189 short s_port; /* port # */
190#else
191 short s_port; /* port # */
192 char FAR * s_proto; /* protocol to use */
193#endif
194};
195
196struct protoent {
197 char FAR * p_name; /* official protocol name */
198 char FAR * FAR * p_aliases; /* alias list */
199 short p_proto; /* protocol # */
200};
201
202/*
203 * Constants and structures defined by the internet system,
204 * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
205 */
206
207/*
208 * Protocols
209 */
210#define IPPROTO_IP 0 /* dummy for IP */
211#define IPPROTO_ICMP 1 /* control message protocol */
212#define IPPROTO_IGMP 2 /* group management protocol */
213#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
214#define IPPROTO_TCP 6 /* tcp */
215#define IPPROTO_PUP 12 /* pup */
216#define IPPROTO_UDP 17 /* user datagram protocol */
217#define IPPROTO_IDP 22 /* xns idp */
218#define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */
219
220#define IPPROTO_RAW 255 /* raw IP packet */
221#define IPPROTO_MAX 256
222
223/*
224 * Port/socket numbers: network standard functions
225 */
226#define IPPORT_ECHO 7
227#define IPPORT_DISCARD 9
228#define IPPORT_SYSTAT 11
229#define IPPORT_DAYTIME 13
230#define IPPORT_NETSTAT 15
231#define IPPORT_FTP 21
232#define IPPORT_TELNET 23
233#define IPPORT_SMTP 25
234#define IPPORT_TIMESERVER 37
235#define IPPORT_NAMESERVER 42
236#define IPPORT_WHOIS 43
237#define IPPORT_MTP 57
238
239/*
240 * Port/socket numbers: host specific functions
241 */
242#define IPPORT_TFTP 69
243#define IPPORT_RJE 77
244#define IPPORT_FINGER 79
245#define IPPORT_TTYLINK 87
246#define IPPORT_SUPDUP 95
247
248/*
249 * UNIX TCP sockets
250 */
251#define IPPORT_EXECSERVER 512
252#define IPPORT_LOGINSERVER 513
253#define IPPORT_CMDSERVER 514
254#define IPPORT_EFSSERVER 520
255
256/*
257 * UNIX UDP sockets
258 */
259#define IPPORT_BIFFUDP 512
260#define IPPORT_WHOSERVER 513
261#define IPPORT_ROUTESERVER 520
262 /* 520+1 also used */
263
264/*
265 * Ports < IPPORT_RESERVED are reserved for
266 * privileged processes (e.g. root).
267 */
268#define IPPORT_RESERVED 1024
269
270/*
271 * Link numbers
272 */
273#define IMPLINK_IP 155
274#define IMPLINK_LOWEXPER 156
275#define IMPLINK_HIGHEXPER 158
276
277#include <inaddr.h>
278
279/*
280 * Definitions of bits in internet address integers.
281 * On subnets, the decomposition of addresses to host and net parts
282 * is done according to subnet mask, not the masks here.
283 */
284#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
285#define IN_CLASSA_NET 0xff000000
286#define IN_CLASSA_NSHIFT 24
287#define IN_CLASSA_HOST 0x00ffffff
288#define IN_CLASSA_MAX 128
289
290#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
291#define IN_CLASSB_NET 0xffff0000
292#define IN_CLASSB_NSHIFT 16
293#define IN_CLASSB_HOST 0x0000ffff
294#define IN_CLASSB_MAX 65536
295
296#define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
297#define IN_CLASSC_NET 0xffffff00
298#define IN_CLASSC_NSHIFT 8
299#define IN_CLASSC_HOST 0x000000ff
300
301#define INADDR_ANY (u_long)0x00000000
302#define INADDR_LOOPBACK 0x7f000001
303#define INADDR_BROADCAST (u_long)0xffffffff
304#define INADDR_NONE 0xffffffff
305
306/*
307 * Socket address, internet style.
308 */
309struct sockaddr_in {
310 short sin_family;
311 u_short sin_port;
312 struct in_addr sin_addr;
313 char sin_zero[8];
314};
315
316#define WSADESCRIPTION_LEN 256
317#define WSASYS_STATUS_LEN 128
318
319typedef struct WSAData {
320 WORD wVersion;
321 WORD wHighVersion;
322#ifdef _WIN64
323 unsigned short iMaxSockets;
324 unsigned short iMaxUdpDg;
325 char FAR * lpVendorInfo;
326 char szDescription[WSADESCRIPTION_LEN+1];
327 char szSystemStatus[WSASYS_STATUS_LEN+1];
328#else
329 char szDescription[WSADESCRIPTION_LEN+1];
330 char szSystemStatus[WSASYS_STATUS_LEN+1];
331 unsigned short iMaxSockets;
332 unsigned short iMaxUdpDg;
333 char FAR * lpVendorInfo;
334#endif
335} WSADATA;
336
337typedef WSADATA FAR *LPWSADATA;
338
339/*
340 * Options for use with [gs]etsockopt at the IP level.
341 */
342#define IP_OPTIONS 1 /* set/get IP per-packet options */
343#define IP_MULTICAST_IF 2 /* set/get IP multicast interface */
344#define IP_MULTICAST_TTL 3 /* set/get IP multicast timetolive */
345#define IP_MULTICAST_LOOP 4 /* set/get IP multicast loopback */
346#define IP_ADD_MEMBERSHIP 5 /* add an IP group membership */
347#define IP_DROP_MEMBERSHIP 6 /* drop an IP group membership */
348#define IP_TTL 7 /* set/get IP Time To Live */
349#define IP_TOS 8 /* set/get IP Type Of Service */
350#define IP_DONTFRAGMENT 9 /* set/get IP Don't Fragment flag */
351
352
353#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */
354#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
355#define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */
356
357/*
358 * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
359 */
360struct ip_mreq {
361 struct in_addr imr_multiaddr; /* IP multicast address of group */
362 struct in_addr imr_interface; /* local IP address of interface */
363};
364
365/*
366 * Definitions related to sockets: types, address families, options,
367 * taken from the BSD file sys/socket.h.
368 */
369
370/*
371 * This is used instead of -1, since the
372 * SOCKET type is unsigned.
373 */
374#define INVALID_SOCKET (SOCKET)(~0)
375#define SOCKET_ERROR (-1)
376
377/*
378 * Types
379 */
380#define SOCK_STREAM 1 /* stream socket */
381#define SOCK_DGRAM 2 /* datagram socket */
382#define SOCK_RAW 3 /* raw-protocol interface */
383#define SOCK_RDM 4 /* reliably-delivered message */
384#define SOCK_SEQPACKET 5 /* sequenced packet stream */
385
386/*
387 * Option flags per-socket.
388 */
389#define SO_DEBUG 0x0001 /* turn on debugging info recording */
390#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
391#define SO_REUSEADDR 0x0004 /* allow local address reuse */
392#define SO_KEEPALIVE 0x0008 /* keep connections alive */
393#define SO_DONTROUTE 0x0010 /* just use interface addresses */
394#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
395#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
396#define SO_LINGER 0x0080 /* linger on close if data present */
397#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
398
399#define SO_DONTLINGER (u_int)(~SO_LINGER)
400
401/*
402 * Additional options.
403 */
404#define SO_SNDBUF 0x1001 /* send buffer size */
405#define SO_RCVBUF 0x1002 /* receive buffer size */
406#define SO_SNDLOWAT 0x1003 /* send low-water mark */
407#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
408#define SO_SNDTIMEO 0x1005 /* send timeout */
409#define SO_RCVTIMEO 0x1006 /* receive timeout */
410#define SO_ERROR 0x1007 /* get error status and clear */
411#define SO_TYPE 0x1008 /* get socket type */
412
413/*
414 * Options for connect and disconnect data and options. Used only by
415 * non-TCP/IP transports such as DECNet, OSI TP4, etc.
416 */
417#define SO_CONNDATA 0x7000
418#define SO_CONNOPT 0x7001
419#define SO_DISCDATA 0x7002
420#define SO_DISCOPT 0x7003
421#define SO_CONNDATALEN 0x7004
422#define SO_CONNOPTLEN 0x7005
423#define SO_DISCDATALEN 0x7006
424#define SO_DISCOPTLEN 0x7007
425
426/*
427 * Option for opening sockets for synchronous access.
428 */
429#define SO_OPENTYPE 0x7008
430
431#define SO_SYNCHRONOUS_ALERT 0x10
432#define SO_SYNCHRONOUS_NONALERT 0x20
433
434/*
435 * Other NT-specific options.
436 */
437#define SO_MAXDG 0x7009
438#define SO_MAXPATHDG 0x700A
439#define SO_UPDATE_ACCEPT_CONTEXT 0x700B
440#define SO_CONNECT_TIME 0x700C
441
442/*
443 * TCP options.
444 */
445#define TCP_NODELAY 0x0001
446#define TCP_BSDURGENT 0x7000
447
448/*
449 * Address families.
450 */
451#define AF_UNSPEC 0 /* unspecified */
452#define AF_UNIX 1 /* local to host (pipes, portals) */
453#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
454#define AF_IMPLINK 3 /* arpanet imp addresses */
455#define AF_PUP 4 /* pup protocols: e.g. BSP */
456#define AF_CHAOS 5 /* mit CHAOS protocols */
457#define AF_IPX 6 /* IPX and SPX */
458#define AF_NS 6 /* XEROX NS protocols */
459#define AF_ISO 7 /* ISO protocols */
460#define AF_OSI AF_ISO /* OSI is ISO */
461#define AF_ECMA 8 /* european computer manufacturers */
462#define AF_DATAKIT 9 /* datakit protocols */
463#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
464#define AF_SNA 11 /* IBM SNA */
465#define AF_DECnet 12 /* DECnet */
466#define AF_DLI 13 /* Direct data link interface */
467#define AF_LAT 14 /* LAT */
468#define AF_HYLINK 15 /* NSC Hyperchannel */
469#define AF_APPLETALK 16 /* AppleTalk */
470#define AF_NETBIOS 17 /* NetBios-style addresses */
471#define AF_VOICEVIEW 18 /* VoiceView */
472#define AF_FIREFOX 19 /* FireFox */
473#define AF_UNKNOWN1 20 /* Somebody is using this! */
474#define AF_BAN 21 /* Banyan */
475
476#define AF_MAX 22
477
478/*
479 * Structure used by kernel to store most
480 * addresses.
481 */
482struct sockaddr {
483 u_short sa_family; /* address family */
484 char sa_data[14]; /* up to 14 bytes of direct address */
485};
486
487/*
488 * Structure used by kernel to pass protocol
489 * information in raw sockets.
490 */
491struct sockproto {
492 u_short sp_family; /* address family */
493 u_short sp_protocol; /* protocol */
494};
495
496/*
497 * Protocol families, same as address families for now.
498 */
499#define PF_UNSPEC AF_UNSPEC
500#define PF_UNIX AF_UNIX
501#define PF_INET AF_INET
502#define PF_IMPLINK AF_IMPLINK
503#define PF_PUP AF_PUP
504#define PF_CHAOS AF_CHAOS
505#define PF_NS AF_NS
506#define PF_IPX AF_IPX
507#define PF_ISO AF_ISO
508#define PF_OSI AF_OSI
509#define PF_ECMA AF_ECMA
510#define PF_DATAKIT AF_DATAKIT
511#define PF_CCITT AF_CCITT
512#define PF_SNA AF_SNA
513#define PF_DECnet AF_DECnet
514#define PF_DLI AF_DLI
515#define PF_LAT AF_LAT
516#define PF_HYLINK AF_HYLINK
517#define PF_APPLETALK AF_APPLETALK
518#define PF_VOICEVIEW AF_VOICEVIEW
519#define PF_FIREFOX AF_FIREFOX
520#define PF_UNKNOWN1 AF_UNKNOWN1
521#define PF_BAN AF_BAN
522
523#define PF_MAX AF_MAX
524
525/*
526 * Structure used for manipulating linger option.
527 */
528struct linger {
529 u_short l_onoff; /* option on/off */
530 u_short l_linger; /* linger time */
531};
532
533/*
534 * Level number for (get/set)sockopt() to apply to socket itself.
535 */
536#define SOL_SOCKET 0xffff /* options for socket level */
537
538/*
539 * Maximum queue length specifiable by listen.
540 */
541#define SOMAXCONN 5
542
543#define MSG_OOB 0x1 /* process out-of-band data */
544#define MSG_PEEK 0x2 /* peek at incoming message */
545#define MSG_DONTROUTE 0x4 /* send without using routing tables */
546
547#define MSG_MAXIOVLEN 16
548
549#define MSG_PARTIAL 0x8000 /* partial send or recv for message xport */
550
551/*
552 * Define constant based on rfc883, used by gethostbyxxxx() calls.
553 */
554#define MAXGETHOSTSTRUCT 1024
555
556/*
557 * Define flags to be used with the WSAAsyncSelect() call.
558 */
559#define FD_READ 0x01
560#define FD_WRITE 0x02
561#define FD_OOB 0x04
562#define FD_ACCEPT 0x08
563#define FD_CONNECT 0x10
564#define FD_CLOSE 0x20
565
566/*
567 * WinSock error codes are also defined in winerror.h
568 * Hence the IFDEF.
569 */
570#ifndef WSABASEERR
571
572/*
573 * All Windows Sockets error constants are biased by WSABASEERR from
574 * the "normal"
575 */
576#define WSABASEERR 10000
577/*
578 * Windows Sockets definitions of regular Microsoft C error constants
579 */
580#define WSAEINTR (WSABASEERR+4)
581#define WSAEBADF (WSABASEERR+9)
582#define WSAEACCES (WSABASEERR+13)
583#define WSAEFAULT (WSABASEERR+14)
584#define WSAEINVAL (WSABASEERR+22)
585#define WSAEMFILE (WSABASEERR+24)
586
587/*
588 * Windows Sockets definitions of regular Berkeley error constants
589 */
590#define WSAEWOULDBLOCK (WSABASEERR+35)
591#define WSAEINPROGRESS (WSABASEERR+36)
592#define WSAEALREADY (WSABASEERR+37)
593#define WSAENOTSOCK (WSABASEERR+38)
594#define WSAEDESTADDRREQ (WSABASEERR+39)
595#define WSAEMSGSIZE (WSABASEERR+40)
596#define WSAEPROTOTYPE (WSABASEERR+41)
597#define WSAENOPROTOOPT (WSABASEERR+42)
598#define WSAEPROTONOSUPPORT (WSABASEERR+43)
599#define WSAESOCKTNOSUPPORT (WSABASEERR+44)
600#define WSAEOPNOTSUPP (WSABASEERR+45)
601#define WSAEPFNOSUPPORT (WSABASEERR+46)
602#define WSAEAFNOSUPPORT (WSABASEERR+47)
603#define WSAEADDRINUSE (WSABASEERR+48)
604#define WSAEADDRNOTAVAIL (WSABASEERR+49)
605#define WSAENETDOWN (WSABASEERR+50)
606#define WSAENETUNREACH (WSABASEERR+51)
607#define WSAENETRESET (WSABASEERR+52)
608#define WSAECONNABORTED (WSABASEERR+53)
609#define WSAECONNRESET (WSABASEERR+54)
610#define WSAENOBUFS (WSABASEERR+55)
611#define WSAEISCONN (WSABASEERR+56)
612#define WSAENOTCONN (WSABASEERR+57)
613#define WSAESHUTDOWN (WSABASEERR+58)
614#define WSAETOOMANYREFS (WSABASEERR+59)
615#define WSAETIMEDOUT (WSABASEERR+60)
616#define WSAECONNREFUSED (WSABASEERR+61)
617#define WSAELOOP (WSABASEERR+62)
618#define WSAENAMETOOLONG (WSABASEERR+63)
619#define WSAEHOSTDOWN (WSABASEERR+64)
620#define WSAEHOSTUNREACH (WSABASEERR+65)
621#define WSAENOTEMPTY (WSABASEERR+66)
622#define WSAEPROCLIM (WSABASEERR+67)
623#define WSAEUSERS (WSABASEERR+68)
624#define WSAEDQUOT (WSABASEERR+69)
625#define WSAESTALE (WSABASEERR+70)
626#define WSAEREMOTE (WSABASEERR+71)
627
628#define WSAEDISCON (WSABASEERR+101)
629
630/*
631 * Extended Windows Sockets error constant definitions
632 */
633#define WSASYSNOTREADY (WSABASEERR+91)
634#define WSAVERNOTSUPPORTED (WSABASEERR+92)
635#define WSANOTINITIALISED (WSABASEERR+93)
636
637/*
638 * Error return codes from gethostbyname() and gethostbyaddr()
639 * (when using the resolver). Note that these errors are
640 * retrieved via WSAGetLastError() and must therefore follow
641 * the rules for avoiding clashes with error numbers from
642 * specific implementations or language run-time systems.
643 * For this reason the codes are based at WSABASEERR+1001.
644 * Note also that [WSA]NO_ADDRESS is defined only for
645 * compatibility purposes.
646 */
647
648
649/* Authoritative Answer: Host not found */
650#define WSAHOST_NOT_FOUND (WSABASEERR+1001)
651
652/* Non-Authoritative: Host not found, or SERVERFAIL */
653#define WSATRY_AGAIN (WSABASEERR+1002)
654
655/* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
656#define WSANO_RECOVERY (WSABASEERR+1003)
657
658/* Valid name, no data record of requested type */
659#define WSANO_DATA (WSABASEERR+1004)
660
661/* Authoritative Answer: Host not found Securely */
662#define WSA_SECURE_HOST_NOT_FOUND (WSABASEERR+1032)
663
664
665/* Name based IPSEC policy could not be added*/
666#define WSA_IPSEC_NAME_POLICY_ERROR (WSABASEERR+1033)
667
668/*
669 * WinSock error codes are also defined in winerror.h
670 * Hence the IFDEF.
671 */
672#endif /* ifdef WSABASEERR */
673
674/*
675 * Compatibility macros.
676 */
677
678
679#define h_errno WSAGetLastError()
680#define HOST_NOT_FOUND WSAHOST_NOT_FOUND
681#define TRY_AGAIN WSATRY_AGAIN
682#define NO_RECOVERY WSANO_RECOVERY
683#define NO_DATA WSANO_DATA
684/* no address, look for MX record */
685#define WSANO_ADDRESS WSANO_DATA
686#define NO_ADDRESS WSANO_ADDRESS
687
688/*
689 * Windows Sockets errors redefined as regular Berkeley error constants.
690 * These are commented out in Windows NT to avoid conflicts with errno.h.
691 * Use the WSA constants instead.
692 */
693#if 0
694#define EWOULDBLOCK WSAEWOULDBLOCK
695#define EINPROGRESS WSAEINPROGRESS
696#define EALREADY WSAEALREADY
697#define ENOTSOCK WSAENOTSOCK
698#define EDESTADDRREQ WSAEDESTADDRREQ
699#define EMSGSIZE WSAEMSGSIZE
700#define EPROTOTYPE WSAEPROTOTYPE
701#define ENOPROTOOPT WSAENOPROTOOPT
702#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
703#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
704#define EOPNOTSUPP WSAEOPNOTSUPP
705#define EPFNOSUPPORT WSAEPFNOSUPPORT
706#define EAFNOSUPPORT WSAEAFNOSUPPORT
707#define EADDRINUSE WSAEADDRINUSE
708#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
709#define ENETDOWN WSAENETDOWN
710#define ENETUNREACH WSAENETUNREACH
711#define ENETRESET WSAENETRESET
712#define ECONNABORTED WSAECONNABORTED
713#define ECONNRESET WSAECONNRESET
714#define ENOBUFS WSAENOBUFS
715#define EISCONN WSAEISCONN
716#define ENOTCONN WSAENOTCONN
717#define ESHUTDOWN WSAESHUTDOWN
718#define ETOOMANYREFS WSAETOOMANYREFS
719#define ETIMEDOUT WSAETIMEDOUT
720#define ECONNREFUSED WSAECONNREFUSED
721#define ELOOP WSAELOOP
722#define ENAMETOOLONG WSAENAMETOOLONG
723#define EHOSTDOWN WSAEHOSTDOWN
724#define EHOSTUNREACH WSAEHOSTUNREACH
725#define ENOTEMPTY WSAENOTEMPTY
726#define EPROCLIM WSAEPROCLIM
727#define EUSERS WSAEUSERS
728#define EDQUOT WSAEDQUOT
729#define ESTALE WSAESTALE
730#define EREMOTE WSAEREMOTE
731#endif
732
733/* Socket function prototypes */
734
735#ifdef __cplusplus
736extern "C" {
737#endif
738
739SOCKET PASCAL FAR accept (
740 _In_ SOCKET s,
741 _Out_writes_bytes_opt_(*addrlen) struct sockaddr FAR *addr,
742 _Inout_opt_ int FAR *addrlen);
743
744int PASCAL FAR bind (
745 _In_ SOCKET s,
746 _In_reads_bytes_(namelen) const struct sockaddr FAR *addr,
747 _In_ int namelen);
748
749int PASCAL FAR closesocket ( IN SOCKET s);
750
751int PASCAL FAR connect (
752 _In_ SOCKET s,
753 _In_reads_bytes_(namelen) const struct sockaddr FAR *name,
754 _In_ int namelen);
755
756int PASCAL FAR ioctlsocket (
757 _In_ SOCKET s,
758 _In_ long cmd,
759 _Inout_ u_long FAR *argp);
760
761int PASCAL FAR getpeername (
762 _In_ SOCKET s,
763 _Out_writes_bytes_to_(*namelen, *namelen) struct sockaddr FAR *name,
764 _Inout_ int FAR * namelen);
765
766int PASCAL FAR getsockname (
767 _In_ SOCKET s,
768 _Out_writes_bytes_to_(*namelen, *namelen) struct sockaddr FAR *name,
769 _Inout_ int FAR * namelen);
770
771int PASCAL FAR getsockopt (
772 _In_ SOCKET s,
773 _In_ int level,
774 _In_ int optname,
775 _Out_writes_bytes_(*optlen) char FAR * optval,
776 _Inout_ int FAR *optlen);
777
778u_long PASCAL FAR htonl ( _In_ u_long hostlong);
779
780u_short PASCAL FAR htons (_In_ u_short hostshort);
781
782unsigned long PASCAL FAR inet_addr (_In_z_ const char FAR * cp);
783
784char FAR * PASCAL FAR inet_ntoa (_In_ struct in_addr in);
785
786int PASCAL FAR listen (
787 _In_ SOCKET s,
788 _In_ int backlog);
789
790u_long PASCAL FAR ntohl (_In_ u_long netlong);
791
792u_short PASCAL FAR ntohs (_In_ u_short netshort);
793
794int PASCAL FAR recv (
795 _In_ SOCKET s,
796 _Out_writes_bytes_to_(len, return) __out_data_source(NETWORK) char FAR * buf,
797 _In_ int len,
798 _In_ int flags);
799
800int PASCAL FAR recvfrom (
801 _In_ SOCKET s,
802 _Out_writes_bytes_to_(len, return) __out_data_source(NETWORK) char FAR * buf,
803 _In_ int len,
804 _In_ int flags,
805 _Out_writes_bytes_to_opt_(*fromlen, *fromlen) struct sockaddr FAR * from,
806 _Inout_opt_ int FAR * fromlen);
807
808int PASCAL FAR select (
809 _In_ int nfds,
810 _Inout_opt_ fd_set FAR *readfds,
811 _Inout_opt_ fd_set FAR *writefds,
812 _Inout_opt_ fd_set FAR *exceptfds,
813 _In_opt_ const struct timeval FAR *timeout);
814
815int PASCAL FAR send (
816 _In_ SOCKET s,
817 _In_reads_bytes_(len) const char FAR * buf,
818 _In_ int len,
819 _In_ int flags);
820
821int PASCAL FAR sendto (
822 _In_ SOCKET s,
823 _In_reads_bytes_(len) const char FAR * buf,
824 _In_ int len,
825 _In_ int flags,
826 _In_reads_bytes_opt_(tolen) const struct sockaddr FAR *to,
827 _In_ int tolen);
828
829int PASCAL FAR setsockopt (
830 _In_ SOCKET s,
831 _In_ int level,
832 _In_ int optname,
833 _In_reads_bytes_opt_(optlen) const char FAR * optval,
834 _In_ int optlen);
835
836int PASCAL FAR shutdown (
837 _In_ SOCKET s,
838 _In_ int how);
839
840SOCKET PASCAL FAR socket (
841 _In_ int af,
842 _In_ int type,
843 _In_ int protocol);
844
845/* Database function prototypes */
846
847struct hostent FAR * PASCAL FAR gethostbyaddr(
848 _In_reads_bytes_(len) const char FAR * addr,
849 _In_ int len,
850 _In_ int type);
851
852struct hostent FAR * PASCAL FAR gethostbyname(_In_z_ const char FAR * name);
853
854int PASCAL FAR gethostname (
855 _Out_writes_bytes_to_(namelen, return) char FAR * name,
856 _In_ int namelen);
857
858struct servent FAR * PASCAL FAR getservbyport(
859 _In_ int port,
860 _In_z_ const char FAR * proto);
861
862struct servent FAR * PASCAL FAR getservbyname(
863 _In_z_ const char FAR * name,
864 _In_z_ const char FAR * proto);
865
866struct protoent FAR * PASCAL FAR getprotobynumber(_In_ int proto);
867
868struct protoent FAR * PASCAL FAR getprotobyname(_In_z_ const char FAR * name);
869
870/* Microsoft Windows Extension function prototypes */
871
872int PASCAL FAR WSAStartup(
873 _In_ WORD wVersionRequired,
874 _Out_ LPWSADATA lpWSAData);
875
876int PASCAL FAR WSACleanup(void);
877
878void PASCAL FAR WSASetLastError(_In_ int iError);
879
880int PASCAL FAR WSAGetLastError(void);
881
882BOOL PASCAL FAR WSAIsBlocking(void);
883
884int PASCAL FAR WSAUnhookBlockingHook(void);
885
886FARPROC PASCAL FAR WSASetBlockingHook(_In_ FARPROC lpBlockFunc);
887
888int PASCAL FAR WSACancelBlockingCall(void);
889
890HANDLE PASCAL FAR WSAAsyncGetServByName(
891 _In_ HWND hWnd,
892 _In_ u_int wMsg,
893 _In_z_ const char FAR * name,
894 _In_z_ const char FAR * proto,
895 _Out_writes_bytes_(buflen) char FAR * buf,
896 _In_ int buflen);
897
898HANDLE PASCAL FAR WSAAsyncGetServByPort(
899 _In_ HWND hWnd,
900 _In_ u_int wMsg,
901 _In_ int port,
902 _In_ const char FAR * proto,
903 _Out_writes_bytes_(buflen) char FAR * buf,
904 _In_ int buflen);
905
906HANDLE PASCAL FAR WSAAsyncGetProtoByName(
907 _In_ HWND hWnd,
908 _In_ u_int wMsg,
909 _In_z_ const char FAR * name,
910 _Out_writes_bytes_(buflen) char FAR * buf,
911 _In_ int buflen);
912
913HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(
914 _In_ HWND hWnd,
915 _In_ u_int wMsg,
916 _In_ int number,
917 _Out_writes_bytes_(buflen) char FAR * buf,
918 _In_ int buflen);
919
920HANDLE PASCAL FAR WSAAsyncGetHostByName(
921 _In_ HWND hWnd,
922 _In_ u_int wMsg,
923 _In_z_ const char FAR * name,
924 _Out_writes_bytes_(buflen) char FAR * buf,
925 _In_ int buflen);
926
927HANDLE PASCAL FAR WSAAsyncGetHostByAddr(
928 _In_ HWND hWnd,
929 _In_ u_int wMsg,
930 _In_ const char FAR * addr,
931 _In_ int len,
932 _In_ int type,
933 _Out_writes_bytes_(buflen) char FAR * buf,
934 _In_ int buflen);
935
936int PASCAL FAR WSACancelAsyncRequest(_In_ HANDLE hAsyncTaskHandle);
937
938int PASCAL FAR WSAAsyncSelect(
939 _In_ SOCKET s,
940 _In_ HWND hWnd,
941 _In_ u_int wMsg,
942 _In_ long lEvent);
943
944int PASCAL FAR WSARecvEx (
945 _In_ SOCKET s,
946 _Out_writes_bytes_to_(len, return) __out_data_source(NETWORK) char FAR * buf,
947 _In_ int len,
948 _Inout_ int FAR *flags);
949
950typedef struct _TRANSMIT_FILE_BUFFERS {
951 PVOID Head;
952 DWORD HeadLength;
953 PVOID Tail;
954 DWORD TailLength;
955} TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, *LPTRANSMIT_FILE_BUFFERS;
956
957#define TF_DISCONNECT 0x01
958#define TF_REUSE_SOCKET 0x02
959#define TF_WRITE_BEHIND 0x04
960
961BOOL
962PASCAL FAR
963TransmitFile (
964 _In_ SOCKET hSocket,
965 _In_ HANDLE hFile,
966 _In_ DWORD nNumberOfBytesToWrite,
967 _In_ DWORD nNumberOfBytesPerSend,
968 _Inout_opt_ LPOVERLAPPED lpOverlapped,
969 _In_opt_ LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
970 _In_ DWORD dwReserved
971 );
972
973BOOL
974PASCAL FAR
975AcceptEx (
976 _In_ SOCKET sListenSocket,
977 _In_ SOCKET sAcceptSocket,
978 _Out_writes_bytes_to_(dwReceiveDataLength+dwLocalAddressLength+dwRemoteAddressLength,
979 *lpdwBytesReceived) PVOID lpOutputBuffer,
980 _In_ DWORD dwReceiveDataLength,
981 _In_ DWORD dwLocalAddressLength,
982 _In_ DWORD dwRemoteAddressLength,
983 _Out_ LPDWORD lpdwBytesReceived,
984 _Inout_ LPOVERLAPPED lpOverlapped
985 );
986
987VOID
988PASCAL FAR
989GetAcceptExSockaddrs (
990 _In_reads_bytes_(dwReceiveDataLength+dwLocalAddressLength+dwRemoteAddressLength) PVOID lpOutputBuffer,
991 _In_ DWORD dwReceiveDataLength,
992 _In_ DWORD dwLocalAddressLength,
993 _In_ DWORD dwRemoteAddressLength,
994 _Outptr_result_bytebuffer_(*LocalSockaddrLength) struct sockaddr **LocalSockaddr,
995 _Out_ LPINT LocalSockaddrLength,
996 _Outptr_result_bytebuffer_(*RemoteSockaddrLength) struct sockaddr **RemoteSockaddr,
997 _Out_ LPINT RemoteSockaddrLength
998 );
999
1000#ifdef __cplusplus
1001}
1002#endif
1003
1004/* Microsoft Windows Extended data types */
1005typedef struct sockaddr SOCKADDR;
1006typedef struct sockaddr *PSOCKADDR;
1007typedef struct sockaddr FAR *LPSOCKADDR;
1008
1009typedef struct sockaddr_in SOCKADDR_IN;
1010typedef struct sockaddr_in *PSOCKADDR_IN;
1011typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
1012
1013typedef struct linger LINGER;
1014typedef struct linger *PLINGER;
1015typedef struct linger FAR *LPLINGER;
1016
1017typedef struct fd_set FD_SET;
1018typedef struct fd_set *PFD_SET;
1019typedef struct fd_set FAR *LPFD_SET;
1020
1021typedef struct hostent HOSTENT;
1022typedef struct hostent *PHOSTENT;
1023typedef struct hostent FAR *LPHOSTENT;
1024
1025typedef struct servent SERVENT;
1026typedef struct servent *PSERVENT;
1027typedef struct servent FAR *LPSERVENT;
1028
1029typedef struct protoent PROTOENT;
1030typedef struct protoent *PPROTOENT;
1031typedef struct protoent FAR *LPPROTOENT;
1032
1033typedef struct timeval TIMEVAL;
1034typedef struct timeval *PTIMEVAL;
1035typedef struct timeval FAR *LPTIMEVAL;
1036
1037/*
1038 * Windows message parameter composition and decomposition
1039 * macros.
1040 *
1041 * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
1042 * when constructing the response to a WSAAsyncGetXByY() routine.
1043 */
1044#define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
1045/*
1046 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
1047 * when constructing the response to WSAAsyncSelect().
1048 */
1049#define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
1050/*
1051 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
1052 * to extract the buffer length from the lParam in the response
1053 * to a WSAGetXByY().
1054 */
1055#define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
1056/*
1057 * WSAGETASYNCERROR is intended for use by the Windows Sockets application
1058 * to extract the error code from the lParam in the response
1059 * to a WSAGetXByY().
1060 */
1061#define WSAGETASYNCERROR(lParam) HIWORD(lParam)
1062/*
1063 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
1064 * to extract the event code from the lParam in the response
1065 * to a WSAAsyncSelect().
1066 */
1067#define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
1068/*
1069 * WSAGETSELECTERROR is intended for use by the Windows Sockets application
1070 * to extract the error code from the lParam in the response
1071 * to a WSAAsyncSelect().
1072 */
1073#define WSAGETSELECTERROR(lParam) HIWORD(lParam)
1074
1075#if(_WIN32_WINNT >= 0x0501)
1076#ifdef IPV6STRICT
1077#error WINSOCK2 required.
1078#endif // IPV6STRICT
1079#endif //(_WIN32_WINNT >= 0x0501)
1080
1081#if _MSC_VER >= 1200
1082#pragma warning(pop)
1083#endif
1084
1085#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
1086#pragma endregion
1087
1088#endif /* _WINSOCKAPI_ */
1089