PageRenderTime 139ms CodeModel.GetById 19ms app.highlight 108ms RepoModel.GetById 1ms app.codeStats 1ms

/binding/win32/winsock2.d

http://github.com/wilkie/djehuty
D | 2953 lines | 2104 code | 464 blank | 385 comment | 36 complexity | ea415c9c9c27ec931beddd9f0ef5d746 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2 * winsock2.d
   3 *
   4 * This module binds WinSock2.h to D. The original copyright
   5 * notice is preserved below.
   6 *
   7 * Author: Dave Wilkinson
   8 * Originated: November 25th, 2009
   9 *
  10 */
  11
  12module binding.win32.winsock2;
  13
  14import binding.c;
  15
  16import binding.win32.windef;
  17import binding.win32.winerror;
  18import binding.win32.guiddef;
  19import binding.win32.winbase;
  20import binding.win32.winnt;
  21import binding.win32.ws2def;
  22import binding.win32.qos;
  23import binding.win32.inaddr;
  24
  25extern(System):
  26
  27/*
  28 * Basic system type definitions, taken from the BSD file sys/types.h.
  29 */
  30alias ubyte    u_char;
  31alias ushort   u_short;
  32alias uint     u_int;
  33alias Culong_t u_long;
  34
  35alias ulong u_int64;
  36
  37/*
  38 * The new type to be used in all
  39 * instances which refer to sockets.
  40 */
  41alias UINT_PTR        SOCKET;
  42
  43/*
  44 * Select uses arrays of SOCKETs.  These macros manipulate such
  45 * arrays.  FD_SETSIZE may be defined by the user before including
  46 * this file, but the default here should be >= 64.
  47 *
  48 * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  49 * INCLUDED IN WINSOCK2.H EXACTLY AS SHOWN HERE.
  50 */
  51
  52const auto FD_SETSIZE       = 64;
  53
  54struct fd_set {
  55        u_int fd_count;               /* how many are SET? */
  56        SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  57}
  58
  59
  60extern(C) int __WSAFDIsSet(SOCKET fd, fd_set *);
  61
  62/*
  63const auto FD_CLR(fd,  = set) do { \;
  64    u_int __i; \
  65    for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) { \
  66        if (((fd_set *)(set))->fd_array[__i] == fd) { \
  67            while (__i < ((fd_set *)(set))->fd_count-1) { \
  68                ((fd_set *)(set))->fd_array[__i] = \
  69                    ((fd_set *)(set))->fd_array[__i+1]; \
  70                __i++; \
  71            } \
  72            ((fd_set *)(set))->fd_count--; \
  73            break; \
  74        } \
  75    } \
  76} while(0)
  77
  78const auto FD_SET(fd,  = set) do { \;
  79    u_int __i; \
  80    for (__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) { \
  81        if (((fd_set *)(set))->fd_array[__i] == (fd)) { \
  82            break; \
  83        } \
  84    } \
  85    if (__i == ((fd_set *)(set))->fd_count) { \
  86        if (((fd_set *)(set))->fd_count < FD_SETSIZE) { \
  87            ((fd_set *)(set))->fd_array[__i] = (fd); \
  88            ((fd_set *)(set))->fd_count++; \
  89        } \
  90    } \
  91} while(0)
  92
  93const auto FD_ZERO(set)  = (((fd_set *)(set))->fd_count=0);
  94
  95const auto FD_ISSET(fd,  = set) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set));
  96*/
  97
  98/*
  99 * Structure used in select() call, taken from the BSD file sys/time.h.
 100 */
 101struct timeval {
 102        Clong_t    tv_sec;         /* seconds */
 103        Clong_t    tv_usec;        /* and microseconds */
 104}
 105
 106/*
 107 * Operations on timevals.
 108 *
 109 * NB: timercmp does not work for >= or <=.
 110 */
 111
 112/*const auto timerisset(tvp)          = ((tvp)->tv_sec || (tvp)->tv_usec);
 113const auto timercmp(tvp,  = uvp, cmp) \;
 114        ((tvp)->tv_sec cmp (uvp)->tv_sec || \
 115         (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
 116const auto timerclear(tvp)          = (tvp)->tv_sec = (tvp)->tv_usec = 0;
 117*/
 118
 119/*
 120 * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
 121 *
 122 *
 123 * Ioctl's have the command encoded in the lower word,
 124 * and the size of any in or out parameters in the upper
 125 * word.  The high 2 bits of the upper word are used
 126 * to encode the in/out status of the parameter; for now
 127 * we restrict parameters to at most 128 bytes.
 128 */
 129const auto IOCPARM_MASK     = 0x7f            ; /* parameters must be < 128 bytes */
 130const auto IOC_VOID         = 0x20000000      ; /* no parameters */
 131const auto IOC_OUT          = 0x40000000      ; /* copy out parameters */
 132const auto IOC_IN           = 0x80000000      ; /* copy in parameters */
 133const auto IOC_INOUT        = (IOC_IN|IOC_OUT);
 134                                        /* 0x20000000 distinguishes new &
 135                                           old ioctl's */
 136
 137template _IO(uint x, uint y) {
 138	const auto _IO = (IOC_VOID|((x)<<8)|(y));
 139}
 140
 141template _IOR(char x, uint y, T) {
 142	const auto _IOR = (IOC_OUT|(((cast(Clong_t)T.sizeof) & IOCPARM_MASK)<<16)|((x)<<8)|(y));
 143}
 144
 145template _IOW(char x, uint y, T) {
 146	const auto _IOW = (IOC_IN|(((cast(Clong_t)T.sizeof) & IOCPARM_MASK)<<16)|((x)<<8)|(y));
 147}
 148
 149const auto FIONREAD     = _IOR!('f', 127, u_long) ; /* get # bytes to read */
 150const auto FIONBIO      = _IOW!('f', 126, u_long) ; /* set/clear non-blocking i/o */
 151const auto FIOASYNC     = _IOW!('f', 125, u_long) ; /* set/clear async i/o */
 152
 153/* Socket I/O Controls */
 154const auto SIOCSHIWAT   = _IOW!('s',  0, u_long)  ; /* set high watermark */
 155const auto SIOCGHIWAT   = _IOR!('s',  1, u_long)  ; /* get high watermark */
 156const auto SIOCSLOWAT   = _IOW!('s',  2, u_long)  ; /* set low watermark */
 157const auto SIOCGLOWAT   = _IOR!('s',  3, u_long)  ; /* get low watermark */
 158const auto SIOCATMARK   = _IOR!('s',  7, u_long)  ; /* at oob mark? */
 159
 160/*
 161 * Structures returned by network data base library, taken from the
 162 * BSD file netdb.h.  All addresses are supplied in host order, and
 163 * returned in network order (suitable for use in system calls).
 164 */
 165
 166struct  hostent {
 167        char    * h_name;           /* official name of host */
 168        char    * * h_aliases;  /* alias list */
 169        short   h_addrtype;             /* host address type */
 170        short   h_length;               /* length of address */
 171        char    * * h_addr_list; /* list of addresses */
 172//const auto h_addr   = h_addr_list[0]          ; /* address, for backward compat */
 173}
 174
 175/*
 176 * It is assumed here that a network number
 177 * fits in 32 bits.
 178 */
 179struct  netent {
 180        char    * n_name;           /* official name of net */
 181        char    * * n_aliases;  /* alias list */
 182        short   n_addrtype;             /* net address type */
 183        u_long  n_net;                  /* network # */
 184}
 185
 186struct  servent {
 187        char    * s_name;           /* official service name */
 188        char    * * s_aliases;  /* alias list */
 189	version(X86_64) {
 190	        char    * s_proto;          /* protocol to use */
 191	        short   s_port;                 /* port # */
 192	}
 193	else {
 194	        short   s_port;                 /* port # */
 195	        char    * s_proto;          /* protocol to use */
 196	}
 197}
 198
 199struct  protoent {
 200        char    * p_name;           /* official protocol name */
 201        char    * * p_aliases;  /* alias list */
 202        short   p_proto;                /* protocol # */
 203}
 204
 205/*
 206 * Constants and structures defined by the internet system,
 207 * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
 208 * IPv6 additions per RFC 2292.
 209 */
 210
 211/*
 212 * Port/socket numbers: network standard functions
 213 */
 214const auto IPPORT_ECHO              = 7;
 215const auto IPPORT_DISCARD           = 9;
 216const auto IPPORT_SYSTAT            = 11;
 217const auto IPPORT_DAYTIME           = 13;
 218const auto IPPORT_NETSTAT           = 15;
 219const auto IPPORT_FTP               = 21;
 220const auto IPPORT_TELNET            = 23;
 221const auto IPPORT_SMTP              = 25;
 222const auto IPPORT_TIMESERVER        = 37;
 223const auto IPPORT_NAMESERVER        = 42;
 224const auto IPPORT_WHOIS             = 43;
 225const auto IPPORT_MTP               = 57;
 226
 227/*
 228 * Port/socket numbers: host specific functions
 229 */
 230const auto IPPORT_TFTP              = 69;
 231const auto IPPORT_RJE               = 77;
 232const auto IPPORT_FINGER            = 79;
 233const auto IPPORT_TTYLINK           = 87;
 234const auto IPPORT_SUPDUP            = 95;
 235
 236/*
 237 * UNIX TCP sockets
 238 */
 239const auto IPPORT_EXECSERVER        = 512;
 240const auto IPPORT_LOGINSERVER       = 513;
 241const auto IPPORT_CMDSERVER         = 514;
 242const auto IPPORT_EFSSERVER         = 520;
 243
 244/*
 245 * UNIX UDP sockets
 246 */
 247const auto IPPORT_BIFFUDP           = 512;
 248const auto IPPORT_WHOSERVER         = 513;
 249const auto IPPORT_ROUTESERVER       = 520;
 250                                        /* 520+1 also used */
 251
 252/*
 253 * Ports < IPPORT_RESERVED are reserved for
 254 * privileged processes (e.g. root).
 255 */
 256const auto IPPORT_RESERVED          = 1024;
 257
 258/*
 259 * Link numbers
 260 */
 261const auto IMPLINK_IP               = 155;
 262const auto IMPLINK_LOWEXPER         = 156;
 263const auto IMPLINK_HIGHEXPER        = 158;
 264
 265const auto ADDR_ANY                 = INADDR_ANY;
 266
 267const auto WSADESCRIPTION_LEN       = 256;
 268const auto WSASYS_STATUS_LEN        = 128;
 269
 270struct WSADATA {
 271        WORD                    wVersion;
 272        WORD                    wHighVersion;
 273	version(X86_64) {
 274	        ushort          iMaxSockets;
 275	        ushort          iMaxUdpDg;
 276	        char *              lpVendorInfo;
 277	        char[WSADESCRIPTION_LEN+1]                    szDescription;
 278	        char[WSASYS_STATUS_LEN+1]                    szSystemStatus;
 279	}
 280	else {
 281	        char[WSADESCRIPTION_LEN+1]                    szDescription;
 282	        char[WSASYS_STATUS_LEN+1]                    szSystemStatus;
 283	        ushort          iMaxSockets;
 284	        ushort          iMaxUdpDg;
 285	        char *              lpVendorInfo;
 286	}
 287}
 288
 289alias WSADATA * LPWSADATA;
 290
 291/*
 292 * Definitions related to sockets: types, address families, options,
 293 * taken from the BSD file sys/socket.h.
 294 */
 295
 296/*
 297 * This is used instead of -1, since the
 298 * SOCKET type is unsigned.
 299 */
 300const auto INVALID_SOCKET   = cast(SOCKET)(~0);
 301const auto SOCKET_ERROR             = (-1);
 302
 303/*
 304 * The  following  may  be used in place of the address family, socket type, or
 305 * protocol  in  a  call  to WSASocket to indicate that the corresponding value
 306 * should  be taken from the supplied WSAPROTOCOL_INFO structure instead of the
 307 * parameter itself.
 308 */
 309const auto FROM_PROTOCOL_INFO  = (-1);
 310
 311/*
 312 * Types
 313 */
 314 
 315// defined ws2def.d
 316
 317//const auto SOCK_STREAM      = 1               ; /* stream socket */
 318//const auto SOCK_DGRAM       = 2               ; /* datagram socket */
 319//const auto SOCK_RAW         = 3               ; /* raw-protocol interface */
 320//const auto SOCK_RDM         = 4               ; /* reliably-delivered message */
 321//const auto SOCK_SEQPACKET   = 5               ; /* sequenced packet stream */
 322
 323/*
 324 * Option flags per-socket.
 325 */
 326const auto SO_DEBUG         = 0x0001          ; /* turn on debugging info recording */
 327const auto SO_ACCEPTCONN    = 0x0002          ; /* socket has had listen() */
 328const auto SO_REUSEADDR     = 0x0004          ; /* allow local address reuse */
 329const auto SO_KEEPALIVE     = 0x0008          ; /* keep connections alive */
 330const auto SO_DONTROUTE     = 0x0010          ; /* just use interface addresses */
 331const auto SO_BROADCAST     = 0x0020          ; /* permit sending of broadcast msgs */
 332const auto SO_USELOOPBACK   = 0x0040          ; /* bypass hardware when possible */
 333const auto SO_LINGER        = 0x0080          ; /* linger on close if data present */
 334const auto SO_OOBINLINE     = 0x0100          ; /* leave received OOB data in line */
 335
 336const auto SO_DONTLINGER    = cast(int)(~SO_LINGER);
 337const auto SO_EXCLUSIVEADDRUSE  = (cast(int)(~SO_REUSEADDR)) ; /* disallow local address reuse */
 338
 339/*
 340 * Additional options.
 341 */
 342const auto SO_SNDBUF        = 0x1001          ; /* send buffer size */
 343const auto SO_RCVBUF        = 0x1002          ; /* receive buffer size */
 344const auto SO_SNDLOWAT      = 0x1003          ; /* send low-water mark */
 345const auto SO_RCVLOWAT      = 0x1004          ; /* receive low-water mark */
 346const auto SO_SNDTIMEO      = 0x1005          ; /* send timeout */
 347const auto SO_RCVTIMEO      = 0x1006          ; /* receive timeout */
 348const auto SO_ERROR         = 0x1007          ; /* get error status and clear */
 349const auto SO_TYPE          = 0x1008          ; /* get socket type */
 350
 351/*
 352 * WinSock 2 extension -- new options
 353 */
 354const auto SO_GROUP_ID        = 0x2001      ; /* ID of a socket group */
 355const auto SO_GROUP_PRIORITY  = 0x2002      ; /* the relative priority within a group*/
 356const auto SO_MAX_MSG_SIZE    = 0x2003      ; /* maximum message size */
 357const auto SO_PROTOCOL_INFOA  = 0x2004      ; /* WSAPROTOCOL_INFOA structure */
 358const auto SO_PROTOCOL_INFOW  = 0x2005      ; /* WSAPROTOCOL_INFOW structure */
 359
 360version(UNICODE) {
 361	alias SO_PROTOCOL_INFOW SO_PROTOCOL_INFO;
 362}
 363else {
 364	alias SO_PROTOCOL_INFOA SO_PROTOCOL_INFO;
 365}
 366
 367const auto PVD_CONFIG         = 0x3001       ; /* configuration info for service provider */
 368const auto SO_CONDITIONAL_ACCEPT  = 0x3002   ; /* enable true conditional accept: */
 369                                       /*  connection is not ack-ed to the */
 370                                       /*  other side until conditional */
 371                                       /*  function returns CF_ACCEPT */
 372
 373/*
 374 * Structure used by kernel to pass protocol
 375 * information in raw sockets.
 376 */
 377struct sockproto {
 378        u_short sp_family;              /* address family */
 379        u_short sp_protocol;            /* protocol */
 380}
 381
 382/*
 383 * Protocol families, same as address families for now.
 384 */
 385const auto PF_UNSPEC        = AF_UNSPEC;
 386const auto PF_UNIX          = AF_UNIX;
 387const auto PF_INET          = AF_INET;
 388const auto PF_IMPLINK       = AF_IMPLINK;
 389const auto PF_PUP           = AF_PUP;
 390const auto PF_CHAOS         = AF_CHAOS;
 391const auto PF_NS            = AF_NS;
 392const auto PF_IPX           = AF_IPX;
 393const auto PF_ISO           = AF_ISO;
 394const auto PF_OSI           = AF_OSI;
 395const auto PF_ECMA          = AF_ECMA;
 396const auto PF_DATAKIT       = AF_DATAKIT;
 397const auto PF_CCITT         = AF_CCITT;
 398const auto PF_SNA           = AF_SNA;
 399const auto PF_DECnet        = AF_DECnet;
 400const auto PF_DLI           = AF_DLI;
 401const auto PF_LAT           = AF_LAT;
 402const auto PF_HYLINK        = AF_HYLINK;
 403const auto PF_APPLETALK     = AF_APPLETALK;
 404const auto PF_VOICEVIEW     = AF_VOICEVIEW;
 405const auto PF_FIREFOX       = AF_FIREFOX;
 406const auto PF_UNKNOWN1      = AF_UNKNOWN1;
 407const auto PF_BAN           = AF_BAN;
 408const auto PF_ATM           = AF_ATM;
 409const auto PF_INET6         = AF_INET6;
 410
 411const auto PF_BTH           = AF_BTH;
 412
 413const auto PF_MAX           = AF_MAX;
 414
 415/*
 416 * Structure used for manipulating linger option.
 417 */
 418struct  linger {
 419        u_short l_onoff;                /* option on/off */
 420        u_short l_linger;               /* linger time */
 421}
 422
 423/*
 424 * Level number for (get/set)sockopt() to apply to socket itself.
 425 */
 426const auto SOL_SOCKET       = 0xffff          ; /* options for socket level */
 427
 428/*
 429 * Maximum queue length specifiable by listen.
 430 */
 431const auto SOMAXCONN        = 0x7fffffff;
 432
 433const auto MSG_OOB          = 0x1             ; /* process out-of-band data */
 434const auto MSG_PEEK         = 0x2             ; /* peek at incoming message */
 435const auto MSG_DONTROUTE    = 0x4             ; /* send without using routing tables */
 436
 437const auto MSG_WAITALL      = 0x8             ; /* do not complete until packet is completely filled */
 438
 439const auto MSG_PARTIAL      = 0x8000          ; /* partial send or recv for message xport */
 440
 441/*
 442 * WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() and
 443 *                          WSARecvFrom()
 444 */
 445const auto MSG_INTERRUPT    = 0x10            ; /* send/recv in the interrupt context */
 446
 447const auto MSG_MAXIOVLEN    = 16;
 448
 449/*
 450 * Define constant based on rfc883, used by gethostbyxxxx() calls.
 451 */
 452const auto MAXGETHOSTSTRUCT         = 1024;
 453
 454/*
 455 * WinSock 2 extension -- bit values and indices for FD_XXX network events
 456 */
 457const auto FD_READ_BIT       = 0;
 458const auto FD_READ           = (1 << FD_READ_BIT);
 459
 460const auto FD_WRITE_BIT      = 1;
 461const auto FD_WRITE          = (1 << FD_WRITE_BIT);
 462
 463const auto FD_OOB_BIT        = 2;
 464const auto FD_OOB            = (1 << FD_OOB_BIT);
 465
 466const auto FD_ACCEPT_BIT     = 3;
 467const auto FD_ACCEPT         = (1 << FD_ACCEPT_BIT);
 468
 469const auto FD_CONNECT_BIT    = 4;
 470const auto FD_CONNECT        = (1 << FD_CONNECT_BIT);
 471
 472const auto FD_CLOSE_BIT      = 5;
 473const auto FD_CLOSE          = (1 << FD_CLOSE_BIT);
 474
 475const auto FD_QOS_BIT        = 6;
 476const auto FD_QOS            = (1 << FD_QOS_BIT);
 477
 478const auto FD_GROUP_QOS_BIT  = 7;
 479const auto FD_GROUP_QOS      = (1 << FD_GROUP_QOS_BIT);
 480
 481const auto FD_ROUTING_INTERFACE_CHANGE_BIT  = 8;
 482const auto FD_ROUTING_INTERFACE_CHANGE      = (1 << FD_ROUTING_INTERFACE_CHANGE_BIT);
 483
 484const auto FD_ADDRESS_LIST_CHANGE_BIT  = 9;
 485const auto FD_ADDRESS_LIST_CHANGE      = (1 << FD_ADDRESS_LIST_CHANGE_BIT);
 486
 487const auto FD_MAX_EVENTS     = 10;
 488const auto FD_ALL_EVENTS     = ((1 << FD_MAX_EVENTS) - 1);
 489
 490
 491/*
 492 * WinSock error codes are also defined in winerror.h
 493 * Hence the IFDEF.
 494 */
 495
 496/*
 497 * All Windows Sockets error constants are biased by WSABASEERR from
 498 * the "normal"
 499 */
 500const auto WSABASEERR               = 10000;
 501
 502/*
 503 * Windows Sockets definitions of regular Microsoft C error constants
 504 */
 505const auto WSAEINTR                 = (WSABASEERR+4);
 506const auto WSAEBADF                 = (WSABASEERR+9);
 507const auto WSAEACCES                = (WSABASEERR+13);
 508const auto WSAEFAULT                = (WSABASEERR+14);
 509const auto WSAEINVAL                = (WSABASEERR+22);
 510const auto WSAEMFILE                = (WSABASEERR+24);
 511
 512/*
 513 * Windows Sockets definitions of regular Berkeley error constants
 514 */
 515const auto WSAEWOULDBLOCK           = (WSABASEERR+35);
 516const auto WSAEINPROGRESS           = (WSABASEERR+36);
 517const auto WSAEALREADY              = (WSABASEERR+37);
 518const auto WSAENOTSOCK              = (WSABASEERR+38);
 519const auto WSAEDESTADDRREQ          = (WSABASEERR+39);
 520const auto WSAEMSGSIZE              = (WSABASEERR+40);
 521const auto WSAEPROTOTYPE            = (WSABASEERR+41);
 522const auto WSAENOPROTOOPT           = (WSABASEERR+42);
 523const auto WSAEPROTONOSUPPORT       = (WSABASEERR+43);
 524const auto WSAESOCKTNOSUPPORT       = (WSABASEERR+44);
 525const auto WSAEOPNOTSUPP            = (WSABASEERR+45);
 526const auto WSAEPFNOSUPPORT          = (WSABASEERR+46);
 527const auto WSAEAFNOSUPPORT          = (WSABASEERR+47);
 528const auto WSAEADDRINUSE            = (WSABASEERR+48);
 529const auto WSAEADDRNOTAVAIL         = (WSABASEERR+49);
 530const auto WSAENETDOWN              = (WSABASEERR+50);
 531const auto WSAENETUNREACH           = (WSABASEERR+51);
 532const auto WSAENETRESET             = (WSABASEERR+52);
 533const auto WSAECONNABORTED          = (WSABASEERR+53);
 534const auto WSAECONNRESET            = (WSABASEERR+54);
 535const auto WSAENOBUFS               = (WSABASEERR+55);
 536const auto WSAEISCONN               = (WSABASEERR+56);
 537const auto WSAENOTCONN              = (WSABASEERR+57);
 538const auto WSAESHUTDOWN             = (WSABASEERR+58);
 539const auto WSAETOOMANYREFS          = (WSABASEERR+59);
 540const auto WSAETIMEDOUT             = (WSABASEERR+60);
 541const auto WSAECONNREFUSED          = (WSABASEERR+61);
 542const auto WSAELOOP                 = (WSABASEERR+62);
 543const auto WSAENAMETOOLONG          = (WSABASEERR+63);
 544const auto WSAEHOSTDOWN             = (WSABASEERR+64);
 545const auto WSAEHOSTUNREACH          = (WSABASEERR+65);
 546const auto WSAENOTEMPTY             = (WSABASEERR+66);
 547const auto WSAEPROCLIM              = (WSABASEERR+67);
 548const auto WSAEUSERS                = (WSABASEERR+68);
 549const auto WSAEDQUOT                = (WSABASEERR+69);
 550const auto WSAESTALE                = (WSABASEERR+70);
 551const auto WSAEREMOTE               = (WSABASEERR+71);
 552
 553/*
 554 * Extended Windows Sockets error constant definitions
 555 */
 556const auto WSASYSNOTREADY           = (WSABASEERR+91);
 557const auto WSAVERNOTSUPPORTED       = (WSABASEERR+92);
 558const auto WSANOTINITIALISED        = (WSABASEERR+93);
 559const auto WSAEDISCON               = (WSABASEERR+101);
 560const auto WSAENOMORE               = (WSABASEERR+102);
 561const auto WSAECANCELLED            = (WSABASEERR+103);
 562const auto WSAEINVALIDPROCTABLE     = (WSABASEERR+104);
 563const auto WSAEINVALIDPROVIDER      = (WSABASEERR+105);
 564const auto WSAEPROVIDERFAILEDINIT   = (WSABASEERR+106);
 565const auto WSASYSCALLFAILURE        = (WSABASEERR+107);
 566const auto WSASERVICE_NOT_FOUND     = (WSABASEERR+108);
 567const auto WSATYPE_NOT_FOUND        = (WSABASEERR+109);
 568const auto WSA_E_NO_MORE            = (WSABASEERR+110);
 569const auto WSA_E_CANCELLED          = (WSABASEERR+111);
 570const auto WSAEREFUSED              = (WSABASEERR+112);
 571
 572/*
 573 * Error return codes from gethostbyname() and gethostbyaddr()
 574 * (when using the resolver). Note that these errors are
 575 * retrieved via WSAGetLastError() and must therefore follow
 576 * the rules for avoiding clashes with error numbers from
 577 * specific implementations or language run-time systems.
 578 * For this reason the codes are based at WSABASEERR+1001.
 579 * Note also that [WSA]NO_ADDRESS is defined only for
 580 * compatibility purposes.
 581 */
 582
 583/* Authoritative Answer: Host not found */
 584const auto WSAHOST_NOT_FOUND        = (WSABASEERR+1001);
 585
 586/* Non-Authoritative: Host not found, or SERVERFAIL */
 587const auto WSATRY_AGAIN             = (WSABASEERR+1002);
 588
 589/* Non-recoverable errors, FORMERR, REFUSED, NOTIMP */
 590const auto WSANO_RECOVERY           = (WSABASEERR+1003);
 591
 592/* Valid name, no data record of requested type */
 593const auto WSANO_DATA               = (WSABASEERR+1004);
 594
 595/*
 596 * Define QOS related error return codes
 597 *
 598 */
 599const auto   WSA_QOS_RECEIVERS               = (WSABASEERR + 1005);
 600         /* at least one Reserve has arrived */
 601const auto   WSA_QOS_SENDERS                 = (WSABASEERR + 1006);
 602         /* at least one Path has arrived */
 603const auto   WSA_QOS_NO_SENDERS              = (WSABASEERR + 1007);
 604         /* there are no senders */
 605const auto   WSA_QOS_NO_RECEIVERS            = (WSABASEERR + 1008);
 606         /* there are no receivers */
 607const auto   WSA_QOS_REQUEST_CONFIRMED       = (WSABASEERR + 1009);
 608         /* Reserve has been confirmed */
 609const auto   WSA_QOS_ADMISSION_FAILURE       = (WSABASEERR + 1010);
 610         /* error due to lack of resources */
 611const auto   WSA_QOS_POLICY_FAILURE          = (WSABASEERR + 1011);
 612         /* rejected for administrative reasons - bad credentials */
 613const auto   WSA_QOS_BAD_STYLE               = (WSABASEERR + 1012);
 614         /* unknown or conflicting style */
 615const auto   WSA_QOS_BAD_OBJECT              = (WSABASEERR + 1013);
 616         /* problem with some part of the filterspec or providerspecific
 617          * buffer in general */
 618const auto   WSA_QOS_TRAFFIC_CTRL_ERROR      = (WSABASEERR + 1014);
 619         /* problem with some part of the flowspec */
 620const auto   WSA_QOS_GENERIC_ERROR           = (WSABASEERR + 1015);
 621         /* general error */
 622const auto   WSA_QOS_ESERVICETYPE            = (WSABASEERR + 1016);
 623         /* invalid service type in flowspec */
 624const auto   WSA_QOS_EFLOWSPEC               = (WSABASEERR + 1017);
 625         /* invalid flowspec */
 626const auto   WSA_QOS_EPROVSPECBUF            = (WSABASEERR + 1018);
 627         /* invalid provider specific buffer */
 628const auto   WSA_QOS_EFILTERSTYLE            = (WSABASEERR + 1019);
 629         /* invalid filter style */
 630const auto   WSA_QOS_EFILTERTYPE             = (WSABASEERR + 1020);
 631         /* invalid filter type */
 632const auto   WSA_QOS_EFILTERCOUNT            = (WSABASEERR + 1021);
 633         /* incorrect number of filters */
 634const auto   WSA_QOS_EOBJLENGTH              = (WSABASEERR + 1022);
 635         /* invalid object length */
 636const auto   WSA_QOS_EFLOWCOUNT              = (WSABASEERR + 1023);
 637         /* incorrect number of flows */
 638const auto   WSA_QOS_EUNKOWNPSOBJ            = (WSABASEERR + 1024);
 639         /* unknown object in provider specific buffer */
 640const auto   WSA_QOS_EPOLICYOBJ              = (WSABASEERR + 1025);
 641         /* invalid policy object in provider specific buffer */
 642const auto   WSA_QOS_EFLOWDESC               = (WSABASEERR + 1026);
 643         /* invalid flow descriptor in the list */
 644const auto   WSA_QOS_EPSFLOWSPEC             = (WSABASEERR + 1027);
 645         /* inconsistent flow spec in provider specific buffer */
 646const auto   WSA_QOS_EPSFILTERSPEC           = (WSABASEERR + 1028);
 647         /* invalid filter spec in provider specific buffer */
 648const auto   WSA_QOS_ESDMODEOBJ              = (WSABASEERR + 1029);
 649         /* invalid shape discard mode object in provider specific buffer */
 650const auto   WSA_QOS_ESHAPERATEOBJ           = (WSABASEERR + 1030);
 651         /* invalid shaping rate object in provider specific buffer */
 652const auto   WSA_QOS_RESERVED_PETYPE         = (WSABASEERR + 1031);
 653         /* reserved policy element in provider specific buffer */
 654
 655
 656
 657/*
 658 * WinSock error codes are also defined in winerror.h
 659 * Hence the IFDEF.
 660 */
 661
 662/*
 663 * Compatibility macros.
 664 */
 665
 666alias WSAGetLastError h_errno;
 667
 668const auto HOST_NOT_FOUND           = WSAHOST_NOT_FOUND;
 669const auto TRY_AGAIN                = WSATRY_AGAIN;
 670const auto NO_RECOVERY              = WSANO_RECOVERY;
 671const auto NO_DATA                  = WSANO_DATA;
 672/* no address, look for MX record */
 673const auto WSANO_ADDRESS            = WSANO_DATA;
 674const auto NO_ADDRESS               = WSANO_ADDRESS;
 675
 676/*
 677 * WinSock 2 extension -- new error codes and type definition
 678 */
 679
 680alias HANDLE WSAEVENT;
 681alias LPHANDLE LPWSAEVENT;
 682alias OVERLAPPED WSAOVERLAPPED;
 683alias OVERLAPPED*    LPWSAOVERLAPPED;
 684
 685const auto WSA_IO_PENDING           = (ERROR_IO_PENDING);
 686const auto WSA_IO_INCOMPLETE        = (ERROR_IO_INCOMPLETE);
 687const auto WSA_INVALID_HANDLE       = (ERROR_INVALID_HANDLE);
 688const auto WSA_INVALID_PARAMETER    = (ERROR_INVALID_PARAMETER);
 689const auto WSA_NOT_ENOUGH_MEMORY    = (ERROR_NOT_ENOUGH_MEMORY);
 690const auto WSA_OPERATION_ABORTED    = (ERROR_OPERATION_ABORTED);
 691
 692const auto WSA_INVALID_EVENT        = (cast(WSAEVENT)null);
 693const auto WSA_MAXIMUM_WAIT_EVENTS  = (MAXIMUM_WAIT_OBJECTS);
 694const auto WSA_WAIT_FAILED          = (WAIT_FAILED);
 695const auto WSA_WAIT_EVENT_0         = (WAIT_OBJECT_0);
 696const auto WSA_WAIT_IO_COMPLETION   = (WAIT_IO_COMPLETION);
 697const auto WSA_WAIT_TIMEOUT         = (WAIT_TIMEOUT);
 698const auto WSA_INFINITE             = (INFINITE);
 699
 700/*
 701 * Include qos.h to pull in FLOWSPEC and related definitions
 702 */
 703
 704struct QOS {
 705    FLOWSPEC      SendingFlowspec;       /* the flow spec for data sending */
 706    FLOWSPEC      ReceivingFlowspec;     /* the flow spec for data receiving */
 707    WSABUF        ProviderSpecific;      /* additional provider specific stuff */
 708}
 709
 710alias QOS * LPQOS;
 711
 712/*
 713 * WinSock 2 extension -- manifest constants for return values of the condition function
 714 */
 715const auto CF_ACCEPT        = 0x0000;
 716const auto CF_REJECT        = 0x0001;
 717const auto CF_DEFER         = 0x0002;
 718
 719/*
 720 * WinSock 2 extension -- manifest constants for shutdown()
 721 */
 722const auto SD_RECEIVE       = 0x00;
 723const auto SD_SEND          = 0x01;
 724const auto SD_BOTH          = 0x02;
 725
 726/*
 727 * WinSock 2 extension -- data type and manifest constants for socket groups
 728 */
 729alias uint             GROUP;
 730
 731const auto SG_UNCONSTRAINED_GROUP    = 0x01;
 732const auto SG_CONSTRAINED_GROUP      = 0x02;
 733
 734/*
 735 * WinSock 2 extension -- data type for WSAEnumNetworkEvents()
 736 */
 737struct WSANETWORKEVENTS {
 738       long lNetworkEvents;
 739       int[FD_MAX_EVENTS] iErrorCode;
 740}
 741
 742alias WSANETWORKEVENTS * LPWSANETWORKEVENTS;
 743
 744/*
 745 * WinSock 2 extension -- WSAPROTOCOL_INFO structure and associated
 746 * manifest constants
 747 */
 748
 749const auto MAX_PROTOCOL_CHAIN  = 7;
 750
 751const auto BASE_PROTOCOL       = 1;
 752const auto LAYERED_PROTOCOL    = 0;
 753
 754struct WSAPROTOCOLCHAIN {
 755    int ChainLen;                                 /* the length of the chain,     */
 756                                                  /* length = 0 means layered protocol, */
 757                                                  /* length = 1 means base protocol, */
 758                                                  /* length > 1 means protocol chain */
 759    DWORD[MAX_PROTOCOL_CHAIN] ChainEntries;       /* a list of dwCatalogEntryIds */
 760}
 761
 762alias WSAPROTOCOLCHAIN * LPWSAPROTOCOLCHAIN;
 763
 764const auto WSAPROTOCOL_LEN   = 255;
 765
 766struct WSAPROTOCOL_INFOA {
 767    DWORD dwServiceFlags1;
 768    DWORD dwServiceFlags2;
 769    DWORD dwServiceFlags3;
 770    DWORD dwServiceFlags4;
 771    DWORD dwProviderFlags;
 772    GUID ProviderId;
 773    DWORD dwCatalogEntryId;
 774    WSAPROTOCOLCHAIN ProtocolChain;
 775    int iVersion;
 776    int iAddressFamily;
 777    int iMaxSockAddr;
 778    int iMinSockAddr;
 779    int iSocketType;
 780    int iProtocol;
 781    int iProtocolMaxOffset;
 782    int iNetworkByteOrder;
 783    int iSecurityScheme;
 784    DWORD dwMessageSize;
 785    DWORD dwProviderReserved;
 786    CHAR[WSAPROTOCOL_LEN+1]   szProtocol;
 787}
 788
 789alias WSAPROTOCOL_INFOA * LPWSAPROTOCOL_INFOA;
 790struct WSAPROTOCOL_INFOW {
 791    DWORD dwServiceFlags1;
 792    DWORD dwServiceFlags2;
 793    DWORD dwServiceFlags3;
 794    DWORD dwServiceFlags4;
 795    DWORD dwProviderFlags;
 796    GUID ProviderId;
 797    DWORD dwCatalogEntryId;
 798    WSAPROTOCOLCHAIN ProtocolChain;
 799    int iVersion;
 800    int iAddressFamily;
 801    int iMaxSockAddr;
 802    int iMinSockAddr;
 803    int iSocketType;
 804    int iProtocol;
 805    int iProtocolMaxOffset;
 806    int iNetworkByteOrder;
 807    int iSecurityScheme;
 808    DWORD dwMessageSize;
 809    DWORD dwProviderReserved;
 810    WCHAR[WSAPROTOCOL_LEN+1]  szProtocol;
 811}
 812
 813alias WSAPROTOCOL_INFOW * LPWSAPROTOCOL_INFOW;
 814
 815version(UNICODE) {
 816	alias WSAPROTOCOL_INFOW WSAPROTOCOL_INFO;
 817	alias LPWSAPROTOCOL_INFOW LPWSAPROTOCOL_INFO;
 818}
 819else {
 820	alias WSAPROTOCOL_INFOA WSAPROTOCOL_INFO;
 821	alias LPWSAPROTOCOL_INFOA LPWSAPROTOCOL_INFO;
 822}
 823
 824/* Flag bit definitions for dwProviderFlags */
 825const auto PFL_MULTIPLE_PROTO_ENTRIES           = 0x00000001;
 826const auto PFL_RECOMMENDED_PROTO_ENTRY          = 0x00000002;
 827const auto PFL_HIDDEN                           = 0x00000004;
 828const auto PFL_MATCHES_PROTOCOL_ZERO            = 0x00000008;
 829
 830/* Flag bit definitions for dwServiceFlags1 */
 831const auto XP1_CONNECTIONLESS                   = 0x00000001;
 832const auto XP1_GUARANTEED_DELIVERY              = 0x00000002;
 833const auto XP1_GUARANTEED_ORDER                 = 0x00000004;
 834const auto XP1_MESSAGE_ORIENTED                 = 0x00000008;
 835const auto XP1_PSEUDO_STREAM                    = 0x00000010;
 836const auto XP1_GRACEFUL_CLOSE                   = 0x00000020;
 837const auto XP1_EXPEDITED_DATA                   = 0x00000040;
 838const auto XP1_CONNECT_DATA                     = 0x00000080;
 839const auto XP1_DISCONNECT_DATA                  = 0x00000100;
 840const auto XP1_SUPPORT_BROADCAST                = 0x00000200;
 841const auto XP1_SUPPORT_MULTIPOINT               = 0x00000400;
 842const auto XP1_MULTIPOINT_CONTROL_PLANE         = 0x00000800;
 843const auto XP1_MULTIPOINT_DATA_PLANE            = 0x00001000;
 844const auto XP1_QOS_SUPPORTED                    = 0x00002000;
 845const auto XP1_INTERRUPT                        = 0x00004000;
 846const auto XP1_UNI_SEND                         = 0x00008000;
 847const auto XP1_UNI_RECV                         = 0x00010000;
 848const auto XP1_IFS_HANDLES                      = 0x00020000;
 849const auto XP1_PARTIAL_MESSAGE                  = 0x00040000;
 850const auto XP1_SAN_SUPPORT_SDP                  = 0x00080000;
 851
 852const auto BIGENDIAN                            = 0x0000;
 853const auto LITTLEENDIAN                         = 0x0001;
 854
 855const auto SECURITY_PROTOCOL_NONE               = 0x0000;
 856
 857/*
 858 * WinSock 2 extension -- manifest constants for WSAJoinLeaf()
 859 */
 860const auto JL_SENDER_ONLY     = 0x01;
 861const auto JL_RECEIVER_ONLY   = 0x02;
 862const auto JL_BOTH            = 0x04;
 863
 864/*
 865 * WinSock 2 extension -- manifest constants for WSASocket()
 866 */
 867const auto WSA_FLAG_OVERLAPPED            = 0x01;
 868const auto WSA_FLAG_MULTIPOINT_C_ROOT     = 0x02;
 869const auto WSA_FLAG_MULTIPOINT_C_LEAF     = 0x04;
 870const auto WSA_FLAG_MULTIPOINT_D_ROOT     = 0x08;
 871const auto WSA_FLAG_MULTIPOINT_D_LEAF     = 0x10;
 872const auto WSA_FLAG_ACCESS_SYSTEM_SECURITY  = 0x40;
 873
 874/*
 875 * WinSock 2 extensions -- data types for the condition function in
 876 * WSAAccept() and overlapped I/O completion routine.
 877 */
 878
 879alias int function (
 880    LPWSABUF lpCallerId,
 881    LPWSABUF lpCallerData,
 882    LPQOS lpSQOS,
 883    LPQOS lpGQOS,
 884    LPWSABUF lpCalleeId,
 885    LPWSABUF lpCalleeData,
 886    GROUP * g,
 887    DWORD_PTR dwCallbackData
 888    ) LPCONDITIONPROC;
 889
 890alias void function (
 891    DWORD dwError,
 892    DWORD cbTransferred,
 893    LPWSAOVERLAPPED lpOverlapped,
 894    DWORD dwFlags
 895    ) LPWSAOVERLAPPED_COMPLETION_ROUTINE;
 896
 897/*
 898 * WinSock 2 extension -- manifest constants and associated structures
 899 * for WSANSPIoctl()
 900 */
 901const auto SIO_NSP_NOTIFY_CHANGE          = _WSAIOW!(IOC_WS2,25);
 902
 903enum WSACOMPLETIONTYPE {
 904    NSP_NOTIFY_IMMEDIATELY = 0,
 905    NSP_NOTIFY_HWND,
 906    NSP_NOTIFY_EVENT,
 907    NSP_NOTIFY_PORT,
 908    NSP_NOTIFY_APC,
 909}
 910
 911alias WSACOMPLETIONTYPE* PWSACOMPLETIONTYPE;
 912alias WSACOMPLETIONTYPE * LPWSACOMPLETIONTYPE;
 913
 914struct WSACOMPLETION {
 915    WSACOMPLETIONTYPE Type;
 916    union _inner_union {
 917        struct _inner_struct {
 918            HWND hWnd;
 919            UINT uMsg;
 920            WPARAM context;
 921        }
 922		_inner_struct WindowMessage;
 923        struct _inner_struct2 {
 924            LPWSAOVERLAPPED lpOverlapped;
 925        }
 926		_inner_struct2 Event;
 927        struct _inner_struct3 {
 928            LPWSAOVERLAPPED lpOverlapped;
 929            LPWSAOVERLAPPED_COMPLETION_ROUTINE lpfnCompletionProc;
 930        }
 931		_inner_struct3 Apc;
 932        struct _inner_struct4 {
 933            LPWSAOVERLAPPED lpOverlapped;
 934            HANDLE hPort;
 935            ULONG_PTR Key;
 936        }
 937		_inner_struct4 Port;
 938    }
 939	_inner_union Parameters;
 940}
 941
 942alias WSACOMPLETION* PWSACOMPLETION;
 943alias WSACOMPLETION *LPWSACOMPLETION;
 944
 945/*
 946 * WinSock 2 extension -- manifest constants for SIO_TRANSLATE_HANDLE ioctl
 947 */
 948const auto TH_NETDEV         = 0x00000001;
 949const auto TH_TAPI           = 0x00000002;
 950
 951/*
 952 * Manifest constants and type definitions related to name resolution and
 953 * registration (RNR) API
 954 */
 955
 956struct BLOB {
 957    ULONG cbSize ;
 958    BYTE *pBlobData ;
 959}
 960
 961alias BLOB* LPBLOB ;
 962
 963/*
 964 * Service Install Flags
 965 */
 966
 967const auto SERVICE_MULTIPLE        = (0x00000001);
 968
 969/*
 970 *& Name Spaces
 971 */
 972
 973const auto NS_ALL                       = (0);
 974
 975const auto NS_SAP                       = (1);
 976const auto NS_NDS                       = (2);
 977const auto NS_PEER_BROWSE               = (3);
 978const auto NS_SLP                       = (5);
 979const auto NS_DHCP                      = (6);
 980
 981const auto NS_TCPIP_LOCAL               = (10);
 982const auto NS_TCPIP_HOSTS               = (11);
 983const auto NS_DNS                       = (12);
 984const auto NS_NETBT                     = (13);
 985const auto NS_WINS                      = (14);
 986
 987const auto NS_NLA                       = (15)    ; /* Network Location Awareness */
 988
 989const auto NS_BTH                       = (16)    ; /* Bluetooth SDP Namespace */
 990
 991const auto NS_NBP                       = (20);
 992
 993const auto NS_MS                        = (30);
 994const auto NS_STDA                      = (31);
 995const auto NS_NTDS                      = (32);
 996
 997const auto NS_EMAIL                     = (37);
 998const auto NS_PNRPNAME                  = (38);
 999const auto NS_PNRPCLOUD                 = (39);
