winsock.pp 39 KB

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