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