winsock.pp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. {
  2. This file is part of the Free Pascal run time library.
  3. This unit contains the declarations for the Wince Socket Library
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit winsock;
  13. { convention is cdecl for WinCE API}
  14. {$calling cdecl}
  15. {$ifdef FPC_OS_UNICODE}
  16. {$define UNICODE}
  17. {$endif}
  18. {remaining functions exported from ws2.dll and not used yet = to do,
  19. * please remove functions done *
  20. WSAAccept
  21. WSAAddressToStringW
  22. WSAAsyncGetAddrInfo
  23. WSACloseEvent
  24. WSAConnect
  25. WSACreateEvent
  26. WSAEnumNameSpaceProvidersW
  27. WSAEnumNetworkEvents
  28. WSAEnumProtocolsW
  29. WSAEventSelect
  30. WSAGetOverlappedResult
  31. WSAHtonl
  32. WSAHtons
  33. WSAIoctl
  34. WSAJoinLeaf
  35. WSALookupServiceBeginW
  36. WSALookupServiceEnd
  37. WSALookupServiceNextW
  38. WSANtohl
  39. WSANtohs
  40. WSARecv
  41. WSARecvFrom
  42. WSAResetEvent
  43. WSASend
  44. WSASendTo
  45. WSASetEvent
  46. WSASetServiceW
  47. WSASocketW
  48. WSAStringToAddressW
  49. WSAWaitForMultipleEvents
  50. WSCDeinstallProvider
  51. WSCEnumProtocols
  52. WSCInstallNameSpace
  53. WSCInstallProvider
  54. WSCUnInstallNameSpace
  55. freeaddrinfo
  56. getaddrinfo
  57. getnameinfo
  58. in6addr_any
  59. in6addr_loopback
  60. sethostname
  61. }
  62. interface
  63. uses
  64. windows;
  65. //begin common win32 & wince
  66. const
  67. winsockdll = 'ws2.dll';
  68. WINSOCK_VERSION = $0101; // hopefully is right for winCE too
  69. {
  70. Default maximium number of sockets.
  71. this does not
  72. mean that the underlying Windows Sockets implementation has to
  73. support that many!
  74. }
  75. FD_SETSIZE = 64;
  76. type
  77. tOS_INT = LongInt;
  78. tOS_UINT = DWord;
  79. ptOS_INT = ^tOS_INT;
  80. ptOS_UINT = ^tOS_UINT;
  81. u_char = char;
  82. u_short = word;
  83. u_int = tOS_UINT;
  84. u_long = dword;
  85. pu_long = ^u_long;
  86. plongint = ^longint;
  87. TSocket = u_long;
  88. { there is already a procedure called FD_SET, so this
  89. record was renamed (FK) }
  90. fdset = record
  91. fd_count : u_int;
  92. fd_array : array[0..(FD_SETSIZE)-1] of TSocket;
  93. end;
  94. TFDSet = fdset;
  95. PFDSet = ^fdset;
  96. timeval = record
  97. tv_sec : longint;
  98. tv_usec : longint;
  99. end;
  100. TTimeVal = timeval;
  101. PTimeVal = ^TTimeVal;
  102. { found no reference to this type in c header files and here. AlexS }
  103. { minutes west of Greenwich }
  104. { type of dst correction }
  105. timezone = record
  106. tz_minuteswest : longint;
  107. tz_dsttime : longint;
  108. end;
  109. TTimeZone = timezone;
  110. PTimeZone = ^TTimeZone;
  111. { ioctlsocket(), taken from the BSD file fcntl.h.
  112. Ioctl's have the command encoded in the lower word,
  113. and the size of any in or out parameters in the upper
  114. word. The high 2 bits of the upper word are used
  115. to encode the in/out status of the parameter; for now
  116. restrict parameters to at most 128 bytes.}
  117. const
  118. IOCPARM_MASK = $7f; {parameters must be < 128 bytes}
  119. IOC_VOID = $20000000; {no parameters}
  120. IOC_OUT = $40000000; {copy out parameters}
  121. IOC_IN = $80000000; {copy in parameters}
  122. IOC_INOUT = IOC_IN or IOC_OUT;
  123. FIONREAD =cardinal( IOC_OUT or { get # bytes to read }
  124. ((4 and IOCPARM_MASK) shl 16) or
  125. (102 shl 8) or 127);
  126. FIONBIO = cardinal(IOC_IN or { set/clear non-blocking i/o }
  127. ((4 and IOCPARM_MASK) shl 16) or
  128. (102 shl 8) or 126);
  129. FIOASYNC = cardinal(IOC_IN or { set/clear async i/o = }
  130. ((4 and IOCPARM_MASK) shl 16) or
  131. (102 shl 8) or 125);
  132. { Socket I/O Controls }
  133. SIOCSHIWAT = cardinal(IOC_IN or { set high watermark }
  134. ((4 and IOCPARM_MASK) shl 16) or
  135. (115 shl 8));
  136. SIOCGHIWAT = cardinal(IOC_OUT or { get high watermark }
  137. ((4 and IOCPARM_MASK) shl 16) or
  138. (115 shl 8) or 1);
  139. SIOCSLOWAT = cardinal(IOC_IN or { set low watermark }
  140. ((4 and IOCPARM_MASK) shl 16) or
  141. (115 shl 8) or 2);
  142. SIOCGLOWAT = cardinal(IOC_OUT or { get low watermark }
  143. ((4 and IOCPARM_MASK) shl 16) or
  144. (115 shl 8) or 3);
  145. SIOCATMARK = cardinal(IOC_OUT or { at oob mark? }
  146. ((4 and IOCPARM_MASK) shl 16) or
  147. (115 shl 8) or 7);
  148. {
  149. Structures returned by network data base library, taken from the
  150. BSD file netdb.h. All addresses are supplied in host order, and
  151. returned in network order (suitable for use in system calls).
  152. Slight modifications for differences between Linux and winsock.h
  153. }
  154. type
  155. hostent = record
  156. { official name of host }
  157. h_name: pchar;
  158. { alias list }
  159. h_aliases: ^pchar;
  160. { host address type }
  161. h_addrtype: SmallInt;
  162. { length of address }
  163. h_length: SmallInt;
  164. { list of addresses }
  165. case byte of
  166. 0: (h_addr_list: ^pchar);
  167. 1: (h_addr: ^pchar)
  168. end;
  169. THostEnt = hostent;
  170. PHostEnt = ^THostEnt;
  171. {
  172. Assumption here is that a network number
  173. fits in an unsigned long -- someday that won't be true!
  174. }
  175. netent = record
  176. { official name of net }
  177. n_name : ^char;
  178. { alias list }
  179. n_aliases : ^pchar;
  180. { net address type }
  181. n_addrtype : SmallInt;
  182. n_pad1 : SmallInt; { ensure right packaging }
  183. { network # }
  184. n_net : u_long;
  185. end;
  186. TNetEnt = netent;
  187. PNetEnt = ^TNetEnt;
  188. servent = record
  189. { official service name }
  190. s_name : ^char;
  191. { alias list }
  192. s_aliases : ^pchar;
  193. { port # }
  194. s_port : SmallInt;
  195. n_pad1 : SmallInt; { ensure right packaging }
  196. { protocol to use }
  197. s_proto : ^char;
  198. end;
  199. TServEnt = servent;
  200. PServEnt = ^TServEnt;
  201. protoent = record
  202. { official protocol name }
  203. p_name : ^char;
  204. { alias list }
  205. p_aliases : ^pchar;
  206. { protocol # }
  207. p_proto : SmallInt;
  208. p_pad1 : SmallInt; { ensure packaging }
  209. end;
  210. TProtoEnt = protoent;
  211. PProtoEnt = ^TProtoEnt;
  212. const
  213. {
  214. Standard well-known IP protocols.
  215. For some reason there are differences between Linx and winsock.h
  216. }
  217. IPPROTO_IP = 0;
  218. IPPROTO_ICMP = 1;
  219. IPPROTO_IGMP = 2;
  220. IPPROTO_GGP = 3;
  221. IPPROTO_TCP = 6;
  222. IPPROTO_PUP = 12;
  223. IPPROTO_UDP = 17;
  224. IPPROTO_IDP = 22;
  225. IPPROTO_IPV6 = 41; { IPv6 }
  226. IPPROTO_ND = 77;
  227. IPPROTO_ICLFXBM = 78;
  228. IPPROTO_RAW = 255;
  229. IPPROTO_MAX = 256;
  230. IPPORT_ECHO = 7;
  231. IPPORT_DISCARD = 9;
  232. IPPORT_SYSTAT = 11;
  233. IPPORT_DAYTIME = 13;
  234. IPPORT_NETSTAT = 15;
  235. IPPORT_FTP = 21;
  236. IPPORT_TELNET = 23;
  237. IPPORT_SMTP = 25;
  238. IPPORT_TIMESERVER = 37;
  239. IPPORT_NAMESERVER = 42;
  240. IPPORT_WHOIS = 43;
  241. IPPORT_MTP = 57;
  242. IPPORT_TFTP = 69;
  243. IPPORT_RJE = 77;
  244. IPPORT_FINGER = 79;
  245. IPPORT_TTYLINK = 87;
  246. IPPORT_SUPDUP = 95;
  247. IPPORT_EXECSERVER = 512;
  248. IPPORT_LOGINSERVER = 513;
  249. IPPORT_CMDSERVER = 514;
  250. IPPORT_EFSSERVER = 520;
  251. IPPORT_BIFFUDP = 512;
  252. IPPORT_WHOSERVER = 513;
  253. IPPORT_ROUTESERVER = 520;
  254. IPPORT_RESERVED = 1024;
  255. const
  256. IMPLINK_IP = 155;
  257. IMPLINK_LOWEXPER = 156;
  258. IMPLINK_HIGHEXPER = 158;
  259. type
  260. SunB = record
  261. s_b1,s_b2,s_b3,s_b4 : u_char;
  262. end;
  263. SunW = record
  264. s_w1,s_w2 : u_short;
  265. end;
  266. in_addr = record
  267. case integer of
  268. 0 : (S_un_b : SunB);
  269. 1 : (S_un_w : SunW);
  270. 2 : (S_addr : u_long);
  271. end;
  272. TInAddr = in_addr;
  273. PInAddr = ^TInAddr;
  274. sockaddr_in = record
  275. case integer of
  276. 0 : ( (* equals to sockaddr_in, size is 16 byte *)
  277. sin_family : SmallInt; (* 2 byte *)
  278. sin_port : u_short; (* 2 byte *)
  279. sin_addr : TInAddr; (* 4 byte *)
  280. sin_zero : array[0..8-1] of char; (* 8 byte *)
  281. );
  282. 1 : ((* equals to sockaddr, size is 16 byte *)
  283. sa_family : Smallint; (* 2 byte *)
  284. sa_data : array[0..14-1] of char; (* 14 byte *)
  285. );
  286. end;
  287. TSockAddrIn = sockaddr_in;
  288. PSockAddrIn = ^TSockAddrIn;
  289. TSockAddr = sockaddr_in;
  290. PSockAddr = ^TSockAddr;
  291. const
  292. INADDR_ANY = $00000000;
  293. INADDR_LOOPBACK = $7F000001;
  294. INADDR_BROADCAST = $FFFFFFFF;
  295. IN_CLASSA_NET = $ff000000;
  296. IN_CLASSA_NSHIFT = 24;
  297. IN_CLASSA_HOST = $00ffffff;
  298. IN_CLASSA_MAX = 128;
  299. IN_CLASSB_NET = $ffff0000;
  300. IN_CLASSB_NSHIFT = 16;
  301. IN_CLASSB_HOST = $0000ffff;
  302. IN_CLASSB_MAX = 65536;
  303. IN_CLASSC_NET = $ffffff00;
  304. IN_CLASSC_NSHIFT = 8;
  305. IN_CLASSC_HOST = $000000ff;
  306. WSADESCRIPTION_LEN = 256;
  307. WSASYS_STATUS_LEN = 128;
  308. type
  309. WSADATA = record
  310. wVersion : WORD; { 2 byte, ofs 0 }
  311. wHighVersion : WORD; { 2 byte, ofs 2 }
  312. szDescription : array[0..(WSADESCRIPTION_LEN+1)-1] of char; { 257 byte, ofs 4 }
  313. szSystemStatus : array[0..(WSASYS_STATUS_LEN+1)-1] of char; { 129 byte, ofs 261 }
  314. iMaxSockets : word; { 2 byte, ofs 390 }
  315. iMaxUdpDg : word; { 2 byte, ofs 392 }
  316. pad1 : SmallInt; { 2 byte, ofs 394 } { ensure right packaging }
  317. lpVendorInfo : pchar; { 4 byte, ofs 396 }
  318. end; { total size 400 }
  319. TWSAData = WSADATA;
  320. PWSAData = ^TWSAData;
  321. const
  322. IP_OPTIONS = 1;
  323. IP_MULTICAST_IF = 2;
  324. IP_MULTICAST_TTL = 3;
  325. IP_MULTICAST_LOOP = 4;
  326. IP_ADD_MEMBERSHIP = 5;
  327. IP_DROP_MEMBERSHIP = 6;
  328. IP_DEFAULT_MULTICAST_TTL = 1;
  329. IP_DEFAULT_MULTICAST_LOOP = 1;
  330. IP_MAX_MEMBERSHIPS = 20;
  331. type
  332. ip_mreq = record
  333. imr_multiaddr : in_addr;
  334. imr_interface : in_addr;
  335. end;
  336. {
  337. Definitions related to sockets: types, address families, options,
  338. taken from the BSD file sys/socket.h.
  339. }
  340. const
  341. INVALID_SOCKET = TSocket(not(0));
  342. SOCKET_ERROR = -1;
  343. SOCK_STREAM = 1;
  344. SOCK_DGRAM = 2;
  345. SOCK_RAW = 3;
  346. SOCK_RDM = 4;
  347. SOCK_SEQPACKET = 5;
  348. { For setsockoptions(2) }
  349. SO_DEBUG = $0001;
  350. SO_ACCEPTCONN = $0002;
  351. SO_REUSEADDR = $0004;
  352. SO_KEEPALIVE = $0008;
  353. SO_DONTROUTE = $0010;
  354. SO_BROADCAST = $0020;
  355. SO_USELOOPBACK = $0040;
  356. SO_LINGER = $0080;
  357. SO_OOBINLINE = $0100;
  358. {
  359. Additional options.
  360. }
  361. { send buffer size }
  362. SO_SNDBUF = $1001;
  363. { receive buffer size }
  364. SO_RCVBUF = $1002;
  365. { send low-water mark }
  366. SO_SNDLOWAT = $1003;
  367. { receive low-water mark }
  368. SO_RCVLOWAT = $1004;
  369. { send timeout }
  370. SO_SNDTIMEO = $1005;
  371. { receive timeout }
  372. SO_RCVTIMEO = $1006;
  373. { get error status and clear }
  374. SO_ERROR = $1007;
  375. { get socket type }
  376. SO_TYPE = $1008;
  377. { WinSock 2 extension -- new options }
  378. SO_GROUP_ID = $2001; { ID of a socket group }
  379. SO_GROUP_PRIORITY = $2002; { the relative priority within a group}
  380. SO_MAX_MSG_SIZE = $2003; { maximum message size }
  381. SO_PROTOCOL_INFOA = $2004; { WSAPROTOCOL_INFOA structure }
  382. SO_PROTOCOL_INFOW = $2005; { WSAPROTOCOL_INFOW structure }
  383. {$ifdef UNICODE}
  384. SO_PROTOCOL_INFO = SO_PROTOCOL_INFOW;
  385. {$else}
  386. SO_PROTOCOL_INFO = SO_PROTOCOL_INFOA;
  387. {$endif UNICODE}
  388. PVD_CONFIG = $3001; { configuration info for service provider }
  389. SO_CONDITIONAL_ACCEPT = $3002; { enable true conditional accept: }
  390. { connection is not ack-ed to the }
  391. { other side until conditional }
  392. { function returns CF_ACCEPT }
  393. {
  394. Options for connect and disconnect data and options. Used only by
  395. non-TCP/IP transports such as DECNet, OSI TP4, etc.
  396. }
  397. SO_CONNDATA = $7000;
  398. SO_CONNOPT = $7001;
  399. SO_DISCDATA = $7002;
  400. SO_DISCOPT = $7003;
  401. SO_CONNDATALEN = $7004;
  402. SO_CONNOPTLEN = $7005;
  403. SO_DISCDATALEN = $7006;
  404. SO_DISCOPTLEN = $7007;
  405. {
  406. Option for opening sockets for synchronous access.
  407. }
  408. SO_OPENTYPE = $7008;
  409. SO_SYNCHRONOUS_ALERT = $10;
  410. SO_SYNCHRONOUS_NONALERT = $20;
  411. {
  412. Other NT-specific options.
  413. }
  414. SO_MAXDG = $7009;
  415. SO_MAXPATHDG = $700A;
  416. SO_UPDATE_ACCEPT_CONTEXT = $700B;
  417. SO_CONNECT_TIME = $700C;
  418. {
  419. TCP options.
  420. }
  421. TCP_NODELAY = $0001;
  422. TCP_BSDURGENT = $7000;
  423. {
  424. Address families.
  425. }
  426. { unspecified }
  427. AF_UNSPEC = 0;
  428. { local to host (pipes, portals) }
  429. AF_UNIX = 1;
  430. { internetwork: UDP, TCP, etc. }
  431. AF_INET = 2;
  432. { arpanet imp addresses }
  433. AF_IMPLINK = 3;
  434. { pup protocols: e.g. BSP }
  435. AF_PUP = 4;
  436. { mit CHAOS protocols }
  437. AF_CHAOS = 5;
  438. { IPX and SPX }
  439. AF_IPX = 6;
  440. { XEROX NS protocols }
  441. AF_NS = 6;
  442. { ISO protocols }
  443. AF_ISO = 7;
  444. { OSI is ISO }
  445. AF_OSI = AF_ISO;
  446. { european computer manufacturers }
  447. AF_ECMA = 8;
  448. { datakit protocols }
  449. AF_DATAKIT = 9;
  450. { CCITT protocols, X.25 etc }
  451. AF_CCITT = 10;
  452. { IBM SNA }
  453. AF_SNA = 11;
  454. { DECnet }
  455. AF_DECnet = 12;
  456. { Direct data link interface }
  457. AF_DLI = 13;
  458. { LAT }
  459. AF_LAT = 14;
  460. { NSC Hyperchannel }
  461. AF_HYLINK = 15;
  462. { AppleTalk }
  463. AF_APPLETALK = 16;
  464. { NetBios-style addresses }
  465. AF_NETBIOS = 17;
  466. { VoiceView }
  467. AF_VOICEVIEW = 18;
  468. { FireFox }
  469. AF_FIREFOX = 19;
  470. { Somebody is using this! }
  471. AF_UNKNOWN1 = 20;
  472. { Banyan }
  473. AF_BAN = 21;
  474. {$ifdef UNDER_CE}
  475. {IrDA}
  476. AF_IRDA = 22;
  477. {$else UNDER_CE}
  478. {Native ATM Services}
  479. AF_ATM = 22;
  480. {$endif UNDER_CE}
  481. {Internetwork Version 6}
  482. AF_INET6 = 23;
  483. {Microsoft Wolfpack}
  484. AF_CLUSTER = 24;
  485. {IEEE 1284.4 WG AF}
  486. AF_12844 = 25;
  487. {$ifdef UNDER_CE}
  488. {Native ATM Services}
  489. AF_ATM = 26;
  490. {$else UNDER_CE}
  491. {IrDA}
  492. AF_IRDA = 26;
  493. {$endif UNDER_CE}
  494. {Network Designers OSI & gateway enabled protocols.}
  495. AF_NETDES = 28;
  496. AF_TCNPROCESS = 29;
  497. AF_TCNMESSAGE = 30;
  498. AF_ICLFXBM = 31;
  499. AF_MAX = 32;
  500. type
  501. { Structure used by kernel to pass protocol information in raw sockets.}
  502. sockproto = record
  503. sp_family : u_short;
  504. sp_protocol : u_short;
  505. end;
  506. TSockProto = sockproto;
  507. PSockProto = ^TSockProto;
  508. const
  509. {Protocol families, same as address families for now.}
  510. PF_UNSPEC = AF_UNSPEC;
  511. PF_UNIX = AF_UNIX;
  512. PF_INET = AF_INET;
  513. PF_IMPLINK = AF_IMPLINK;
  514. PF_PUP = AF_PUP;
  515. PF_CHAOS = AF_CHAOS;
  516. PF_NS = AF_NS;
  517. PF_IPX = AF_IPX;
  518. PF_ISO = AF_ISO;
  519. PF_OSI = AF_OSI;
  520. PF_ECMA = AF_ECMA;
  521. PF_DATAKIT = AF_DATAKIT;
  522. PF_CCITT = AF_CCITT;
  523. PF_SNA = AF_SNA;
  524. PF_DECnet = AF_DECnet;
  525. PF_DLI = AF_DLI;
  526. PF_LAT = AF_LAT;
  527. PF_HYLINK = AF_HYLINK;
  528. PF_APPLETALK = AF_APPLETALK;
  529. PF_VOICEVIEW = AF_VOICEVIEW;
  530. PF_FIREFOX = AF_FIREFOX;
  531. PF_UNKNOWN1 = AF_UNKNOWN1;
  532. PF_BAN = AF_BAN;
  533. PF_ATM = AF_ATM;
  534. PF_INET6 = AF_INET6;
  535. PF_MAX = AF_MAX;
  536. type
  537. {
  538. Structure used for manipulating linger option.
  539. }
  540. linger = record
  541. l_onoff : u_short;
  542. l_linger : u_short;
  543. end;
  544. TLinger = linger;
  545. PLinger = ^TLinger;
  546. const
  547. {
  548. Level number for (get/set)sockopt() to apply to socket itself.
  549. }
  550. { options for socket level }
  551. SOL_SOCKET = $ffff;
  552. {
  553. Maximum queue length specifiable by listen.
  554. }
  555. SOMAXCONN = $7fffffff;
  556. { process out-of-band data }
  557. MSG_OOB = $1;
  558. { peek at incoming message }
  559. MSG_PEEK = $2;
  560. { send without using routing tables }
  561. MSG_DONTROUTE = $4;
  562. MSG_MAXIOVLEN = 16;
  563. { partial send or recv for message xport }
  564. MSG_PARTIAL = $8000;
  565. {WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv()
  566. and WSARecvFrom()}
  567. MSG_INTERRUPT = $10; { send/recv in the interrupt context }
  568. {
  569. Define constant based on rfc883, used by gethostbyxxxx() calls.
  570. }
  571. MAXGETHOSTSTRUCT = 1024;
  572. MAXHOSTNAMELEN = MAXGETHOSTSTRUCT;
  573. {Define flags to be used with the WSAAsyncSelect() call.}
  574. FD_READ = $01;
  575. FD_WRITE = $02;
  576. FD_OOB = $04;
  577. FD_ACCEPT = $08;
  578. FD_CONNECT = $10;
  579. FD_CLOSE = $20;
  580. FD_QOS = $40;
  581. FD_GROUP_QOS = $80;
  582. FD_ROUTING_INTERFACE_CHANGE = $100;
  583. FD_ADDRESS_LIST_CHANGE = $200;
  584. FD_MAX_EVENTS = 10;
  585. FD_ALL_EVENTS = $3FF;
  586. {
  587. All Windows Sockets error constants are biased by WSABASEERR from
  588. the "normal"
  589. }
  590. WSABASEERR = 10000;
  591. {
  592. Windows Sockets definitions of regular Microsoft C error constants
  593. }
  594. WSAEINTR = WSABASEERR + 4;
  595. WSAEBADF = WSABASEERR + 9;
  596. WSAEACCES = WSABASEERR + 13;
  597. WSAEFAULT = WSABASEERR + 14;
  598. WSAEINVAL = WSABASEERR + 22;
  599. WSAEMFILE = WSABASEERR + 24;
  600. {
  601. Windows Sockets definitions of regular Berkeley error constants
  602. }
  603. WSAEWOULDBLOCK = WSABASEERR + 35;
  604. WSAEINPROGRESS = WSABASEERR + 36;
  605. WSAEALREADY = WSABASEERR + 37;
  606. WSAENOTSOCK = WSABASEERR + 38;
  607. WSAEDESTADDRREQ = WSABASEERR + 39;
  608. WSAEMSGSIZE = WSABASEERR + 40;
  609. WSAEPROTOTYPE = WSABASEERR + 41;
  610. WSAENOPROTOOPT = WSABASEERR + 42;
  611. WSAEPROTONOSUPPORT = WSABASEERR + 43;
  612. WSAESOCKTNOSUPPORT = WSABASEERR + 44;
  613. WSAEOPNOTSUPP = WSABASEERR + 45;
  614. WSAEPFNOSUPPORT = WSABASEERR + 46;
  615. WSAEAFNOSUPPORT = WSABASEERR + 47;
  616. WSAEADDRINUSE = WSABASEERR + 48;
  617. WSAEADDRNOTAVAIL = WSABASEERR + 49;
  618. WSAENETDOWN = WSABASEERR + 50;
  619. WSAENETUNREACH = WSABASEERR + 51;
  620. WSAENETRESET = WSABASEERR + 52;
  621. WSAECONNABORTED = WSABASEERR + 53;
  622. WSAECONNRESET = WSABASEERR + 54;
  623. WSAENOBUFS = WSABASEERR + 55;
  624. WSAEISCONN = WSABASEERR + 56;
  625. WSAENOTCONN = WSABASEERR + 57;
  626. WSAESHUTDOWN = WSABASEERR + 58;
  627. WSAETOOMANYREFS = WSABASEERR + 59;
  628. WSAETIMEDOUT = WSABASEERR + 60;
  629. WSAECONNREFUSED = WSABASEERR + 61;
  630. WSAELOOP = WSABASEERR + 62;
  631. WSAENAMETOOLONG = WSABASEERR + 63;
  632. WSAEHOSTDOWN = WSABASEERR + 64;
  633. WSAEHOSTUNREACH = WSABASEERR + 65;
  634. WSAENOTEMPTY = WSABASEERR + 66;
  635. WSAEPROCLIM = WSABASEERR + 67;
  636. WSAEUSERS = WSABASEERR + 68;
  637. WSAEDQUOT = WSABASEERR + 69;
  638. WSAESTALE = WSABASEERR + 70;
  639. WSAEREMOTE = WSABASEERR + 71;
  640. {
  641. Extended Windows Sockets error constant definitions
  642. }
  643. WSASYSNOTREADY = WSABASEERR + 91;
  644. WSAVERNOTSUPPORTED = WSABASEERR + 92;
  645. WSANOTINITIALISED = WSABASEERR + 93;
  646. WSAEDISCON = WSABASEERR + 101;
  647. WSAENOMORE = WSABASEERR+102;
  648. WSAECANCELLED = WSABASEERR+103;
  649. WSAEINVALIDPROCTABLE = WSABASEERR+104;
  650. WSAEINVALIDPROVIDER = WSABASEERR+105;
  651. WSAEPROVIDERFAILEDINIT = WSABASEERR+106;
  652. WSASYSCALLFAILURE = WSABASEERR+107;
  653. WSASERVICE_NOT_FOUND = WSABASEERR+108;
  654. WSATYPE_NOT_FOUND = WSABASEERR+109;
  655. WSA_E_NO_MORE = WSABASEERR+110;
  656. WSA_E_CANCELLED = WSABASEERR+111;
  657. WSAEREFUSED = WSABASEERR+112;
  658. {$ifdef UNDER_CE}
  659. WSAEDUPLICATE_NAME = WSABASEERR+900;
  660. {$endif UNDER_CE}
  661. {
  662. Error return codes from gethostbyname() and gethostbyaddr()
  663. (when using the resolver). Note that these errors are
  664. retrieved via WSAGetLastError() and must therefore follow
  665. the rules for avoiding clashes with error numbers from
  666. specific implementations or language run-time systems.
  667. For this reason the codes are based at WSABASEERR+1001.
  668. Note also that [WSA]NO_ADDRESS is defined only for
  669. compatibility purposes.
  670. }
  671. WSAHOST_NOT_FOUND = WSABASEERR + 1001;
  672. HOST_NOT_FOUND = WSAHOST_NOT_FOUND;
  673. { Non-Authoritative: Host not found, or SERVERFAIL }
  674. WSATRY_AGAIN = WSABASEERR + 1002;
  675. TRY_AGAIN = WSATRY_AGAIN;
  676. { Non recoverable errors, FORMERR, REFUSED, NOTIMP }
  677. WSANO_RECOVERY = WSABASEERR + 1003;
  678. NO_RECOVERY = WSANO_RECOVERY;
  679. { Valid name, no data record of requested type }
  680. WSANO_DATA = WSABASEERR + 1004;
  681. NO_DATA = WSANO_DATA;
  682. { no address, look for MX record }
  683. WSANO_ADDRESS = WSANO_DATA;
  684. NO_ADDRESS = WSANO_ADDRESS;
  685. { Define QOS related error return codes }
  686. WSA_QOS_RECEIVERS = WSABASEERR + 1005;
  687. { at least one Reserve has arrived }
  688. WSA_QOS_SENDERS = WSABASEERR + 1006;
  689. { at least one Path has arrived }
  690. WSA_QOS_NO_SENDERS = WSABASEERR + 1007;
  691. { there are no senders }
  692. WSA_QOS_NO_RECEIVERS = WSABASEERR + 1008;
  693. { there are no receivers }
  694. WSA_QOS_REQUEST_CONFIRMED = WSABASEERR + 1009;
  695. { Reserve has been confirmed }
  696. WSA_QOS_ADMISSION_FAILURE = WSABASEERR + 1010;
  697. { error due to lack of resources }
  698. WSA_QOS_POLICY_FAILURE = WSABASEERR + 1011;
  699. { rejected for administrative reasons - bad credentials }
  700. WSA_QOS_BAD_STYLE = WSABASEERR + 1012;
  701. { unknown or conflicting style }
  702. WSA_QOS_BAD_OBJECT = WSABASEERR + 1013;
  703. { problem with some part of the filterspec or providerspecific buffer }
  704. WSA_QOS_TRAFFIC_CTRL_ERROR = WSABASEERR + 1014;
  705. { problem with some part of the flowspec }
  706. WSA_QOS_GENERIC_ERROR = WSABASEERR + 1015;
  707. { general error }
  708. WSA_QOS_ESERVICETYPE = WSABASEERR + 1016;
  709. { invalid service type in flowspec }
  710. WSA_QOS_EFLOWSPEC = WSABASEERR + 1017;
  711. { invalid flowspec }
  712. WSA_QOS_EPROVSPECBUF = WSABASEERR + 1018;
  713. { invalid provider specific buffer }
  714. WSA_QOS_EFILTERSTYLE = WSABASEERR + 1019;
  715. { invalid filter style }
  716. WSA_QOS_EFILTERTYPE = WSABASEERR + 1020;
  717. { invalid filter type }
  718. WSA_QOS_EFILTERCOUNT = WSABASEERR + 1021;
  719. { incorrect number of filters }
  720. WSA_QOS_EOBJLENGTH = WSABASEERR + 1022;
  721. { invalid object length }
  722. WSA_QOS_EFLOWCOUNT = WSABASEERR + 1023;
  723. { incorrect number of flows }
  724. WSA_QOS_EUNKOWNPSOBJ = WSABASEERR + 1024;
  725. { unknown object in provider specific buffer }
  726. WSA_QOS_EPOLICYOBJ = WSABASEERR + 1025;
  727. { invalid policy object in provider specific buffer }
  728. WSA_QOS_EFLOWDESC = WSABASEERR + 1026;
  729. { invalid flow descriptor in the list }
  730. WSA_QOS_EPSFLOWSPEC = WSABASEERR + 1027;
  731. { inconsistent flow spec in provider specific buffer }
  732. WSA_QOS_EPSFILTERSPEC = WSABASEERR + 1028;
  733. { invalid filter spec in provider specific buffer }
  734. WSA_QOS_ESDMODEOBJ = WSABASEERR + 1029;
  735. { invalid shape discard mode object in provider specific buffer }
  736. WSA_QOS_ESHAPERATEOBJ = WSABASEERR + 1030;
  737. { invalid shaping rate object in provider specific buffer }
  738. WSA_QOS_RESERVED_PETYPE = WSABASEERR + 1031;
  739. { reserved policy element in provider specific buffer }
  740. const
  741. {
  742. Windows Sockets errors redefined as regular Berkeley error constants.
  743. }
  744. EWOULDBLOCK = WSAEWOULDBLOCK;
  745. EINPROGRESS = WSAEINPROGRESS;
  746. EALREADY = WSAEALREADY;
  747. ENOTSOCK = WSAENOTSOCK;
  748. EDESTADDRREQ = WSAEDESTADDRREQ;
  749. EMSGSIZE = WSAEMSGSIZE;
  750. EPROTOTYPE = WSAEPROTOTYPE;
  751. ENOPROTOOPT = WSAENOPROTOOPT;
  752. EPROTONOSUPPORT = WSAEPROTONOSUPPORT;
  753. ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT;
  754. EOPNOTSUPP = WSAEOPNOTSUPP;
  755. EPFNOSUPPORT = WSAEPFNOSUPPORT;
  756. EAFNOSUPPORT = WSAEAFNOSUPPORT;
  757. EADDRINUSE = WSAEADDRINUSE;
  758. EADDRNOTAVAIL = WSAEADDRNOTAVAIL;
  759. ENETDOWN = WSAENETDOWN;
  760. ENETUNREACH = WSAENETUNREACH;
  761. ENETRESET = WSAENETRESET;
  762. ECONNABORTED = WSAECONNABORTED;
  763. ECONNRESET = WSAECONNRESET;
  764. ENOBUFS = WSAENOBUFS;
  765. EISCONN = WSAEISCONN;
  766. ENOTCONN = WSAENOTCONN;
  767. ESHUTDOWN = WSAESHUTDOWN;
  768. ETOOMANYREFS = WSAETOOMANYREFS;
  769. ETIMEDOUT = WSAETIMEDOUT;
  770. ECONNREFUSED = WSAECONNREFUSED;
  771. ELOOP = WSAELOOP;
  772. ENAMETOOLONG = WSAENAMETOOLONG;
  773. EHOSTDOWN = WSAEHOSTDOWN;
  774. EHOSTUNREACH = WSAEHOSTUNREACH;
  775. ENOTEMPTY = WSAENOTEMPTY;
  776. EPROCLIM = WSAEPROCLIM;
  777. EUSERS = WSAEUSERS;
  778. EDQUOT = WSAEDQUOT;
  779. ESTALE = WSAESTALE;
  780. EREMOTE = WSAEREMOTE;
  781. TF_DISCONNECT = $01;
  782. TF_REUSE_SOCKET = $02;
  783. TF_WRITE_BEHIND = $04;
  784. {
  785. Options for use with [gs]etsockopt at the IP level.
  786. }
  787. IP_TTL = 7;
  788. IP_TOS = 8;
  789. IP_DONTFRAGMENT = 9;
  790. type
  791. _TRANSMIT_FILE_BUFFERS = record
  792. Head : Pointer;
  793. HeadLength : dword;
  794. Tail : Pointer;
  795. TailLength : dword;
  796. end;
  797. TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS;
  798. TTransmitFileBuffers = _TRANSMIT_FILE_BUFFERS;
  799. PTransmitFileBuffers = ^TTransmitFileBuffers;
  800. {
  801. Winsock types all buffers as pchar (char *), modern POSIX does it the ANSI
  802. C way with pointer (void *). If the pointer overloaded version doesn't exist,
  803. a "pointer" will be passed to the "var" version. (bug 3142).
  804. So if there are var/const versions:
  805. - To keep ported unix code working, there must be "pointer" variants (ANSI)
  806. - To keep Delphi/ported C Winsock code working there must be pchar variants
  807. (K&R)
  808. IOW, there _must_ be 3 versions then: var/const, pchar and pointer}
  809. function accept(s:TSocket; addr: PSockAddr; addrlen : ptOS_INT) : TSocket;external winsockdll name 'accept';
  810. function accept(s:TSocket; addr: PSockAddr; var addrlen : tOS_INT) : TSocket;external winsockdll name 'accept';
  811. function bind(s:TSocket; addr: PSockaddr;namelen:tOS_INT):tOS_INT; external winsockdll name 'bind';
  812. function bind(s:TSocket; const addr: TSockaddr;namelen:tOS_INT):tOS_INT; external winsockdll name 'bind';
  813. function closesocket(s:TSocket):tOS_INT;external winsockdll name 'closesocket';
  814. function connect(s:TSocket; addr:PSockAddr; namelen:tOS_INT):tOS_INT;external winsockdll name 'connect';
  815. function connect(s:TSocket; Const name:TSockAddr; namelen:tOS_INT):tOS_INT;external winsockdll name 'connect';
  816. function ioctlsocket(s:TSocket; cmd:longint; var arg:u_long):tOS_INT;external winsockdll name 'ioctlsocket'; { really a c-long }
  817. function ioctlsocket(s:TSocket; cmd:longint; var arg:longint):tOS_INT;external winsockdll name 'ioctlsocket'; { really a c-long }
  818. function ioctlsocket(s:TSocket; cmd:longint; argp:pu_long):tOS_INT;external winsockdll name 'ioctlsocket'; { really a c-long }
  819. function getpeername(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;
  820. external winsockdll name 'getpeername';
  821. function getsockname(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;
  822. external winsockdll name 'getsockname';
  823. function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pchar;var optlen:tOS_INT):tOS_INT;
  824. external winsockdll name 'getsockopt';
  825. function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pointer;var optlen:tOS_INT):tOS_INT;
  826. external winsockdll name 'getsockopt';
  827. function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;var optval;var optlen:tOS_INT):tOS_INT;
  828. external winsockdll name 'getsockopt';
  829. function htonl(hostlong:u_long):u_long;external winsockdll name 'htonl';
  830. function htons(hostshort:u_short):u_short;external winsockdll name 'htons';
  831. function inet_addr(cp:pchar):cardinal;external winsockdll name 'inet_addr';
  832. function inet_ntoa(i : TInAddr):pchar;external winsockdll name 'inet_ntoa';
  833. function listen(s:TSocket; backlog:tOS_INT):tOS_INT;external winsockdll name 'listen';
  834. function ntohl(netlong:u_long):u_long;external winsockdll name 'ntohl';
  835. function ntohs(netshort:u_short):u_short;external winsockdll name 'ntohs';
  836. function recv(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;external winsockdll name 'recv';
  837. function recv(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT):tOS_INT;external winsockdll name 'recv';
  838. function recv(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT):tOS_INT;external winsockdll name 'recv';
  839. function recvfrom(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT;
  840. external winsockdll name 'recvfrom';
  841. function recvfrom(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT;
  842. external winsockdll name 'recvfrom';
  843. function recvfrom(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT;Const from:TSockAddr; var fromlen:tOS_INT):tOS_INT;
  844. external winsockdll name 'recvfrom';
  845. function select(nfds:tOS_INT; readfds,writefds,exceptfds : PFDSet;timeout: PTimeVal):tOS_INT;
  846. external winsockdll name 'select';
  847. function send(s:TSocket;Const buf; len:tOS_INT; flags:tOS_INT):tOS_INT;
  848. external winsockdll name 'send';
  849. function send(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;
  850. external winsockdll name 'send';
  851. function send(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT):tOS_INT;
  852. external winsockdll name 'send';
  853. function sendto(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT;
  854. external winsockdll name 'sendto';
  855. function sendto(s:TSocket; buf:pointer; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT;
  856. external winsockdll name 'sendto';
  857. function sendto(s:TSocket; Const buf; len:tOS_INT; flags:tOS_INT;Const toaddr:TSockAddr; tolen:tOS_INT):tOS_INT;
  858. external winsockdll name 'sendto';
  859. function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pchar; optlen:tOS_INT):tOS_INT;
  860. external winsockdll name 'setsockopt';
  861. function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pointer; optlen:tOS_INT):tOS_INT;
  862. external winsockdll name 'setsockopt';
  863. function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; Const optval; optlen:tOS_INT):tOS_INT;
  864. external winsockdll name 'setsockopt';
  865. function shutdown(s:TSocket; how:tOS_INT):tOS_INT;
  866. external winsockdll name 'shutdown';
  867. function socket(af:tOS_INT; t:tOS_INT; protocol:tOS_INT):TSocket;
  868. external winsockdll name 'socket';
  869. { Database function prototypes }
  870. function gethostbyaddr(addr:pchar; len:tOS_INT; t:tOS_INT): PHostEnt;external winsockdll name 'gethostbyaddr';
  871. function gethostbyname(name:pchar):PHostEnt;external winsockdll name 'gethostbyname';
  872. function gethostname(name:pchar; namelen:tOS_INT):tOS_INT;external winsockdll name 'gethostname';
  873. function getservbyport(port:tOS_INT; proto:pchar):PServEnt;external winsockdll name 'getservbyport';
  874. function getservbyname(name:pchar; proto:pchar):PServEnt;external winsockdll name 'getservbyname';
  875. function getprotobynumber(proto:tOS_INT):PProtoEnt;external winsockdll name 'getprotobynumber';
  876. function getprotobyname(name:pchar):PProtoEnt;external winsockdll name 'getprotobyname';
  877. { Microsoft Windows Extension function prototypes }
  878. function WSAStartup(wVersionRequired:word;var WSAData:TWSADATA):tOS_INT;
  879. external winsockdll name 'WSAStartup';
  880. function WSACleanup:tOS_INT;external winsockdll name 'WSACleanup';
  881. procedure WSASetLastError(iError:tOS_INT);external winsockdll name 'WSASetLastError';
  882. function WSAGetLastError:tOS_INT;external winsockdll name 'WSAGetLastError';
  883. function WSAAsyncGetHostByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;
  884. external winsockdll name 'WSAAsyncGetHostByName';
  885. function WSACancelAsyncRequest(hAsyncTaskHandle:THandle):tOS_INT;
  886. external winsockdll name 'WSACancelAsyncRequest';
  887. function WSAAsyncSelect(s:TSocket; hWnd:HWND; wMsg:u_int; lEvent:longint):tOS_INT; { really a c-long }
  888. external winsockdll name 'WSAAsyncSelect';
  889. function __WSAFDIsSet(s:TSocket; var FDSet:TFDSet):Bool;
  890. external winsockdll name '__WSAFDIsSet';
  891. function WSAMakeSyncReply(Buflen,Error:Word):dword;
  892. function WSAMakeSelectReply(Event,Error:Word):dword;
  893. function WSAGetAsyncBuflen(Param:dword):Word;
  894. function WSAGetAsyncError(Param:dword):Word;
  895. function WSAGetSelectEvent(Param:dword):Word;
  896. function WSAGetSelectError(Param:dword):Word;
  897. procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet);
  898. function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean;
  899. procedure FD_SET(Socket:TSocket; var FDSet:TFDSet);
  900. procedure FD_ZERO(var FDSet:TFDSet);
  901. //end common win32 & wince
  902. {$ifdef WIN32}
  903. //begin win32 only
  904. function WSAIsBlocking:BOOL;external winsockdll name 'WSAIsBlocking';
  905. function WSAUnhookBlockingHook:tOS_INT;external winsockdll name 'WSAUnhookBlockingHook';
  906. function WSASetBlockingHook(lpBlockFunc:TFarProc):TFarProc;external winsockdll name 'WSASetBlockingHook';
  907. function WSACancelBlockingCall:tOS_INT;external winsockdll name 'WSACancelBlockingCall';
  908. function WSAAsyncGetServByName(hWnd:HWND; wMsg:u_int; name:pchar; proto:pchar; buf:pchar;
  909. buflen:tOS_INT):THandle;external winsockdll name 'WSAAsyncGetServByName';
  910. function WSAAsyncGetServByPort(hWnd:HWND; wMsg:u_int; port:tOS_INT; proto:pchar; buf:pchar;
  911. buflen:tOS_INT):THandle;external winsockdll name 'WSAAsyncGetServByPort';
  912. function WSAAsyncGetProtoByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;
  913. external winsockdll name 'WSAAsyncGetProtoByName';
  914. function WSAAsyncGetProtoByNumber(hWnd:HWND; wMsg:u_int; number:tOS_INT; buf:pchar; buflen:tOS_INT):THandle;
  915. external winsockdll name 'WSAAsyncGetProtoByNumber';
  916. function WSAAsyncGetHostByAddr(hWnd:HWND; wMsg:u_int; addr:pchar; len:tOS_INT; t:tOS_INT;
  917. buf:pchar; buflen:tOS_INT):THandle;
  918. external winsockdll name 'WSAAsyncGetHostByAddr';
  919. function WSARecvEx(s:TSocket;var buf; len:tOS_INT; flags:ptOS_INT):tOS_INT;
  920. external winsockdll name 'WSARecvEx';
  921. function TransmitFile(hSocket:TSocket; hFile:THandle; nNumberOfBytesToWrite:dword;
  922. nNumberOfBytesPerSend:DWORD; lpOverlapped:POverlapped;
  923. lpTransmitBuffers:PTransmitFileBuffers; dwReserved:dword):Bool;
  924. external winsockdll name 'TransmitFile';
  925. function AcceptEx(sListenSocket,sAcceptSocket:TSocket;
  926. lpOutputBuffer:Pointer; dwReceiveDataLength,dwLocalAddressLength,
  927. dwRemoteAddressLength:dword; var lpdwBytesReceived:dword;
  928. lpOverlapped:POverlapped):Bool;
  929. external winsockdll name 'AcceptEx';
  930. procedure GetAcceptExSockaddrs(lpOutputBuffer:Pointer;
  931. dwReceiveDataLength,dwLocalAddressLength,dwRemoteAddressLength:dword;
  932. var LocalSockaddr:PSockAddr; var LocalSockaddrLength:tOS_INT;
  933. var RemoteSockaddr:PSockAddr; var RemoteSockaddrLength:tOS_INT);
  934. external winsockdll name 'GetAcceptExSockaddrs';
  935. //end win32 only
  936. {$endif WIN32}
  937. {$ifdef WINCE}
  938. //begin wince only
  939. //end wince only
  940. {$endif WINCE}
  941. implementation
  942. //begin common win32 & wince
  943. {
  944. Implementation of the helper routines
  945. }
  946. function WSAMakeSyncReply(Buflen,Error:Word):dword;
  947. begin
  948. WSAMakeSyncReply:=MakeLong(Buflen, Error);
  949. end;
  950. function WSAMakeSelectReply(Event,Error:Word):dword;
  951. begin
  952. WSAMakeSelectReply:=MakeLong(Event,Error);
  953. end;
  954. function WSAGetAsyncBuflen(Param:dword):Word;
  955. begin
  956. WSAGetAsyncBuflen:=lo(Param);
  957. end;
  958. function WSAGetAsyncError(Param:dword):Word;
  959. begin
  960. WSAGetAsyncError:=hi(Param);
  961. end;
  962. function WSAGetSelectEvent(Param:dword):Word;
  963. begin
  964. WSAGetSelectEvent:=lo(Param);
  965. end;
  966. function WSAGetSelectError(Param:dword):Word;
  967. begin
  968. WSAGetSelectError:=hi(Param);
  969. end;
  970. procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet);
  971. var
  972. i : u_int;
  973. begin
  974. i:=0;
  975. while i<FDSet.fd_count do
  976. begin
  977. if FDSet.fd_array[i]=Socket then
  978. begin
  979. while i<FDSet.fd_count-1 do
  980. begin
  981. FDSet.fd_array[i]:=FDSet.fd_array[i+1];
  982. inc(i);
  983. end;
  984. dec(FDSet.fd_count);
  985. break;
  986. end;
  987. inc(i);
  988. end;
  989. end;
  990. function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean;
  991. begin
  992. FD_ISSET:=__WSAFDIsSet(Socket,FDSet);
  993. end;
  994. procedure FD_SET(Socket:TSocket; var FDSet:TFDSet);
  995. begin
  996. if FDSet.fd_count<FD_SETSIZE then
  997. begin
  998. FDSet.fd_array[FDSet.fd_count]:=Socket;
  999. Inc(FDSet.fd_count);
  1000. end;
  1001. end;
  1002. procedure FD_ZERO(var FDSet:TFDSet);
  1003. begin
  1004. FDSet.fd_count:=0;
  1005. end;
  1006. //end common win32 & wince
  1007. {$ifdef WIN32}
  1008. //begin win32 only
  1009. //end win32 only
  1010. {$endif WIN32}
  1011. {$ifdef WINCE}
  1012. //begin wince only
  1013. //end wince only
  1014. {$endif WINCE}
  1015. end.