1000
1001const auto NS_X500                      = (40);
1002const auto NS_NIS                       = (41);
1003const auto NS_NISPLUS                   = (42);
1004
1005const auto NS_WRQ                       = (50);
1006
1007const auto NS_NETDES                    = (60)    ; /* Network Designers Limited */
1008
1009/*
1010 * Resolution flags for WSAGetAddressByName().
1011 * Note these are also used by the 1.1 API GetAddressByName, so
1012 * leave them around.
1013 */
1014const auto RES_UNUSED_1                 = (0x00000001);
1015const auto RES_FLUSH_CACHE              = (0x00000002);
1016const auto RES_SERVICE                  = (0x00000004);
1017
1018/*
1019 * Well known value names for Service Types
1020 */
1021
1022const auto SERVICE_TYPE_VALUE_IPXPORTA       = "IpxSocket\0"c;
1023const auto SERVICE_TYPE_VALUE_IPXPORTW      = "IpxSocket\0"w;
1024const auto SERVICE_TYPE_VALUE_SAPIDA         = "SapId\0"c;
1025const auto SERVICE_TYPE_VALUE_SAPIDW        = "SapId\0"w;
1026
1027const auto SERVICE_TYPE_VALUE_TCPPORTA       = "TcpPort\0"c;
1028const auto SERVICE_TYPE_VALUE_TCPPORTW      = "TcpPort\0"w;
1029
1030const auto SERVICE_TYPE_VALUE_UDPPORTA       = "UdpPort\0"c;
1031const auto SERVICE_TYPE_VALUE_UDPPORTW      = "UdpPort\0"w;
1032
1033const auto SERVICE_TYPE_VALUE_OBJECTIDA      = "ObjectId\0"c;
1034const auto SERVICE_TYPE_VALUE_OBJECTIDW     = "ObjectId\0"w;
1035
1036version(UNICODE) {
1037	alias SERVICE_TYPE_VALUE_SAPIDW SERVICE_TYPE_VALUE_SAPID;
1038	alias SERVICE_TYPE_VALUE_TCPPORTW SERVICE_TYPE_VALUE_TCPPORT;
1039	alias SERVICE_TYPE_VALUE_UDPPORTW SERVICE_TYPE_VALUE_UDPPORT;
1040	alias SERVICE_TYPE_VALUE_OBJECTIDW SERVICE_TYPE_VALUE_OBJECTID;
1041}
1042else {
1043	alias SERVICE_TYPE_VALUE_SAPIDA SERVICE_TYPE_VALUE_SAPID;
1044	alias SERVICE_TYPE_VALUE_TCPPORTA SERVICE_TYPE_VALUE_TCPPORT;
1045	alias SERVICE_TYPE_VALUE_UDPPORTA SERVICE_TYPE_VALUE_UDPPORT;
1046	alias SERVICE_TYPE_VALUE_OBJECTIDA SERVICE_TYPE_VALUE_OBJECTID;
1047}
1048
1049/*
1050 *  Address Family/Protocol Tuples
1051 */
1052struct AFPROTOCOLS {
1053    INT iAddressFamily;
1054    INT iProtocol;
1055}
1056
1057alias AFPROTOCOLS* PAFPROTOCOLS;
1058alias AFPROTOCOLS* LPAFPROTOCOLS;
1059
1060/*
1061 * Client Query API Typedefs
1062 */
1063
1064/*
1065 * The comparators
1066 */
1067enum WSAECOMPARATOR {
1068    COMP_EQUAL = 0,
1069    COMP_NOTLESS
1070}
1071
1072alias WSAECOMPARATOR* PWSAECOMPARATOR;
1073alias WSAECOMPARATOR* LPWSAECOMPARATOR;
1074
1075struct WSAVERSION {
1076    DWORD           dwVersion;
1077    WSAECOMPARATOR  ecHow;
1078}
1079
1080alias WSAVERSION* PWSAVERSION;
1081alias WSAVERSION* LPWSAVERSION;
1082
1083struct WSAQUERYSETA {
1084    DWORD           dwSize;
1085    LPSTR           lpszServiceInstanceName;
1086    LPGUID          lpServiceClassId;
1087    LPWSAVERSION    lpVersion;
1088    LPSTR           lpszComment;
1089    DWORD           dwNameSpace;
1090    LPGUID          lpNSProviderId;
1091    LPSTR           lpszContext;
1092    DWORD           dwNumberOfProtocols;
1093    LPAFPROTOCOLS   lpafpProtocols;
1094    LPSTR           lpszQueryString;
1095    DWORD           dwNumberOfCsAddrs;
1096    LPCSADDR_INFO   lpcsaBuffer;
1097    DWORD           dwOutputFlags;
1098    LPBLOB          lpBlob;
1099}
1100
1101alias WSAQUERYSETA* PWSAQUERYSETA;
1102alias WSAQUERYSETA* LPWSAQUERYSETA;
1103struct WSAQUERYSETW {
1104    DWORD           dwSize;
1105    LPWSTR          lpszServiceInstanceName;
1106    LPGUID          lpServiceClassId;
1107    LPWSAVERSION    lpVersion;
1108    LPWSTR          lpszComment;
1109    DWORD           dwNameSpace;
1110    LPGUID          lpNSProviderId;
1111    LPWSTR          lpszContext;
1112    DWORD           dwNumberOfProtocols;
1113	LPAFPROTOCOLS   lpafpProtocols;
1114    LPWSTR          lpszQueryString;
1115    DWORD           dwNumberOfCsAddrs;
1116	LPCSADDR_INFO   lpcsaBuffer;
1117    DWORD           dwOutputFlags;
1118    LPBLOB          lpBlob;
1119}
1120
1121alias WSAQUERYSETW* PWSAQUERYSETW;
1122alias WSAQUERYSETW* LPWSAQUERYSETW;
1123
1124struct WSAQUERYSET2A {
1125    DWORD           dwSize;
1126    LPSTR           lpszServiceInstanceName;
1127    LPWSAVERSION    lpVersion;
1128    LPSTR           lpszComment;
1129    DWORD           dwNameSpace;
1130    LPGUID          lpNSProviderId;
1131    LPSTR           lpszContext;
1132    DWORD           dwNumberOfProtocols;
1133    LPAFPROTOCOLS   lpafpProtocols;
1134    LPSTR           lpszQueryString;
1135    DWORD           dwNumberOfCsAddrs;
1136    LPCSADDR_INFO   lpcsaBuffer;
1137    DWORD           dwOutputFlags;
1138    LPBLOB          lpBlob;
1139}
1140
1141alias WSAQUERYSET2A* PWSAQUERYSET2A;
1142alias WSAQUERYSET2A* LPWSAQUERYSET2A;
1143struct WSAQUERYSET2W {
1144    DWORD           dwSize;
1145    LPWSTR          lpszServiceInstanceName;
1146    LPWSAVERSION    lpVersion;
1147    LPWSTR          lpszComment;
1148    DWORD           dwNameSpace;
1149    LPGUID          lpNSProviderId;
1150    LPWSTR          lpszContext;
1151    DWORD           dwNumberOfProtocols;
1152	LPAFPROTOCOLS   lpafpProtocols;
1153    LPWSTR          lpszQueryString;
1154    DWORD           dwNumberOfCsAddrs;
1155	LPCSADDR_INFO   lpcsaBuffer;
1156    DWORD           dwOutputFlags;
1157    LPBLOB          lpBlob;
1158}
1159
1160alias WSAQUERYSET2W* PWSAQUERYSET2W;
1161alias WSAQUERYSET2W* LPWSAQUERYSET2W;
1162
1163version(UNICODE) {
1164	alias WSAQUERYSETW WSAQUERYSET;
1165	alias PWSAQUERYSETW PWSAQUERYSET;
1166	alias LPWSAQUERYSETW LPWSAQUERYSET;
1167	alias WSAQUERYSET2W WSAQUERYSET2;
1168	alias PWSAQUERYSET2W PWSAQUERYSET2;
1169	alias LPWSAQUERYSET2W LPWSAQUERYSET2;
1170}
1171else {
1172	alias WSAQUERYSETA WSAQUERYSET;
1173	alias PWSAQUERYSETA PWSAQUERYSET;
1174	alias LPWSAQUERYSETA LPWSAQUERYSET;
1175	alias WSAQUERYSET2A WSAQUERYSET2;
1176	alias PWSAQUERYSET2A PWSAQUERYSET2;
1177	alias LPWSAQUERYSET2A LPWSAQUERYSET2;
1178}
1179
1180const auto LUP_DEEP                 = 0x0001;
1181const auto LUP_CONTAINERS           = 0x0002;
1182const auto LUP_NOCONTAINERS         = 0x0004;
1183const auto LUP_NEAREST              = 0x0008;
1184const auto LUP_RETURN_NAME          = 0x0010;
1185const auto LUP_RETURN_TYPE          = 0x0020;
1186const auto LUP_RETURN_VERSION       = 0x0040;
1187const auto LUP_RETURN_COMMENT       = 0x0080;
1188const auto LUP_RETURN_ADDR          = 0x0100;
1189const auto LUP_RETURN_BLOB          = 0x0200;
1190const auto LUP_RETURN_ALIASES       = 0x0400;
1191const auto LUP_RETURN_QUERY_STRING  = 0x0800;
1192const auto LUP_RETURN_ALL           = 0x0FF0;
1193const auto LUP_RES_SERVICE          = 0x8000;
1194
1195const auto LUP_FLUSHCACHE           = 0x1000;
1196const auto LUP_FLUSHPREVIOUS        = 0x2000;
1197
1198const auto LUP_NON_AUTHORITATIVE    = 0x4000;
1199const auto LUP_SECURE               = 0x8000;
1200const auto LUP_RETURN_PREFERRED_NAMES   = 0x10000;
1201
1202const auto LUP_ADDRCONFIG           = 0x00100000;
1203const auto LUP_DUAL_ADDR            = 0x00200000;
1204
1205
1206/*
1207 * Return flags
1208 */
1209
1210const auto   RESULT_IS_ALIAS      = 0x0001;
1211
1212const auto   RESULT_IS_ADDED      = 0x0010;
1213const auto   RESULT_IS_CHANGED    = 0x0020;
1214const auto   RESULT_IS_DELETED    = 0x0040;
1215
1216/*
1217 * Service Address Registration and Deregistration Data Types.
1218 */
1219
1220enum WSAESETSERVICEOP {
1221    RNRSERVICE_REGISTER=0,
1222    RNRSERVICE_DEREGISTER,
1223    RNRSERVICE_DELETE
1224}
1225
1226alias WSAESETSERVICEOP* PWSAESETSERVICEOP;
1227alias WSAESETSERVICEOP* LPWSAESETSERVICEOP;
1228
1229/*
1230 * Service Installation/Removal Data Types.
1231 */
1232
1233struct WSANSCLASSINFOA {
1234    LPSTR   lpszName;
1235    DWORD   dwNameSpace;
1236    DWORD   dwValueType;
1237    DWORD   dwValueSize;
1238    LPVOID  lpValue;
1239}
1240
1241alias WSANSCLASSINFOA* PWSANSCLASSINFOA;
1242alias WSANSCLASSINFOA* LPWSANSCLASSINFOA;
1243struct WSANSCLASSINFOW {
1244    LPWSTR  lpszName;
1245    DWORD   dwNameSpace;
1246    DWORD   dwValueType;
1247    DWORD   dwValueSize;
1248    LPVOID  lpValue;
1249}
1250
1251alias WSANSCLASSINFOW* PWSANSCLASSINFOW;
1252alias WSANSCLASSINFOW* LPWSANSCLASSINFOW;
1253
1254version(UNICODE) {
1255	alias WSANSCLASSINFOW WSANSCLASSINFO;
1256	alias PWSANSCLASSINFOW PWSANSCLASSINFO;
1257	alias LPWSANSCLASSINFOW LPWSANSCLASSINFO;
1258}
1259else {
1260	alias WSANSCLASSINFOA WSANSCLASSINFO;
1261	alias PWSANSCLASSINFOA PWSANSCLASSINFO;
1262	alias LPWSANSCLASSINFOA LPWSANSCLASSINFO;
1263}
1264
1265struct WSASERVICECLASSINFOA {
1266    LPGUID              lpServiceClassId;
1267    LPSTR               lpszServiceClassName;
1268    DWORD               dwCount;
1269    LPWSANSCLASSINFOA   lpClassInfos;
1270}
1271
1272alias WSASERVICECLASSINFOA* PWSASERVICECLASSINFOA;
1273alias WSASERVICECLASSINFOA* LPWSASERVICECLASSINFOA;
1274struct WSASERVICECLASSINFOW {
1275    LPGUID              lpServiceClassId;
1276    LPWSTR              lpszServiceClassName;
1277    DWORD               dwCount;
1278    LPWSANSCLASSINFOW   lpClassInfos;
1279}
1280
1281alias WSASERVICECLASSINFOW* PWSASERVICECLASSINFOW;
1282alias WSASERVICECLASSINFOW* LPWSASERVICECLASSINFOW;
1283
1284version(UNICODE) {
1285	alias WSASERVICECLASSINFOW WSASERVICECLASSINFO;
1286	alias PWSASERVICECLASSINFOW PWSASERVICECLASSINFO;
1287	alias LPWSASERVICECLASSINFOW LPWSASERVICECLASSINFO;
1288}
1289else {
1290	alias WSASERVICECLASSINFOA WSASERVICECLASSINFO;
1291	alias PWSASERVICECLASSINFOA PWSASERVICECLASSINFO;
1292	alias LPWSASERVICECLASSINFOA LPWSASERVICECLASSINFO;
1293}
1294
1295struct WSANAMESPACE_INFOA {
1296    GUID                NSProviderId;
1297    DWORD               dwNameSpace;
1298    BOOL                fActive;
1299    DWORD               dwVersion;
1300    LPSTR               lpszIdentifier;
1301}
1302
1303alias WSANAMESPACE_INFOA* PWSANAMESPACE_INFOA;
1304alias WSANAMESPACE_INFOA* LPWSANAMESPACE_INFOA;
1305
1306struct WSANAMESPACE_INFOW {
1307    GUID                NSProviderId;
1308    DWORD               dwNameSpace;
1309    BOOL                fActive;
1310    DWORD               dwVersion;
1311    LPWSTR              lpszIdentifier;
1312}
1313
1314alias WSANAMESPACE_INFOW* PWSANAMESPACE_INFOW;
1315alias WSANAMESPACE_INFOW* LPWSANAMESPACE_INFOW;
1316
1317struct WSANAMESPACE_INFOEXA {
1318    GUID                NSProviderId;
1319    DWORD               dwNameSpace;
1320    BOOL                fActive;
1321    DWORD               dwVersion;
1322    LPSTR               lpszIdentifier;
1323    BLOB                ProviderSpecific;
1324}
1325
1326alias WSANAMESPACE_INFOEXA* PWSANAMESPACE_INFOEXA;
1327alias WSANAMESPACE_INFOEXA* LPWSANAMESPACE_INFOEXA;
1328
1329struct WSANAMESPACE_INFOEXW {
1330    GUID                NSProviderId;
1331    DWORD               dwNameSpace;
1332    BOOL                fActive;
1333    DWORD               dwVersion;
1334    LPWSTR              lpszIdentifier;
1335    BLOB                ProviderSpecific;
1336}
1337
1338alias WSANAMESPACE_INFOEXW* PWSANAMESPACE_INFOEXW;
1339alias WSANAMESPACE_INFOEXW* LPWSANAMESPACE_INFOEXW;
1340
1341
1342version(UNICODE) {
1343	alias WSANAMESPACE_INFOW WSANAMESPACE_INFO;
1344	alias PWSANAMESPACE_INFOW PWSANAMESPACE_INFO;
1345	alias LPWSANAMESPACE_INFOW LPWSANAMESPACE_INFO;
1346	alias WSANAMESPACE_INFOEXW WSANAMESPACE_INFOEX;
1347	alias PWSANAMESPACE_INFOEXW PWSANAMESPACE_INFOEX;
1348	alias LPWSANAMESPACE_INFOEXW LPWSANAMESPACE_INFOEX;
1349}
1350else {
1351	alias WSANAMESPACE_INFOA WSANAMESPACE_INFO;
1352	alias PWSANAMESPACE_INFOA PWSANAMESPACE_INFO;
1353	alias LPWSANAMESPACE_INFOA LPWSANAMESPACE_INFO;
1354	alias WSANAMESPACE_INFOEXA WSANAMESPACE_INFOEX;
1355	alias PWSANAMESPACE_INFOEXA PWSANAMESPACE_INFOEX;
1356	alias LPWSANAMESPACE_INFOEXA LPWSANAMESPACE_INFOEX;
1357}
1358
1359/* Event flag definitions for WSAPoll(). */
1360
1361const auto POLLRDNORM   = 0x0100;
1362const auto POLLRDBAND   = 0x0200;
1363const auto POLLIN       = (POLLRDNORM | POLLRDBAND);
1364const auto POLLPRI      = 0x0400;
1365
1366const auto POLLWRNORM   = 0x0010;
1367const auto POLLOUT      = (POLLWRNORM);
1368const auto POLLWRBAND   = 0x0020;
1369
1370const auto POLLERR      = 0x0001;
1371const auto POLLHUP      = 0x0002;
1372const auto POLLNVAL     = 0x0004;
1373
1374struct WSAPOLLFD {
1375    SOCKET  fd;
1376    SHORT   events;
1377    SHORT   revents;
1378}
1379
1380alias WSAPOLLFD* PWSAPOLLFD;
1381alias WSAPOLLFD *LPWSAPOLLFD;
1382
1383/* Socket function prototypes */
1384
1385SOCKET accept(
1386    SOCKET s,
1387	sockaddr * addr,
1388    int * addrlen
1389    );
1390
1391alias SOCKET function(
1392    SOCKET s,
1393    sockaddr * addr,
1394    int * addrlen
1395    ) LPFN_ACCEPT;
1396
1397int bind(
1398    SOCKET s,
1399    sockaddr * name,
1400    int namelen
1401    );
1402
1403alias int function(
1404    SOCKET s,
1405    sockaddr * name,
1406    int namelen
1407    ) LPFN_BIND;
1408
1409int closesocket(
1410    SOCKET s
1411    );
1412
1413alias int function (
1414    SOCKET s
1415    ) LPFN_CLOSESOCKET;
1416
1417int connect(
1418    SOCKET s,
1419    sockaddr * name,
1420    int namelen
1421    );
1422
1423alias int function (
1424    SOCKET s,
1425    sockaddr * name,
1426    int namelen
1427    ) LPFN_CONNECT;
1428
1429int ioctlsocket(
1430    SOCKET s,
1431    Clong_t cmd,
1432    u_long * argp
1433    );
1434
1435alias int function (
1436    SOCKET s,
1437    Clong_t cmd,
1438    u_long * argp
1439    ) LPFN_IOCTLSOCKET;
1440
1441int getpeername(
1442    SOCKET s,
1443	sockaddr * name,
1444    int * namelen
1445    );
1446
1447alias int function (
1448    SOCKET s,
1449    sockaddr * name,
1450    int * namelen
1451    ) LPFN_GETPEERNAME;
1452
1453int getsockname(
1454    SOCKET s,
1455    sockaddr * name,
1456    int * namelen
1457    );
1458
1459alias int function (
1460    SOCKET s,
1461    sockaddr * name,
1462    int * namelen
1463    ) LPFN_GETSOCKNAME;
1464
1465int getsockopt(
1466    SOCKET s,
1467    int level,
1468    int optname,
1469    char * optval,
1470    int * optlen
1471    );
1472
1473alias int function (
1474    SOCKET s,
1475    int level,
1476    int optname,
1477    char * optval,
1478    int * optlen
1479    ) LPFN_GETSOCKOPT;
1480
1481u_long htonl(
1482    u_long hostlong
1483    );
1484
1485alias u_long function (
1486    u_long hostlong
1487    ) LPFN_HTONL;
1488
1489u_short htons(
1490    u_short hostshort
1491    );
1492
1493alias u_short function (
1494    u_short hostshort
1495    ) LPFN_HTONS;
1496
1497Culong_t inet_addr(
1498    char * cp
1499    );
1500
1501alias Culong_t function (
1502    char * cp
1503    ) LPFN_INET_ADDR;
1504
1505char * inet_ntoa(
1506    in_addr _in
1507    );
1508
1509alias char * function (
1510    in_addr _in
1511    ) LPFN_INET_NTOA;
1512
1513int listen(
1514    SOCKET s,
1515    int backlog
1516    );
1517
1518alias int function (
1519    SOCKET s,
1520    int backlog
1521    ) LPFN_LISTEN;
1522
1523u_long ntohl(
1524    u_long netlong
1525    );
1526
1527alias u_long function (
1528    u_long netlong
1529    ) LPFN_NTOHL;
1530
1531u_short ntohs(
1532    u_short netshort
1533    );
1534
1535alias u_short function (
1536    u_short netshort
1537    ) LPFN_NTOHS;
1538
1539int recv(
1540    SOCKET s,
1541	ubyte * buf,
1542    int len,
1543    int flags
1544    );
1545
1546alias int function (
1547    SOCKET s,
1548	ubyte * buf,
1549    int len,
1550    int flags
1551    ) LPFN_RECV;
1552
1553int recvfrom(
1554    SOCKET s,
1555	ubyte * buf,
1556    int len,
1557    int flags,
1558	sockaddr * from,
1559    int * fromlen
1560    );
1561
1562alias int function (
1563    SOCKET s,
1564	ubyte * buf,
1565    int len,
1566    int flags,
1567	sockaddr * from,
1568    int * fromlen
1569    ) LPFN_RECVFROM;
1570
1571int select(
1572    int nfds,
1573    fd_set * readfds,
1574    fd_set * writefds,
1575    fd_set * exceptfds,
1576    timeval * timeout
1577    );
1578
1579alias int function (
1580    int nfds,
1581    fd_set * readfds,
1582    fd_set * writefds,
1583    fd_set *exceptfds,
1584    	timeval * timeout
1585    ) LPFN_SELECT;
1586
1587int send(
1588    SOCKET s,
1589    ubyte * buf,
1590    int len,
1591    int flags
1592    );
1593
1594alias int function (
1595    SOCKET s,
1596    ubyte * buf,
1597    int len,
1598    int flags
1599    ) LPFN_SEND;
1600
1601int sendto(
1602    SOCKET s,
1603	ubyte * buf,
1604    int len,
1605    int flags,
1606    sockaddr * to,
1607    int tolen
1608    );
1609
1610alias int function (
1611    SOCKET s,
1612    ubyte * buf,
1613    int len,
1614    int flags,
1615    sockaddr * to,
1616    int tolen
1617    ) LPFN_SENDTO;
1618
1619int setsockopt(
1620    SOCKET s,
1621    int level,
1622    int optname,
1623	char * optval,
1624    int optlen
1625    );
1626
1627alias int function (
1628    SOCKET s,
1629    int level,
1630    int optname,
1631    char * optval,
1632    int optlen
1633    ) LPFN_SETSOCKOPT;
1634
1635int shutdown(
1636    SOCKET s,
1637    int how
1638    );
1639
1640alias int function (
1641    SOCKET s,
1642    int how
1643    ) LPFN_SHUTDOWN;
1644
1645SOCKET socket(
1646    int af,
1647    int type,
1648    int protocol
1649    );
1650
1651alias SOCKET function (
1652    int af,
1653    int type,
1654    int protocol
1655    ) LPFN_SOCKET;
1656
1657/* Database function prototypes */
1658
1659hostent * gethostbyaddr(
1660    char * addr,
1661    int len,
1662    int type
1663    );
1664
1665alias hostent* function (
1666    char * addr,
1667    int len,
1668    int type
1669    ) LPFN_GETHOSTBYADDR;
1670
1671hostent * gethostbyname(
1672    char * name
1673    );
1674
1675alias hostent* function (
1676    char * name
1677    ) LPFN_GETHOSTBYNAME;
1678
1679int gethostname(
1680    char * name,
1681    int namelen
1682    );
1683
1684alias int function (
1685    char * name,
1686    int namelen
1687    ) LPFN_GETHOSTNAME;
1688
1689servent * getservbyport(
1690    int port,
1691    char * proto
1692    );
1693
1694alias servent* function (
1695    int port,
1696    char * proto
1697    ) LPFN_GETSERVBYPORT;
1698
1699servent * getservbyname(
1700    char * name,
1701    char * proto
1702    );
1703
1704alias servent* function (
1705    char * name,
1706    char * proto
1707    ) LPFN_GETSERVBYNAME;
1708
1709protoent * getprotobynumber(
1710    int number
1711    );
1712
1713alias protoent* function (
1714    int number
1715    ) LPFN_GETPROTOBYNUMBER;
1716
1717protoent * getprotobyname(
1718    char * name
1719    );
1720
1721alias protoent* function (
1722    char * name
1723    ) LPFN_GETPROTOBYNAME;
1724
1725/* Microsoft Windows Extension function prototypes */
1726
1727int WSAStartup(
1728    WORD wVersionRequested,
1729    LPWSADATA lpWSAData
1730    );
1731
1732alias int 

Large files files are truncated, but you can click here to view the full file