winsock.pp 39 KB

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