/usr/lib/gcc/x86_64-linux-gnu/5/include/d/core/sys/windows/winsock2.d is in libphobos-5-dev 5.5.0-12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | /*
Written by Christopher E. Miller
Placed into public domain.
*/
module core.sys.windows.winsock2;
version (Windows):
extern(Windows):
nothrow:
alias SOCKET = size_t;
alias socklen_t = int;
const SOCKET INVALID_SOCKET = cast(SOCKET)~0;
const int SOCKET_ERROR = -1;
enum WSADESCRIPTION_LEN = 256;
enum WSASYS_STATUS_LEN = 128;
struct WSADATA
{
ushort wVersion;
ushort wHighVersion;
char[WSADESCRIPTION_LEN + 1] szDescription;
char[WSASYS_STATUS_LEN + 1] szSystemStatus;
ushort iMaxSockets;
ushort iMaxUdpDg;
char* lpVendorInfo;
}
alias LPWSADATA = WSADATA*;
const int IOCPARM_MASK = 0x7F;
const int IOC_IN = cast(int)0x80000000;
const int FIONBIO = cast(int)(IOC_IN | ((uint.sizeof & IOCPARM_MASK) << 16) | (102 << 8) | 126);
enum NI_MAXHOST = 1025;
enum NI_MAXSERV = 32;
@nogc
{
int WSAStartup(ushort wVersionRequested, LPWSADATA lpWSAData);
int WSACleanup();
SOCKET socket(int af, int type, int protocol);
int ioctlsocket(SOCKET s, int cmd, uint* argp);
int bind(SOCKET s, const(sockaddr)* name, socklen_t namelen);
int connect(SOCKET s, const(sockaddr)* name, socklen_t namelen);
int listen(SOCKET s, int backlog);
SOCKET accept(SOCKET s, sockaddr* addr, socklen_t* addrlen);
int closesocket(SOCKET s);
int shutdown(SOCKET s, int how);
int getpeername(SOCKET s, sockaddr* name, socklen_t* namelen);
int getsockname(SOCKET s, sockaddr* name, socklen_t* namelen);
int send(SOCKET s, const(void)* buf, int len, int flags);
int sendto(SOCKET s, const(void)* buf, int len, int flags, const(sockaddr)* to, socklen_t tolen);
int recv(SOCKET s, void* buf, int len, int flags);
int recvfrom(SOCKET s, void* buf, int len, int flags, sockaddr* from, socklen_t* fromlen);
int getsockopt(SOCKET s, int level, int optname, void* optval, socklen_t* optlen);
int setsockopt(SOCKET s, int level, int optname, const(void)* optval, socklen_t optlen);
uint inet_addr(const char* cp);
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, const(timeval)* timeout);
char* inet_ntoa(in_addr ina);
hostent* gethostbyname(const char* name);
hostent* gethostbyaddr(const(void)* addr, int len, int type);
protoent* getprotobyname(const char* name);
protoent* getprotobynumber(int number);
servent* getservbyname(const char* name, const char* proto);
servent* getservbyport(int port, const char* proto);
}
enum: int
{
NI_NOFQDN = 0x01,
NI_NUMERICHOST = 0x02,
NI_NAMEREQD = 0x04,
NI_NUMERICSERV = 0x08,
NI_DGRAM = 0x10,
}
@nogc
{
int gethostname(const char* name, int namelen);
int getaddrinfo(const(char)* nodename, const(char)* servname, const(addrinfo)* hints, addrinfo** res);
void freeaddrinfo(addrinfo* ai);
int getnameinfo(const(sockaddr)* sa, socklen_t salen, char* host, uint hostlen, char* serv, uint servlen, int flags);
}
enum WSABASEERR = 10000;
enum: int
{
/*
* Windows Sockets definitions of regular Microsoft C error constants
*/
WSAEINTR = (WSABASEERR+4),
WSAEBADF = (WSABASEERR+9),
WSAEACCES = (WSABASEERR+13),
WSAEFAULT = (WSABASEERR+14),
WSAEINVAL = (WSABASEERR+22),
WSAEMFILE = (WSABASEERR+24),
/*
* Windows Sockets definitions of regular Berkeley error constants
*/
WSAEWOULDBLOCK = (WSABASEERR+35),
WSAEINPROGRESS = (WSABASEERR+36),
WSAEALREADY = (WSABASEERR+37),
WSAENOTSOCK = (WSABASEERR+38),
WSAEDESTADDRREQ = (WSABASEERR+39),
WSAEMSGSIZE = (WSABASEERR+40),
WSAEPROTOTYPE = (WSABASEERR+41),
WSAENOPROTOOPT = (WSABASEERR+42),
WSAEPROTONOSUPPORT = (WSABASEERR+43),
WSAESOCKTNOSUPPORT = (WSABASEERR+44),
WSAEOPNOTSUPP = (WSABASEERR+45),
WSAEPFNOSUPPORT = (WSABASEERR+46),
WSAEAFNOSUPPORT = (WSABASEERR+47),
WSAEADDRINUSE = (WSABASEERR+48),
WSAEADDRNOTAVAIL = (WSABASEERR+49),
WSAENETDOWN = (WSABASEERR+50),
WSAENETUNREACH = (WSABASEERR+51),
WSAENETRESET = (WSABASEERR+52),
WSAECONNABORTED = (WSABASEERR+53),
WSAECONNRESET = (WSABASEERR+54),
WSAENOBUFS = (WSABASEERR+55),
WSAEISCONN = (WSABASEERR+56),
WSAENOTCONN = (WSABASEERR+57),
WSAESHUTDOWN = (WSABASEERR+58),
WSAETOOMANYREFS = (WSABASEERR+59),
WSAETIMEDOUT = (WSABASEERR+60),
WSAECONNREFUSED = (WSABASEERR+61),
WSAELOOP = (WSABASEERR+62),
WSAENAMETOOLONG = (WSABASEERR+63),
WSAEHOSTDOWN = (WSABASEERR+64),
WSAEHOSTUNREACH = (WSABASEERR+65),
WSAENOTEMPTY = (WSABASEERR+66),
WSAEPROCLIM = (WSABASEERR+67),
WSAEUSERS = (WSABASEERR+68),
WSAEDQUOT = (WSABASEERR+69),
WSAESTALE = (WSABASEERR+70),
WSAEREMOTE = (WSABASEERR+71),
/*
* Extended Windows Sockets error constant definitions
*/
WSASYSNOTREADY = (WSABASEERR+91),
WSAVERNOTSUPPORTED = (WSABASEERR+92),
WSANOTINITIALISED = (WSABASEERR+93),
/* Authoritative Answer: Host not found */
WSAHOST_NOT_FOUND = (WSABASEERR+1001),
HOST_NOT_FOUND = WSAHOST_NOT_FOUND,
/* Non-Authoritative: Host not found, or SERVERFAIL */
WSATRY_AGAIN = (WSABASEERR+1002),
TRY_AGAIN = WSATRY_AGAIN,
/* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
WSANO_RECOVERY = (WSABASEERR+1003),
NO_RECOVERY = WSANO_RECOVERY,
/* Valid name, no data record of requested type */
WSANO_DATA = (WSABASEERR+1004),
NO_DATA = WSANO_DATA,
/* no address, look for MX record */
WSANO_ADDRESS = WSANO_DATA,
NO_ADDRESS = WSANO_ADDRESS
}
/*
* Windows Sockets errors redefined as regular Berkeley error constants
*/
enum: int
{
EWOULDBLOCK = WSAEWOULDBLOCK,
EINPROGRESS = WSAEINPROGRESS,
EALREADY = WSAEALREADY,
ENOTSOCK = WSAENOTSOCK,
EDESTADDRREQ = WSAEDESTADDRREQ,
EMSGSIZE = WSAEMSGSIZE,
EPROTOTYPE = WSAEPROTOTYPE,
ENOPROTOOPT = WSAENOPROTOOPT,
EPROTONOSUPPORT = WSAEPROTONOSUPPORT,
ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT,
EOPNOTSUPP = WSAEOPNOTSUPP,
EPFNOSUPPORT = WSAEPFNOSUPPORT,
EAFNOSUPPORT = WSAEAFNOSUPPORT,
EADDRINUSE = WSAEADDRINUSE,
EADDRNOTAVAIL = WSAEADDRNOTAVAIL,
ENETDOWN = WSAENETDOWN,
ENETUNREACH = WSAENETUNREACH,
ENETRESET = WSAENETRESET,
ECONNABORTED = WSAECONNABORTED,
ECONNRESET = WSAECONNRESET,
ENOBUFS = WSAENOBUFS,
EISCONN = WSAEISCONN,
ENOTCONN = WSAENOTCONN,
ESHUTDOWN = WSAESHUTDOWN,
ETOOMANYREFS = WSAETOOMANYREFS,
ETIMEDOUT = WSAETIMEDOUT,
ECONNREFUSED = WSAECONNREFUSED,
ELOOP = WSAELOOP,
ENAMETOOLONG = WSAENAMETOOLONG,
EHOSTDOWN = WSAEHOSTDOWN,
EHOSTUNREACH = WSAEHOSTUNREACH,
ENOTEMPTY = WSAENOTEMPTY,
EPROCLIM = WSAEPROCLIM,
EUSERS = WSAEUSERS,
EDQUOT = WSAEDQUOT,
ESTALE = WSAESTALE,
EREMOTE = WSAEREMOTE
}
enum: int
{
EAI_NONAME = WSAHOST_NOT_FOUND,
}
int WSAGetLastError() @trusted @nogc;
enum: int
{
AF_UNSPEC = 0,
AF_UNIX = 1,
AF_INET = 2,
AF_IMPLINK = 3,
AF_PUP = 4,
AF_CHAOS = 5,
AF_NS = 6,
AF_IPX = AF_NS,
AF_ISO = 7,
AF_OSI = AF_ISO,
AF_ECMA = 8,
AF_DATAKIT = 9,
AF_CCITT = 10,
AF_SNA = 11,
AF_DECnet = 12,
AF_DLI = 13,
AF_LAT = 14,
AF_HYLINK = 15,
AF_APPLETALK = 16,
AF_NETBIOS = 17,
AF_VOICEVIEW = 18,
AF_FIREFOX = 19,
AF_UNKNOWN1 = 20,
AF_BAN = 21,
AF_ATM = 22,
AF_INET6 = 23,
AF_CLUSTER = 24,
AF_12844 = 25,
AF_IRDA = 26,
AF_NETDES = 28,
AF_MAX = 29,
PF_UNSPEC = AF_UNSPEC,
PF_UNIX = AF_UNIX,
PF_INET = AF_INET,
PF_IMPLINK = AF_IMPLINK,
PF_PUP = AF_PUP,
PF_CHAOS = AF_CHAOS,
PF_NS = AF_NS,
PF_IPX = AF_IPX,
PF_ISO = AF_ISO,
PF_OSI = AF_OSI,
PF_ECMA = AF_ECMA,
PF_DATAKIT = AF_DATAKIT,
PF_CCITT = AF_CCITT,
PF_SNA = AF_SNA,
PF_DECnet = AF_DECnet,
PF_DLI = AF_DLI,
PF_LAT = AF_LAT,
PF_HYLINK = AF_HYLINK,
PF_APPLETALK = AF_APPLETALK,
PF_VOICEVIEW = AF_VOICEVIEW,
PF_FIREFOX = AF_FIREFOX,
PF_UNKNOWN1 = AF_UNKNOWN1,
PF_BAN = AF_BAN,
PF_INET6 = AF_INET6,
PF_MAX = AF_MAX,
}
enum: int
{
SOL_SOCKET = 0xFFFF,
}
enum: int
{
SO_DEBUG = 0x0001,
SO_ACCEPTCONN = 0x0002,
SO_REUSEADDR = 0x0004,
SO_KEEPALIVE = 0x0008,
SO_DONTROUTE = 0x0010,
SO_BROADCAST = 0x0020,
SO_USELOOPBACK = 0x0040,
SO_LINGER = 0x0080,
SO_DONTLINGER = ~SO_LINGER,
SO_OOBINLINE = 0x0100,
SO_SNDBUF = 0x1001,
SO_RCVBUF = 0x1002,
SO_SNDLOWAT = 0x1003,
SO_RCVLOWAT = 0x1004,
SO_SNDTIMEO = 0x1005,
SO_RCVTIMEO = 0x1006,
SO_ERROR = 0x1007,
SO_TYPE = 0x1008,
SO_EXCLUSIVEADDRUSE = ~SO_REUSEADDR,
TCP_NODELAY = 1,
IP_MULTICAST_LOOP = 0x4,
IP_ADD_MEMBERSHIP = 0x5,
IP_DROP_MEMBERSHIP = 0x6,
IPV6_UNICAST_HOPS = 4,
IPV6_MULTICAST_IF = 9,
IPV6_MULTICAST_HOPS = 10,
IPV6_MULTICAST_LOOP = 11,
IPV6_ADD_MEMBERSHIP = 12,
IPV6_DROP_MEMBERSHIP = 13,
IPV6_JOIN_GROUP = IPV6_ADD_MEMBERSHIP,
IPV6_LEAVE_GROUP = IPV6_DROP_MEMBERSHIP,
IPV6_V6ONLY = 27,
}
/// Default FD_SETSIZE value.
/// In C/C++, it is redefinable by #define-ing the macro before #include-ing
/// winsock.h. In D, use the $(D FD_CREATE) function to allocate a $(D fd_set)
/// of an arbitrary size.
enum int FD_SETSIZE = 64;
struct fd_set_custom(uint SETSIZE)
{
uint fd_count;
SOCKET[SETSIZE] fd_array;
}
alias fd_set = fd_set_custom!FD_SETSIZE;
// Removes.
void FD_CLR(SOCKET fd, fd_set* set) pure @nogc
{
uint c = set.fd_count;
SOCKET* start = set.fd_array.ptr;
SOCKET* stop = start + c;
for(; start != stop; start++)
{
if(*start == fd)
goto found;
}
return; //not found
found:
for(++start; start != stop; start++)
{
*(start - 1) = *start;
}
set.fd_count = c - 1;
}
// Tests.
int FD_ISSET(SOCKET fd, const(fd_set)* set) pure @nogc
{
const(SOCKET)* start = set.fd_array.ptr;
const(SOCKET)* stop = start + set.fd_count;
for(; start != stop; start++)
{
if(*start == fd)
return true;
}
return false;
}
// Adds.
void FD_SET(SOCKET fd, fd_set* set) pure @nogc
{
uint c = set.fd_count;
set.fd_array.ptr[c] = fd;
set.fd_count = c + 1;
}
// Resets to zero.
void FD_ZERO(fd_set* set) pure @nogc
{
set.fd_count = 0;
}
/// Creates a new $(D fd_set) with the specified capacity.
fd_set* FD_CREATE(uint capacity) pure
{
// Take into account alignment (SOCKET may be 64-bit and require 64-bit alignment on 64-bit systems)
size_t size = (fd_set_custom!1).sizeof - SOCKET.sizeof + (SOCKET.sizeof * capacity);
auto data = new ubyte[size];
auto set = cast(fd_set*)data.ptr;
FD_ZERO(set);
return set;
}
struct linger
{
ushort l_onoff;
ushort l_linger;
}
struct protoent
{
char* p_name;
char** p_aliases;
short p_proto;
}
struct servent
{
char* s_name;
char** s_aliases;
version (Win64)
{
char* s_proto;
short s_port;
}
else version (Win32)
{
short s_port;
char* s_proto;
}
}
/+
union in6_addr
{
private union _u_t
{
ubyte[16] Byte;
ushort[8] Word;
}
_u_t u;
}
struct in_addr6
{
ubyte[16] s6_addr;
}
+/
@safe pure @nogc
{
version(BigEndian)
{
ushort htons(ushort x)
{
return x;
}
uint htonl(uint x)
{
return x;
}
}
else version(LittleEndian)
{
private import core.bitop;
ushort htons(ushort x)
{
return cast(ushort)((x >> 8) | (x << 8));
}
uint htonl(uint x)
{
return bswap(x);
}
}
else
{
static assert(0);
}
ushort ntohs(ushort x)
{
return htons(x);
}
uint ntohl(uint x)
{
return htonl(x);
}
} // @safe pure @nogc
enum: int
{
SOCK_STREAM = 1,
SOCK_DGRAM = 2,
SOCK_RAW = 3,
SOCK_RDM = 4,
SOCK_SEQPACKET = 5,
}
enum: int
{
IPPROTO_IP = 0,
IPPROTO_ICMP = 1,
IPPROTO_IGMP = 2,
IPPROTO_GGP = 3,
IPPROTO_TCP = 6,
IPPROTO_PUP = 12,
IPPROTO_UDP = 17,
IPPROTO_IDP = 22,
IPPROTO_IPV6 = 41,
IPPROTO_ND = 77,
IPPROTO_RAW = 255,
IPPROTO_MAX = 256,
}
enum: int
{
MSG_OOB = 0x1,
MSG_PEEK = 0x2,
MSG_DONTROUTE = 0x4
}
enum: int
{
SD_RECEIVE = 0,
SD_SEND = 1,
SD_BOTH = 2,
}
enum: uint
{
INADDR_ANY = 0,
INADDR_LOOPBACK = 0x7F000001,
INADDR_BROADCAST = 0xFFFFFFFF,
INADDR_NONE = 0xFFFFFFFF,
ADDR_ANY = INADDR_ANY,
}
enum: int
{
AI_PASSIVE = 0x1,
AI_CANONNAME = 0x2,
AI_NUMERICHOST = 0x4,
AI_ADDRCONFIG = 0x0400,
AI_NON_AUTHORITATIVE = 0x04000,
AI_SECURE = 0x08000,
AI_RETURN_PREFERRED_NAMES = 0x010000,
}
struct timeval
{
int tv_sec;
int tv_usec;
}
union in_addr
{
private union _S_un_t
{
private struct _S_un_b_t
{
ubyte s_b1, s_b2, s_b3, s_b4;
}
_S_un_b_t S_un_b;
private struct _S_un_w_t
{
ushort s_w1, s_w2;
}
_S_un_w_t S_un_w;
uint S_addr;
}
_S_un_t S_un;
uint s_addr;
struct
{
ubyte s_net, s_host;
union
{
ushort s_imp;
struct
{
ubyte s_lh, s_impno;
}
}
}
}
union in6_addr
{
private union _in6_u_t
{
ubyte[16] u6_addr8;
ushort[8] u6_addr16;
uint[4] u6_addr32;
}
_in6_u_t in6_u;
ubyte[16] s6_addr8;
ushort[8] s6_addr16;
uint[4] s6_addr32;
alias s6_addr = s6_addr8;
}
const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
const in6_addr IN6ADDR_LOOPBACK = { s6_addr8: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] };
//alias IN6ADDR_ANY_INIT = IN6ADDR_ANY;
//alias IN6ADDR_LOOPBACK_INIT = IN6ADDR_LOOPBACK;
enum int INET_ADDRSTRLEN = 16;
enum int INET6_ADDRSTRLEN = 46;
struct sockaddr
{
short sa_family;
ubyte[14] sa_data;
}
struct sockaddr_in
{
short sin_family = AF_INET;
ushort sin_port;
in_addr sin_addr;
ubyte[8] sin_zero;
}
struct sockaddr_in6
{
short sin6_family = AF_INET6;
ushort sin6_port;
uint sin6_flowinfo;
in6_addr sin6_addr;
uint sin6_scope_id;
}
struct addrinfo
{
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char* ai_canonname;
sockaddr* ai_addr;
addrinfo* ai_next;
}
struct hostent
{
char* h_name;
char** h_aliases;
short h_addrtype;
short h_length;
char** h_addr_list;
char* h_addr() @safe pure nothrow @nogc
{
return h_addr_list[0];
}
}
// Note: These are Winsock2!!
struct WSAOVERLAPPED;
alias LPWSAOVERLAPPED = WSAOVERLAPPED*;
alias LPWSAOVERLAPPED_COMPLETION_ROUTINE = void function(uint, uint, LPWSAOVERLAPPED, uint);
int WSAIoctl(SOCKET s, uint dwIoControlCode,
void* lpvInBuffer, uint cbInBuffer,
void* lpvOutBuffer, uint cbOutBuffer,
uint* lpcbBytesReturned,
LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
enum IOC_VENDOR = 0x18000000;
enum SIO_KEEPALIVE_VALS = IOC_IN | IOC_VENDOR | 4;
/* Argument structure for SIO_KEEPALIVE_VALS */
struct tcp_keepalive
{
uint onoff;
uint keepalivetime;
uint keepaliveinterval;
}
|