winsock.pp 39 KB

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