PageRenderTime 116ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/dm-rc-server/trunk/DM_RC_Client (Miranda)/ICS/OverbyteIcsWinsock.pas

http://dm-rc-server.googlecode.com/
Pascal | 736 lines | 514 code | 31 blank | 191 comment | 0 complexity | 202ff47b82485d918ec781828eed95be MD5 | raw file
  1. {*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. Author: François PIETTE
  3. Description: WinSock API for Delphi 8 for the Microsoft .NET framework
  4. This is the subset needed for ICS components.
  5. Creation: December 2003
  6. Version: 1.00
  7. EMail: francois.piette@overbyte.be http://www.overbyte.be
  8. Support: Use the mailing list twsocket@elists.org
  9. Follow "support" link at http://www.overbyte.be for subscription.
  10. Legal issues: Copyright (C) 1996-2007 by François PIETTE
  11. Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
  12. <francois.piette@overbyte.be>
  13. This software is provided 'as-is', without any express or
  14. implied warranty. In no event will the author be held liable
  15. for any damages arising from the use of this software.
  16. Permission is granted to anyone to use this software for any
  17. purpose, including commercial applications, and to alter it
  18. and redistribute it freely, subject to the following
  19. restrictions:
  20. 1. The origin of this software must not be misrepresented,
  21. you must not claim that you wrote the original software.
  22. If you use this software in a product, an acknowledgment
  23. in the product documentation would be appreciated but is
  24. not required.
  25. 2. Altered source versions must be plainly marked as such, and
  26. must not be misrepresented as being the original software.
  27. 3. This notice may not be removed or altered from any source
  28. distribution.
  29. 4. You must register this software by sending a picture postcard
  30. to the author. Use a nice stamp and mention your name, street
  31. address, EMail address and any comment you like to say.
  32. History:
  33. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  34. unit OverbyteIcsWinSock;
  35. {$IFDEF WIN32}
  36. interface
  37. uses
  38. WinSock;
  39. type
  40. {$EXTERNALSYM in_addr}
  41. in_addr = Winsock.in_addr;
  42. {$EXTERNALSYM TInAddr}
  43. TInAddr = Winsock.TInAddr;
  44. {$EXTERNALSYM PInAddr}
  45. PInAddr = Winsock.PInAddr;
  46. {$EXTERNALSYM TSockAddr}
  47. TSockAddr = Winsock.TSockAddr;
  48. {$EXTERNALSYM PSockAddr}
  49. PSockAddr = Winsock.PSockAddr;
  50. {$EXTERNALSYM TSockAddrIn}
  51. TSockAddrIn = Winsock.TSockAddrIn;
  52. {$EXTERNALSYM TLinger}
  53. TLinger = Winsock.TLinger;
  54. {$EXTERNALSYM u_int}
  55. u_int = Winsock.u_int;
  56. {$EXTERNALSYM u_short}
  57. u_short = Winsock.u_short;
  58. {$EXTERNALSYM u_long}
  59. u_long = Winsock.u_long;
  60. {$EXTERNALSYM u_char}
  61. u_char = Winsock.u_char;
  62. {$EXTERNALSYM sockaddr_in}
  63. sockaddr_in = Winsock.sockaddr_in;
  64. {$EXTERNALSYM TTimeVal}
  65. TTimeVal = Winsock.TTimeVal;
  66. {$EXTERNALSYM TWSADATA}
  67. TWSADATA = Winsock.TWSADATA;
  68. {$EXTERNALSYM PHostEnt}
  69. PHostEnt = Winsock.PHostEnt;
  70. {$EXTERNALSYM PServEnt}
  71. PServEnt = Winsock.PServEnt;
  72. {$EXTERNALSYM PProtoEnt}
  73. PProtoEnt = Winsock.PProtoEnt;
  74. {$EXTERNALSYM TSocket}
  75. TSocket = Winsock.TSocket; { AG 06/30/07 }
  76. const
  77. {$EXTERNALSYM MAXGETHOSTSTRUCT}
  78. MAXGETHOSTSTRUCT = Winsock.MAXGETHOSTSTRUCT;
  79. {$EXTERNALSYM AF_INET}
  80. AF_INET = Winsock.AF_INET;
  81. {$EXTERNALSYM PF_INET}
  82. PF_INET = Winsock.PF_INET;
  83. {$EXTERNALSYM INADDR_NONE}
  84. INADDR_NONE = Winsock.INADDR_NONE;
  85. {$EXTERNALSYM INADDR_BROADCAST}
  86. INADDR_BROADCAST = Winsock.INADDR_BROADCAST;
  87. {$EXTERNALSYM IPPROTO_IP}
  88. IPPROTO_IP = Winsock.IPPROTO_IP;
  89. {$EXTERNALSYM IPPROTO_TCP}
  90. IPPROTO_TCP = Winsock.IPPROTO_TCP;
  91. {$EXTERNALSYM IPPROTO_UDP}
  92. IPPROTO_UDP = Winsock.IPPROTO_UDP;
  93. {$EXTERNALSYM IPPROTO_RAW}
  94. IPPROTO_RAW = Winsock.IPPROTO_RAW;
  95. {$EXTERNALSYM SOCK_STREAM}
  96. SOCK_STREAM = Winsock.SOCK_STREAM;
  97. {$EXTERNALSYM SOCK_DGRAM}
  98. SOCK_DGRAM = Winsock.SOCK_DGRAM;
  99. {$EXTERNALSYM SOCK_RAW}
  100. SOCK_RAW = Winsock.SOCK_RAW;
  101. {$EXTERNALSYM SOL_SOCKET}
  102. SOL_SOCKET = Winsock.SOL_SOCKET;
  103. {$EXTERNALSYM SO_LINGER}
  104. SO_LINGER = Winsock.SO_LINGER;
  105. {$EXTERNALSYM SO_BROADCAST}
  106. SO_BROADCAST = Winsock.SO_BROADCAST;
  107. {$EXTERNALSYM SO_REUSEADDR}
  108. SO_REUSEADDR = Winsock.SO_REUSEADDR;
  109. {$EXTERNALSYM SO_KEEPALIVE}
  110. SO_KEEPALIVE = Winsock.SO_KEEPALIVE;
  111. {$EXTERNALSYM SO_SNDBUF}
  112. SO_SNDBUF = Winsock.SO_SNDBUF;
  113. {$EXTERNALSYM SO_RCVBUF}
  114. SO_RCVBUF = Winsock.SO_RCVBUF;
  115. {$EXTERNALSYM TCP_NODELAY}
  116. TCP_NODELAY = Winsock.TCP_NODELAY;
  117. {$EXTERNALSYM INVALID_SOCKET}
  118. INVALID_SOCKET = Winsock.INVALID_SOCKET;
  119. {$EXTERNALSYM SOCKET_ERROR}
  120. SOCKET_ERROR = Winsock.SOCKET_ERROR;
  121. {$EXTERNALSYM IP_DEFAULT_MULTICAST_TTL}
  122. IP_DEFAULT_MULTICAST_TTL = Winsock.IP_DEFAULT_MULTICAST_TTL;
  123. {$EXTERNALSYM IP_MULTICAST_TTL}
  124. IP_MULTICAST_TTL = Winsock.IP_MULTICAST_TTL;
  125. {$EXTERNALSYM IP_MULTICAST_IF}
  126. IP_MULTICAST_IF = Winsock.IP_MULTICAST_IF;
  127. {$EXTERNALSYM IP_ADD_MEMBERSHIP}
  128. IP_ADD_MEMBERSHIP = Winsock.IP_ADD_MEMBERSHIP;
  129. {$EXTERNALSYM FD_READ}
  130. FD_READ = Winsock.FD_READ;
  131. {$EXTERNALSYM FD_WRITE}
  132. FD_WRITE = Winsock.FD_WRITE;
  133. {$EXTERNALSYM FD_CLOSE}
  134. FD_CLOSE = Winsock.FD_CLOSE;
  135. {$EXTERNALSYM FD_CONNECT}
  136. FD_CONNECT = Winsock.FD_CONNECT;
  137. {$EXTERNALSYM FD_ACCEPT}
  138. FD_ACCEPT = Winsock.FD_ACCEPT;
  139. {$EXTERNALSYM FIONREAD}
  140. FIONREAD = Winsock.FIONREAD;
  141. {$EXTERNALSYM MSG_PEEK}
  142. MSG_PEEK = Winsock.MSG_PEEK;
  143. {$EXTERNALSYM MSG_OOB}
  144. MSG_OOB = Winsock.MSG_OOB;
  145. {$EXTERNALSYM WSABASEERR}
  146. WSABASEERR = Winsock.WSABASEERR;
  147. {$EXTERNALSYM WSAECONNRESET}
  148. WSAECONNRESET = Winsock.WSAECONNRESET;
  149. {$EXTERNALSYM WSAENOTSOCK}
  150. WSAENOTSOCK = Winsock.WSAENOTSOCK;
  151. {$EXTERNALSYM WSAENOTCONN}
  152. WSAENOTCONN = Winsock.WSAENOTCONN;
  153. {$EXTERNALSYM WSAEINVAL}
  154. WSAEINVAL = Winsock.WSAEINVAL;
  155. {$EXTERNALSYM WSAECONNABORTED}
  156. WSAECONNABORTED = Winsock.WSAECONNABORTED;
  157. {$EXTERNALSYM WSAEWOULDBLOCK}
  158. WSAEWOULDBLOCK = Winsock.WSAEWOULDBLOCK;
  159. {$EXTERNALSYM WSAEINTR}
  160. WSAEINTR = Winsock.WSAEINTR;
  161. {$EXTERNALSYM WSANOTINITIALISED}
  162. WSANOTINITIALISED = Winsock.WSANOTINITIALISED;
  163. {$EXTERNALSYM WSAEBADF}
  164. WSAEBADF = Winsock.WSAEBADF;
  165. {$EXTERNALSYM WSAEACCES}
  166. WSAEACCES = Winsock.WSAEACCES;
  167. {$EXTERNALSYM WSAEFAULT}
  168. WSAEFAULT = Winsock.WSAEFAULT;
  169. {$EXTERNALSYM WSAEMFILE}
  170. WSAEMFILE = Winsock.WSAEMFILE;
  171. {$EXTERNALSYM WSAEINPROGRESS}
  172. WSAEINPROGRESS = Winsock.WSAEINPROGRESS;
  173. {$EXTERNALSYM WSAEALREADY}
  174. WSAEALREADY = Winsock.WSAEALREADY;
  175. {$EXTERNALSYM WSAEDESTADDRREQ}
  176. WSAEDESTADDRREQ = Winsock.WSAEDESTADDRREQ;
  177. {$EXTERNALSYM WSAEMSGSIZE}
  178. WSAEMSGSIZE = Winsock.WSAEMSGSIZE;
  179. {$EXTERNALSYM WSAEPROTOTYPE}
  180. WSAEPROTOTYPE = Winsock.WSAEPROTOTYPE;
  181. {$EXTERNALSYM WSAENOPROTOOPT}
  182. WSAENOPROTOOPT = Winsock.WSAENOPROTOOPT;
  183. {$EXTERNALSYM WSAEPROTONOSUPPORT}
  184. WSAEPROTONOSUPPORT = Winsock.WSAEPROTONOSUPPORT;
  185. {$EXTERNALSYM WSAESOCKTNOSUPPORT}
  186. WSAESOCKTNOSUPPORT = Winsock.WSAESOCKTNOSUPPORT;
  187. {$EXTERNALSYM WSAEOPNOTSUPP}
  188. WSAEOPNOTSUPP = Winsock.WSAEOPNOTSUPP;
  189. {$EXTERNALSYM WSAEPFNOSUPPORT}
  190. WSAEPFNOSUPPORT = Winsock.WSAEPFNOSUPPORT;
  191. {$EXTERNALSYM WSAEAFNOSUPPORT}
  192. WSAEAFNOSUPPORT = Winsock.WSAEAFNOSUPPORT;
  193. {$EXTERNALSYM WSAEADDRINUSE}
  194. WSAEADDRINUSE = Winsock.WSAEADDRINUSE;
  195. {$EXTERNALSYM WSAEADDRNOTAVAIL}
  196. WSAEADDRNOTAVAIL = Winsock.WSAEADDRNOTAVAIL;
  197. {$EXTERNALSYM WSAENETDOWN}
  198. WSAENETDOWN = Winsock.WSAENETDOWN;
  199. {$EXTERNALSYM WSAENETUNREACH}
  200. WSAENETUNREACH = Winsock.WSAENETUNREACH;
  201. {$EXTERNALSYM WSAENETRESET}
  202. WSAENETRESET = Winsock.WSAENETRESET;
  203. {$EXTERNALSYM WSAENOBUFS}
  204. WSAENOBUFS = Winsock.WSAENOBUFS;
  205. {$EXTERNALSYM WSAEISCONN}
  206. WSAEISCONN = Winsock.WSAEISCONN;
  207. {$EXTERNALSYM WSAESHUTDOWN}
  208. WSAESHUTDOWN = Winsock.WSAESHUTDOWN;
  209. {$EXTERNALSYM WSAETOOMANYREFS}
  210. WSAETOOMANYREFS = Winsock.WSAETOOMANYREFS;
  211. {$EXTERNALSYM WSAETIMEDOUT}
  212. WSAETIMEDOUT = Winsock.WSAETIMEDOUT;
  213. {$EXTERNALSYM WSAECONNREFUSED}
  214. WSAECONNREFUSED = Winsock.WSAECONNREFUSED;
  215. {$EXTERNALSYM WSAELOOP}
  216. WSAELOOP = Winsock.WSAELOOP;
  217. {$EXTERNALSYM WSAENAMETOOLONG}
  218. WSAENAMETOOLONG = Winsock.WSAENAMETOOLONG;
  219. {$EXTERNALSYM WSAEHOSTDOWN}
  220. WSAEHOSTDOWN = Winsock.WSAEHOSTDOWN;
  221. {$EXTERNALSYM WSAEHOSTUNREACH}
  222. WSAEHOSTUNREACH = Winsock.WSAEHOSTUNREACH;
  223. {$EXTERNALSYM WSAENOTEMPTY}
  224. WSAENOTEMPTY = Winsock.WSAENOTEMPTY;
  225. {$EXTERNALSYM WSAEPROCLIM}
  226. WSAEPROCLIM = Winsock.WSAEPROCLIM;
  227. {$EXTERNALSYM WSAEUSERS}
  228. WSAEUSERS = Winsock.WSAEUSERS;
  229. {$EXTERNALSYM WSAEDQUOT}
  230. WSAEDQUOT = Winsock.WSAEDQUOT;
  231. {$EXTERNALSYM WSAESTALE}
  232. WSAESTALE = Winsock.WSAESTALE;
  233. {$EXTERNALSYM WSAEREMOTE}
  234. WSAEREMOTE = Winsock.WSAEREMOTE;
  235. {$EXTERNALSYM WSASYSNOTREADY}
  236. WSASYSNOTREADY = Winsock.WSASYSNOTREADY;
  237. {$EXTERNALSYM WSAVERNOTSUPPORTED}
  238. WSAVERNOTSUPPORTED = Winsock.WSAVERNOTSUPPORTED;
  239. {$EXTERNALSYM WSAHOST_NOT_FOUND}
  240. WSAHOST_NOT_FOUND = Winsock.WSAHOST_NOT_FOUND;
  241. {$EXTERNALSYM WSATRY_AGAIN}
  242. WSATRY_AGAIN = Winsock.WSATRY_AGAIN;
  243. {$EXTERNALSYM WSANO_RECOVERY}
  244. WSANO_RECOVERY = Winsock.WSANO_RECOVERY;
  245. {$EXTERNALSYM WSANO_DATA}
  246. WSANO_DATA = Winsock.WSANO_DATA;
  247. {$EXTERNALSYM SizeOfTSockAddrIn}
  248. SizeOfTSockAddrIn = SizeOf(TSockAddrIn);
  249. {$EXTERNALSYM SizeOfTSockAddr}
  250. SizeOfTSockAddr = SizeOf(TSockAddr);
  251. implementation
  252. {$ENDIF}
  253. {$IFDEF CLR}
  254. {$ALIGN 1}
  255. interface
  256. uses
  257. System.Runtime.InteropServices,
  258. System.Text,
  259. OverbyteIcsTypes;
  260. const
  261. WSADESCRIPTION_LEN = 256;
  262. WSASYS_STATUS_LEN = 128;
  263. IP_DEFAULT_MULTICAST_TTL = 1;
  264. AF_INET = 2; { internetwork: UDP, TCP, etc. }
  265. PF_INET = AF_INET;
  266. IPPROTO_IP = 0; { dummy for IP }
  267. IPPROTO_TCP = 6; { tcp }
  268. IPPROTO_UDP = 17; { user datagram protocol }
  269. IPPROTO_RAW = 255; { raw IP packet }
  270. SOCK_STREAM = 1; { stream socket }
  271. SOCK_DGRAM = 2; { datagram socket }
  272. SOCK_RAW = 3; { raw-protocol interface }
  273. INADDR_ANY = $00000000;
  274. INADDR_LOOPBACK = $7F000001;
  275. INADDR_BROADCAST = -1;
  276. INADDR_NONE = -1;
  277. IP_OPTIONS = 1;
  278. IP_MULTICAST_IF = 2; { set/get IP multicast interface }
  279. IP_MULTICAST_TTL = 3; { set/get IP multicast timetolive }
  280. IP_MULTICAST_LOOP = 4; { set/get IP multicast loopback }
  281. IP_ADD_MEMBERSHIP = 5; { add an IP group membership }
  282. IP_DROP_MEMBERSHIP = 6; { drop an IP group membership }
  283. IP_TTL = 7; { set/get IP Time To Live }
  284. IP_TOS = 8; { set/get IP Type Of Service }
  285. IP_DONTFRAGMENT = 9; { set/get IP Don't Fragment flag }
  286. SOL_SOCKET = $ffff; {options for socket level }
  287. // Option flags per-socket.
  288. SO_DEBUG = $0001; { turn on debugging info recording }
  289. SO_ACCEPTCONN = $0002; { socket has had listen() }
  290. SO_REUSEADDR = $0004; { allow local address reuse }
  291. SO_KEEPALIVE = $0008; { keep connections alive }
  292. SO_DONTROUTE = $0010; { just use interface addresses }
  293. SO_BROADCAST = $0020; { permit sending of broadcast msgs }
  294. SO_USELOOPBACK = $0040; { bypass hardware when possible }
  295. SO_LINGER = $0080; { linger on close if data present }
  296. SO_OOBINLINE = $0100; { leave received OOB data in line }
  297. SO_DONTLINGER = $ff7f;
  298. // Additional options.
  299. SO_SNDBUF = $1001; { send buffer size }
  300. SO_RCVBUF = $1002; { receive buffer size }
  301. SO_SNDLOWAT = $1003; { send low-water mark }
  302. SO_RCVLOWAT = $1004; { receive low-water mark }
  303. SO_SNDTIMEO = $1005; { send timeout }
  304. SO_RCVTIMEO = $1006; { receive timeout }
  305. SO_ERROR = $1007; { get error status and clear }
  306. SO_TYPE = $1008; { get socket type }
  307. TCP_NODELAY = $0001;
  308. // Define flags to be used with the WSAAsyncSelect() call.
  309. FD_READ = $01;
  310. FD_WRITE = $02;
  311. FD_OOB = $04;
  312. FD_ACCEPT = $08;
  313. FD_CONNECT = $10;
  314. FD_CLOSE = $20;
  315. WSABASEERR = 10000;
  316. // Windows Sockets definitions of regular Microsoft C error constants
  317. WSAEINTR = (WSABASEERR+4);
  318. WSAEBADF = (WSABASEERR+9);
  319. WSAEACCES = (WSABASEERR+13);
  320. WSAEFAULT = (WSABASEERR+14);
  321. WSAEINVAL = (WSABASEERR+22);
  322. WSAEMFILE = (WSABASEERR+24);
  323. // Windows Sockets definitions of regular Berkeley error constants
  324. WSAEWOULDBLOCK = (WSABASEERR+35);
  325. WSAEINPROGRESS = (WSABASEERR+36);
  326. WSAEALREADY = (WSABASEERR+37);
  327. WSAENOTSOCK = (WSABASEERR+38);
  328. WSAEDESTADDRREQ = (WSABASEERR+39);
  329. WSAEMSGSIZE = (WSABASEERR+40);
  330. WSAEPROTOTYPE = (WSABASEERR+41);
  331. WSAENOPROTOOPT = (WSABASEERR+42);
  332. WSAEPROTONOSUPPORT = (WSABASEERR+43);
  333. WSAESOCKTNOSUPPORT = (WSABASEERR+44);
  334. WSAEOPNOTSUPP = (WSABASEERR+45);
  335. WSAEPFNOSUPPORT = (WSABASEERR+46);
  336. WSAEAFNOSUPPORT = (WSABASEERR+47);
  337. WSAEADDRINUSE = (WSABASEERR+48);
  338. WSAEADDRNOTAVAIL = (WSABASEERR+49);
  339. WSAENETDOWN = (WSABASEERR+50);
  340. WSAENETUNREACH = (WSABASEERR+51);
  341. WSAENETRESET = (WSABASEERR+52);
  342. WSAECONNABORTED = (WSABASEERR+53);
  343. WSAECONNRESET = (WSABASEERR+54);
  344. WSAENOBUFS = (WSABASEERR+55);
  345. WSAEISCONN = (WSABASEERR+56);
  346. WSAENOTCONN = (WSABASEERR+57);
  347. WSAESHUTDOWN = (WSABASEERR+58);
  348. WSAETOOMANYREFS = (WSABASEERR+59);
  349. WSAETIMEDOUT = (WSABASEERR+60);
  350. WSAECONNREFUSED = (WSABASEERR+61);
  351. WSAELOOP = (WSABASEERR+62);
  352. WSAENAMETOOLONG = (WSABASEERR+63);
  353. WSAEHOSTDOWN = (WSABASEERR+64);
  354. WSAEHOSTUNREACH = (WSABASEERR+65);
  355. WSAENOTEMPTY = (WSABASEERR+66);
  356. WSAEPROCLIM = (WSABASEERR+67);
  357. WSAEUSERS = (WSABASEERR+68);
  358. WSAEDQUOT = (WSABASEERR+69);
  359. WSAESTALE = (WSABASEERR+70);
  360. WSAEREMOTE = (WSABASEERR+71);
  361. WSAEDISCON = (WSABASEERR+101);
  362. // Extended Windows Sockets error constant definitions
  363. WSASYSNOTREADY = (WSABASEERR+91);
  364. WSAVERNOTSUPPORTED = (WSABASEERR+92);
  365. WSANOTINITIALISED = (WSABASEERR+93);
  366. // Error return codes from gethostbyname() and gethostbyaddr()
  367. // (when using the resolver). Note that these errors are
  368. // retrieved via WSAGetLastError() and must therefore follow
  369. // the rules for avoiding clashes with error numbers from
  370. // specific implementations or language run-time systems.
  371. // For this reason the codes are based at WSABASEERR+1001.
  372. // Note also that [WSA]NO_ADDRESS is defined only for
  373. // compatibility purposes.
  374. // Authoritative Answer: Host not found
  375. WSAHOST_NOT_FOUND = (WSABASEERR+1001);
  376. HOST_NOT_FOUND = WSAHOST_NOT_FOUND;
  377. // Non-Authoritative: Host not found, or SERVERFAIL
  378. WSATRY_AGAIN = (WSABASEERR+1002);
  379. TRY_AGAIN = WSATRY_AGAIN;
  380. // Non recoverable errors, FORMERR, REFUSED, NOTIMP
  381. WSANO_RECOVERY = (WSABASEERR+1003);
  382. NO_RECOVERY = WSANO_RECOVERY;
  383. // Valid name, no data record of requested type
  384. WSANO_DATA = (WSABASEERR+1004);
  385. NO_DATA = WSANO_DATA;
  386. // no address, look for MX record
  387. WSANO_ADDRESS = WSANO_DATA;
  388. NO_ADDRESS = WSANO_ADDRESS;
  389. // Windows Sockets errors redefined as regular Berkeley error constants.
  390. // These are commented out in Windows NT to avoid conflicts with errno.h.
  391. // Use the WSA constants instead.
  392. EWOULDBLOCK = WSAEWOULDBLOCK;
  393. EINPROGRESS = WSAEINPROGRESS;
  394. EALREADY = WSAEALREADY;
  395. ENOTSOCK = WSAENOTSOCK;
  396. EDESTADDRREQ = WSAEDESTADDRREQ;
  397. EMSGSIZE = WSAEMSGSIZE;
  398. EPROTOTYPE = WSAEPROTOTYPE;
  399. ENOPROTOOPT = WSAENOPROTOOPT;
  400. EPROTONOSUPPORT = WSAEPROTONOSUPPORT;
  401. ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT;
  402. EOPNOTSUPP = WSAEOPNOTSUPP;
  403. EPFNOSUPPORT = WSAEPFNOSUPPORT;
  404. EAFNOSUPPORT = WSAEAFNOSUPPORT;
  405. EADDRINUSE = WSAEADDRINUSE;
  406. EADDRNOTAVAIL = WSAEADDRNOTAVAIL;
  407. ENETDOWN = WSAENETDOWN;
  408. ENETUNREACH = WSAENETUNREACH;
  409. ENETRESET = WSAENETRESET;
  410. ECONNABORTED = WSAECONNABORTED;
  411. ECONNRESET = WSAECONNRESET;
  412. ENOBUFS = WSAENOBUFS;
  413. EISCONN = WSAEISCONN;
  414. ENOTCONN = WSAENOTCONN;
  415. ESHUTDOWN = WSAESHUTDOWN;
  416. ETOOMANYREFS = WSAETOOMANYREFS;
  417. ETIMEDOUT = WSAETIMEDOUT;
  418. ECONNREFUSED = WSAECONNREFUSED;
  419. ELOOP = WSAELOOP;
  420. ENAMETOOLONG = WSAENAMETOOLONG;
  421. EHOSTDOWN = WSAEHOSTDOWN;
  422. EHOSTUNREACH = WSAEHOSTUNREACH;
  423. ENOTEMPTY = WSAENOTEMPTY;
  424. EPROCLIM = WSAEPROCLIM;
  425. EUSERS = WSAEUSERS;
  426. EDQUOT = WSAEDQUOT;
  427. ESTALE = WSAESTALE;
  428. EREMOTE = WSAEREMOTE;
  429. // ioctlsocket
  430. IOCPARM_MASK = $7f;
  431. IOC_VOID = $20000000;
  432. IOC_OUT = $40000000;
  433. IOC_IN = $80000000;
  434. IOC_INOUT = (IOC_IN or IOC_OUT);
  435. FIONREAD = IOC_OUT or { get # bytes to read }
  436. ((LongInt(SizeOf(LongInt))
  437. and IOCPARM_MASK) shl 16) or
  438. (LongInt(Byte('f')) shl 8) or 127;
  439. FIONBIO = IOC_IN or { set/clear non-blocking i/o }
  440. ((LongInt(SizeOf(LongInt))
  441. and IOCPARM_MASK) shl 16) or
  442. (LongInt(Byte('f')) shl 8) or 126;
  443. FIOASYNC = IOC_IN or { set/clear async i/o }
  444. ((LongInt(SizeOf(LongInt))
  445. and IOCPARM_MASK) shl 16) or
  446. (LongInt(Byte('f')) shl 8) or 125;
  447. { Maximum queue length specifiable by listen. }
  448. SOMAXCONN = 5;
  449. MSG_OOB = $1; {process out-of-band data }
  450. MSG_PEEK = $2; {peek at incoming message }
  451. MSG_DONTROUTE = $4; {send without using routing tables }
  452. MSG_MAXIOVLEN = 16;
  453. MSG_PARTIAL = $8000; {partial send or recv for message xport }
  454. MAXGETHOSTSTRUCT = 1024;
  455. type
  456. [StructLayout(LayoutKind.Sequential)]
  457. TWSAData = record
  458. wVersion : Word;
  459. wHighVersion : Word;
  460. [MarshalAs(UnmanagedType.ByValArray, SizeConst=WSADESCRIPTION_LEN)]
  461. szDescription : array[0..WSADESCRIPTION_LEN] of Char;
  462. [MarshalAs(UnmanagedType.ByValArray, SizeConst=WSASYS_STATUS_LEN)]
  463. szSystemStatus : array[0..WSASYS_STATUS_LEN] of Char;
  464. iMaxSockets : Word;
  465. iMaxUdpDg : Word;
  466. //[MarshalAs(UnmanagedType.LPStr)]
  467. lpVendorInfo : IntPtr;
  468. end;
  469. u_char = Byte;
  470. u_short = Word;
  471. u_long = Cardinal;
  472. u_int = Integer;
  473. TSocket = u_int;
  474. const
  475. INVALID_SOCKET = TSocket(NOT(0));
  476. SOCKET_ERROR = -1;
  477. SizeOfTSockAddrIn = 16; // Win32 size
  478. SizeOfTSockAddr = 16; // Win32 size
  479. type
  480. SunB = packed record
  481. s_b1, s_b2, s_b3, s_b4: u_char;
  482. end;
  483. SunW = packed record
  484. s_w1, s_w2: u_short;
  485. end;
  486. in_addr = record
  487. { case Integer of
  488. 0: (S_un_b: SunB);
  489. 1: (S_un_w: SunW);
  490. 2: (S_addr: u_long); }
  491. S_addr: u_long;
  492. end;
  493. TInAddr = in_addr;
  494. sockaddr_in = record
  495. { case Integer of
  496. 0: (sin_family: u_short;
  497. sin_port: u_short;
  498. sin_addr: TInAddr;
  499. sin_zero: array[0..7] of Char);
  500. 1: (sa_family: u_short;
  501. sa_data: array[0..13] of Char) }
  502. sin_family : u_short;
  503. sin_port : u_short;
  504. sin_addr : TInAddr;
  505. [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
  506. sin_zero : array [0..7] of Char;
  507. end;
  508. TSockAddrIn = sockaddr_in;
  509. PSOCKADDR = ^TSockAddr;
  510. TSockAddr = sockaddr_in;
  511. type
  512. PProtoEnt = ^TProtoEnt;
  513. protoent = record
  514. p_name : IntPtr; //PChar;
  515. p_aliases : IntPtr; //^Pchar;
  516. p_proto : Smallint;
  517. end;
  518. TProtoEnt = protoent;
  519. PServEnt = ^TServEnt;
  520. servent = record
  521. s_name : IntPtr; //PChar;
  522. s_aliases : IntPtr; //^PChar;
  523. s_port : Word;
  524. s_proto : IntPtr; //PChar;
  525. end;
  526. TServEnt = servent;
  527. PHostEnt = ^THostEnt;
  528. hostent = record
  529. h_name : IntPtr; //PChar;
  530. h_aliases : IntPtr; //^PChar;
  531. h_addrtype : Smallint;
  532. h_length : Smallint;
  533. {case Byte of
  534. 0: (h_addr_list: ^PChar);
  535. 1: (h_addr: ^PChar) }
  536. h_addr_list: IntPtr; //^PChar;
  537. end;
  538. THostEnt = hostent;
  539. PLinger = ^TLinger;
  540. linger = record
  541. l_onoff : u_short;
  542. l_linger : u_short;
  543. end;
  544. TLinger = linger;
  545. PTimeVal = ^TTimeVal;
  546. timeval = record
  547. tv_sec : Longint;
  548. tv_usec : Longint;
  549. end;
  550. TTimeVal = timeval;
  551. ip_mreq = record
  552. imr_multiaddr : in_addr;
  553. imr_interface : in_addr;
  554. end;
  555. function WSAStartup(wVersionRequired: WORD;
  556. out WSData: TWSAData): Integer;
  557. function WSACleanup : Integer;
  558. function WSAGetLastError: Integer;
  559. procedure WSASetLastError(iError: Integer);
  560. function WSAAsyncSelect(s: TSocket; HWindow: HWND; wMsg: u_int; lEvent: Longint): Integer;
  561. function WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int; const name : String;
  562. buf: IntPtr; buflen: Integer): THandle;
  563. function WSAAsyncGetHostByAddr(HWindow: HWND; wMsg: u_int; var addr: u_long;
  564. len, Struct: Integer; buf: IntPtr; buflen: Integer): THandle;
  565. function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Integer;
  566. function gethostname(name: StringBuilder; len: Integer): Integer;
  567. function getprotobyname(name : String) : IntPtr;
  568. function getservbyname(name, proto: String): IntPtr;
  569. function gethostbyname(name: String): IntPtr;
  570. function gethostbyaddr(var addr: u_long; len, Struct: Integer): IntPtr;
  571. function getpeername(s: TSocket; out name: TSockAddr;
  572. var namelen: Integer): Integer;
  573. function ntohl(netshort: u_short): u_short;
  574. function htons(hostshort: u_short): u_short;
  575. function ntohs(hostshort: u_short): u_short;
  576. function htonl(hostlong: u_long): u_long;
  577. function inet_addr(const cp: String): u_long;
  578. function inet_ntoa(inaddr: TInAddr): String;
  579. function socket(af, Struct, protocol: Integer): TSocket;
  580. function shutdown(s: TSocket; how: Integer): Integer;
  581. function closesocket(s: TSocket): Integer;
  582. function accept(s: TSocket; var addr: TSockAddr; var addrlen: Integer): TSocket;
  583. function bind(s: TSocket; var addr: TSockAddr; namelen: Integer): Integer;
  584. function connect(s: TSocket; var name: TSockAddr; namelen: Integer): Integer;
  585. function listen(s: TSocket; backlog: Integer): Integer;
  586. function recv(s: TSocket; [out] Buf: TBytes; len, flags: Integer): Integer;
  587. function recvfrom(s: TSocket; [out] Buf: TBytes; len, flags: Integer;
  588. out from: TSockAddr; var fromlen: Integer): Integer;
  589. function ioctlsocket(s: TSocket; cmd: DWORD; var arg: u_long): Integer;
  590. function send(s: TSocket; const Buf : TBytes; len, flags: Integer): Integer;
  591. function sendto(s: TSocket; const Buf : TBytes; len, flags: Integer; var addrto: TSockAddr;
  592. tolen: Integer): Integer;
  593. function getsockname(s: TSocket; out name: TSockAddr; var namelen: Integer): Integer;
  594. function setsockopt_integer(s: TSocket; level, optname: Integer;
  595. var optval: Integer; optlen: Integer): Integer;
  596. function setsockopt_tinaddr(s: TSocket; level, optname: Integer;
  597. var optval: TInAddr; optlen: Integer): Integer;
  598. function setsockopt_ip_mreq(s: TSocket; level, optname: Integer;
  599. var optval: ip_mreq; optlen: Integer): Integer;
  600. function setsockopt_tlinger(s: TSocket; level, optname: Integer;
  601. var optval: TLinger; optlen: Integer): Integer;
  602. function getsockopt_integer(s: TSocket; level, optname: Integer;
  603. var optval: Integer; var optlen: Integer): Integer;
  604. function getsockopt_ip_mreq(s: TSocket; level, optname: Integer;
  605. var optval: ip_mreq; var optlen: Integer): Integer;
  606. function getsockopt_tinaddr(s: TSocket; level, optname: Integer;
  607. var optval: TInAddr; var optlen: Integer): Integer;
  608. function getsockopt_tlinger(s: TSocket; level, optname: Integer;
  609. var optval: TLinger; var optlen: Integer): Integer;
  610. implementation
  611. const
  612. winsocket = 'wsock32.dll';
  613. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'WSAStartup')]
  614. function WSAStartup; external;
  615. [DllImport(winsocket, SetLastError = False, EntryPoint = 'WSACleanup')]
  616. function WSACleanup; external;
  617. [DllImport(winsocket, SetLastError = False, EntryPoint = 'WSAGetLastError')]
  618. function WSAGetLastError; external;
  619. [DllImport(winsocket, SetLastError = False, EntryPoint = 'WSASetLastError')]
  620. procedure WSASetLastError; external;
  621. [DllImport(winsocket, SetLastError = False, EntryPoint = 'WSAAsyncSelect')]
  622. function WSAAsyncSelect; external;
  623. [DllImport(winsocket, SetLastError = False, EntryPoint = 'WSAAsyncGetHostByName')]
  624. function WSAAsyncGetHostByName; external;
  625. [DllImport(winsocket, SetLastError = False, EntryPoint = 'WSAAsyncGetHostByAddr')]
  626. function WSAAsyncGetHostByAddr; external;
  627. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'WSACancelAsyncRequest')]
  628. function WSACancelAsyncRequest; external;
  629. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'gethostname')]
  630. function gethostname; external;
  631. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'getprotobyname')]
  632. function getprotobyname; external;
  633. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'getservbyname')]
  634. function getservbyname; external;
  635. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'gethostbyname')]
  636. function gethostbyname; external;
  637. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'gethostbyaddr')]
  638. function gethostbyaddr; external;
  639. [DllImport(winsocket, SetLastError = False, EntryPoint = 'getpeername')]
  640. function getpeername; external;
  641. [DllImport(winsocket, SetLastError = False, EntryPoint = 'ntohl')]
  642. function ntohl; external;
  643. [DllImport(winsocket, SetLastError = False, EntryPoint = 'htonl')]
  644. function htonl; external;
  645. [DllImport(winsocket, SetLastError = False, EntryPoint = 'htons')]
  646. function htons; external;
  647. [DllImport(winsocket, SetLastError = False, EntryPoint = 'ntohs')]
  648. function ntohs; external;
  649. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'inet_addr')]
  650. function inet_addr; external;
  651. [DllImport(winsocket, CharSet = CharSet.Ansi, SetLastError = False, EntryPoint = 'inet_ntoa')]
  652. function inet_ntoa; external;
  653. [DllImport(winsocket, SetLastError = False, EntryPoint = 'socket')]
  654. function socket; external;
  655. [DllImport(winsocket, SetLastError = False, EntryPoint = 'shutdown')]
  656. function shutdown; external;
  657. [DllImport(winsocket, SetLastError = False, EntryPoint = 'closesocket')]
  658. function closesocket; external;
  659. [DllImport(winsocket, SetLastError = False, EntryPoint = 'bind')]
  660. function bind; external;
  661. [DllImport(winsocket, SetLastError = False, EntryPoint = 'accept')]
  662. function accept; external;
  663. [DllImport(winsocket, SetLastError = False, EntryPoint = 'connect')]
  664. function connect; external;
  665. [DllImport(winsocket, SetLastError = False, EntryPoint = 'listen')]
  666. function listen; external;
  667. [DllImport(winsocket, SetLastError = False, EntryPoint = 'send')]
  668. function send; external;
  669. [DllImport(winsocket, SetLastError = False, EntryPoint = 'sendto')]
  670. function sendto; external;
  671. [DllImport(winsocket, SetLastError = False, EntryPoint = 'recv')]
  672. function recv; external;
  673. [DllImport(winsocket, SetLastError = False, EntryPoint = 'recvfrom')]
  674. function recvfrom; external;
  675. [DllImport(winsocket, SetLastError = False, EntryPoint = 'ioctlsocket')]
  676. function ioctlsocket; external;
  677. [DllImport(winsocket, SetLastError = False, EntryPoint = 'getsockname')]
  678. function getsockname; external;
  679. [DllImport(winsocket, SetLastError = False, EntryPoint = 'setsockopt')]
  680. function setsockopt_integer; external;
  681. [DllImport(winsocket, SetLastError = False, EntryPoint = 'setsockopt')]
  682. function setsockopt_tinaddr; external;
  683. [DllImport(winsocket, SetLastError = False, EntryPoint = 'setsockopt')]
  684. function setsockopt_tlinger; external;
  685. [DllImport(winsocket, SetLastError = False, EntryPoint = 'setsockopt')]
  686. function setsockopt_ip_mreq; external;
  687. [DllImport(winsocket, SetLastError = False, EntryPoint = 'getsockopt')]
  688. function getsockopt_integer; external;
  689. [DllImport(winsocket, SetLastError = False, EntryPoint = 'getsockopt')]
  690. function getsockopt_ip_mreq; external;
  691. [DllImport(winsocket, SetLastError = False, EntryPoint = 'getsockopt')]
  692. function getsockopt_tinaddr; external;
  693. [DllImport(winsocket, SetLastError = False, EntryPoint = 'getsockopt')]
  694. function getsockopt_tlinger; external;
  695. {$ENDIF}
  696. end.