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