jwawinsock.pas 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225
  1. {******************************************************************************}
  2. { }
  3. { Winsock API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: winsock.h, released June 2000. The original Pascal }
  9. { code is: WinSock.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. unit JwaWinSock;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "winsock.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaWinType, JwaWinBase;
  51. (*
  52. * Basic system type definitions, taken from the BSD file sys/types.h.
  53. *)
  54. type
  55. u_char = Byte;
  56. {$EXTERNALSYM u_char}
  57. u_short = Word;
  58. {$EXTERNALSYM u_short}
  59. u_int = Cardinal;
  60. {$EXTERNALSYM u_int}
  61. u_long = Cardinal;
  62. {$EXTERNALSYM u_long}
  63. (*
  64. * The new type to be used in all
  65. * instances which refer to sockets.
  66. *)
  67. type
  68. TSocket = UINT_PTR;
  69. (*
  70. * Select uses arrays of SOCKETs. These macros manipulate such
  71. * arrays. FD_SETSIZE may be defined by the user before including
  72. * this file, but the default here should be >= 64.
  73. *
  74. * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  75. * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  76. *)
  77. const
  78. FD_SETSIZE = 64;
  79. {$EXTERNALSYM FD_SETSIZE}
  80. type
  81. fd_set = record
  82. fd_count: u_int; // how many are SET?
  83. fd_array: array [0..FD_SETSIZE - 1] of TSocket; // an array of SOCKETs
  84. end;
  85. {$EXTERNALSYM fd_set}
  86. TFdSet = fd_set;
  87. PFdSet = ^fd_set;
  88. function __WSAFDIsSet(s: TSocket; var FDSet: TFDSet): Integer; stdcall;
  89. {$EXTERNALSYM __WSAFDIsSet}
  90. procedure FD_CLR(fd: TSocket; var fdset: TFdSet);
  91. {$EXTERNALSYM FD_CLR}
  92. procedure _FD_SET(fd: TSocket; var fdset: TFDSet);
  93. //{$EXTERNALSYM FD_SET}
  94. procedure FD_ZERO(var fdset: TFdSet);
  95. {$EXTERNALSYM FD_ZERO}
  96. function FD_ISSET(fd: TSocket; var fdset: TFdSet): Boolean;
  97. {$EXTERNALSYM FD_ISSET}
  98. (*
  99. * Structure used in select() call, taken from the BSD file sys/time.h.
  100. *)
  101. type
  102. timeval = record
  103. tv_sec: Longint; // seconds
  104. tv_usec: Longint; // and microseconds
  105. end;
  106. {$EXTERNALSYM timeval}
  107. TTimeVal = timeval;
  108. PTimeVal = ^timeval;
  109. (*
  110. * Operations on timevals.
  111. *
  112. * NB: timercmp does not work for >= or <=.
  113. *)
  114. function timerisset(const tvp: TTimeVal): Boolean;
  115. {$EXTERNALSYM timerisset}
  116. //function timercmp(const tvp, uvp: TTimeVal; cmp): Boolean;
  117. //{$EXTERNALSYM timercmp}
  118. procedure timerclear(var tvp: TTimeVal);
  119. {$EXTERNALSYM timerclear}
  120. (*
  121. * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
  122. *
  123. *
  124. * Ioctl's have the command encoded in the lower word,
  125. * and the size of any in or out parameters in the upper
  126. * word. The high 2 bits of the upper word are used
  127. * to encode the in/out status of the parameter; for now
  128. * we restrict parameters to at most 128 bytes.
  129. *)
  130. const
  131. IOCPARM_MASK = $7f; // parameters must be < 128 bytes
  132. {$EXTERNALSYM IOCPARM_MASK}
  133. IOC_VOID = $20000000; // no parameters
  134. {$EXTERNALSYM IOC_VOID}
  135. IOC_OUT = $40000000; // copy out parameters
  136. {$EXTERNALSYM IOC_OUT}
  137. IOC_IN = DWORD($80000000); // copy in parameters
  138. {$EXTERNALSYM IOC_IN}
  139. IOC_INOUT = DWORD(IOC_IN or IOC_OUT);
  140. {$EXTERNALSYM IOC_INOUT}
  141. // 0x20000000 distinguishes new & old ioctl's
  142. function _IO(x, y: DWORD): DWORD;
  143. {$EXTERNALSYM _IO}
  144. function _IOR(x, y, t: DWORD): DWORD;
  145. {$EXTERNALSYM _IOR}
  146. function _IOW(x, y, t: DWORD): DWORD;
  147. {$EXTERNALSYM _IOW}
  148. const
  149. FIONREAD = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 127; // get # bytes to read
  150. {$EXTERNALSYM FIONREAD}
  151. FIONBIO = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 126; // set/clear non-blocking i/o
  152. {$EXTERNALSYM FIONBIO}
  153. FIOASYNC = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 125; // set/clear async i/o
  154. {$EXTERNALSYM FIOASYNC}
  155. (* Socket I/O Controls *)
  156. SIOCSHIWAT = DWORD(IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 0); // set high watermark
  157. {$EXTERNALSYM SIOCSHIWAT}
  158. SIOCGHIWAT = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 1; // get high watermark
  159. {$EXTERNALSYM SIOCGHIWAT}
  160. SIOCSLOWAT = DWORD(IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 2); // set low watermark
  161. {$EXTERNALSYM SIOCSLOWAT}
  162. SIOCGLOWAT = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 3; // get low watermark
  163. {$EXTERNALSYM SIOCGLOWAT}
  164. SIOCATMARK = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 7; // at oob mark?
  165. {$EXTERNALSYM SIOCATMARK}
  166. (*
  167. * Structures returned by network data base library, taken from the
  168. * BSD file netdb.h. All addresses are supplied in host order, and
  169. * returned in network order (suitable for use in system calls).
  170. *)
  171. type
  172. hostent = record
  173. h_name: PChar; // official name of host
  174. h_aliases: PPChar; // alias list
  175. h_addrtype: Smallint; // host address type
  176. h_length: Smallint; // length of address
  177. case Integer of
  178. 0: (h_addr_list: PPChar); // list of addresses
  179. 1: (h_addr: PPChar); // address, for backward compat
  180. end;
  181. {$EXTERNALSYM hostent}
  182. THostEnt = hostent;
  183. PHostEnt = ^hostent;
  184. (*
  185. * It is assumed here that a network number
  186. * fits in 32 bits.
  187. *)
  188. type
  189. netent = record
  190. n_name: PChar; // official name of net
  191. n_aliases: PPChar; // alias list
  192. n_addrtype: Smallint; // net address type
  193. n_net: u_long; // network #
  194. end;
  195. {$EXTERNALSYM netent}
  196. TNetEnt = netent;
  197. PNetEnt = ^netent;
  198. servent = record
  199. s_name: PChar; // official service name
  200. s_aliases: PPChar; // alias list
  201. s_port: Smallint; // port #
  202. s_proto: PChar; // protocol to use
  203. end;
  204. {$EXTERNALSYM servent}
  205. TServEnt = servent;
  206. PServEnt = ^servent;
  207. protoent = record
  208. p_name: PChar; // official protocol name
  209. p_aliases: PPChar; // alias list
  210. p_proto: Smallint; // protocol #
  211. end;
  212. {$EXTERNALSYM protoent}
  213. TProtoEnt = protoent;
  214. PProtoEnt = ^protoent;
  215. (*
  216. * Constants and structures defined by the internet system,
  217. * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  218. *)
  219. (*
  220. * Protocols
  221. *)
  222. const
  223. IPPROTO_IP = 0; // dummy for IP
  224. {$EXTERNALSYM IPPROTO_IP}
  225. IPPROTO_ICMP = 1; // control message protocol
  226. {$EXTERNALSYM IPPROTO_ICMP}
  227. IPPROTO_IGMP = 2; // internet group management protocol
  228. {$EXTERNALSYM IPPROTO_IGMP}
  229. IPPROTO_GGP = 3; // gateway^2 (deprecated)
  230. {$EXTERNALSYM IPPROTO_GGP}
  231. IPPROTO_TCP = 6; // tcp
  232. {$EXTERNALSYM IPPROTO_TCP}
  233. IPPROTO_PUP = 12; // pup
  234. {$EXTERNALSYM IPPROTO_PUP}
  235. IPPROTO_UDP = 17; // user datagram protocol
  236. {$EXTERNALSYM IPPROTO_UDP}
  237. IPPROTO_IDP = 22; // xns idp
  238. {$EXTERNALSYM IPPROTO_IDP}
  239. IPPROTO_ND = 77; // UNOFFICIAL net disk proto
  240. {$EXTERNALSYM IPPROTO_ND}
  241. IPPROTO_RAW = 255; // raw IP packet
  242. {$EXTERNALSYM IPPROTO_RAW}
  243. IPPROTO_MAX = 256;
  244. {$EXTERNALSYM IPPROTO_MAX}
  245. (*
  246. * Port/socket numbers: network standard functions
  247. *)
  248. IPPORT_ECHO = 7;
  249. {$EXTERNALSYM IPPORT_ECHO}
  250. IPPORT_DISCARD = 9;
  251. {$EXTERNALSYM IPPORT_DISCARD}
  252. IPPORT_SYSTAT = 11;
  253. {$EXTERNALSYM IPPORT_SYSTAT}
  254. IPPORT_DAYTIME = 13;
  255. {$EXTERNALSYM IPPORT_DAYTIME}
  256. IPPORT_NETSTAT = 15;
  257. {$EXTERNALSYM IPPORT_NETSTAT}
  258. IPPORT_FTP = 21;
  259. {$EXTERNALSYM IPPORT_FTP}
  260. IPPORT_TELNET = 23;
  261. {$EXTERNALSYM IPPORT_TELNET}
  262. IPPORT_SMTP = 25;
  263. {$EXTERNALSYM IPPORT_SMTP}
  264. IPPORT_TIMESERVER = 37;
  265. {$EXTERNALSYM IPPORT_TIMESERVER}
  266. IPPORT_NAMESERVER = 42;
  267. {$EXTERNALSYM IPPORT_NAMESERVER}
  268. IPPORT_WHOIS = 43;
  269. {$EXTERNALSYM IPPORT_WHOIS}
  270. IPPORT_MTP = 57;
  271. {$EXTERNALSYM IPPORT_MTP}
  272. (*
  273. * Port/socket numbers: host specific functions
  274. *)
  275. IPPORT_TFTP = 69;
  276. {$EXTERNALSYM IPPORT_TFTP}
  277. IPPORT_RJE = 77;
  278. {$EXTERNALSYM IPPORT_RJE}
  279. IPPORT_FINGER = 79;
  280. {$EXTERNALSYM IPPORT_FINGER}
  281. IPPORT_TTYLINK = 87;
  282. {$EXTERNALSYM IPPORT_TTYLINK}
  283. IPPORT_SUPDUP = 95;
  284. {$EXTERNALSYM IPPORT_SUPDUP}
  285. (*
  286. * UNIX TCP sockets
  287. *)
  288. IPPORT_EXECSERVER = 512;
  289. {$EXTERNALSYM IPPORT_EXECSERVER}
  290. IPPORT_LOGINSERVER = 513;
  291. {$EXTERNALSYM IPPORT_LOGINSERVER}
  292. IPPORT_CMDSERVER = 514;
  293. {$EXTERNALSYM IPPORT_CMDSERVER}
  294. IPPORT_EFSSERVER = 520;
  295. {$EXTERNALSYM IPPORT_EFSSERVER}
  296. (*
  297. * UNIX UDP sockets
  298. *)
  299. IPPORT_BIFFUDP = 512;
  300. {$EXTERNALSYM IPPORT_BIFFUDP}
  301. IPPORT_WHOSERVER = 513;
  302. {$EXTERNALSYM IPPORT_WHOSERVER}
  303. IPPORT_ROUTESERVER = 520;
  304. {$EXTERNALSYM IPPORT_ROUTESERVER}
  305. (* 520+1 also used *)
  306. (*
  307. * Ports < IPPORT_RESERVED are reserved for
  308. * privileged processes (e.g. root).
  309. *)
  310. IPPORT_RESERVED = 1024;
  311. {$EXTERNALSYM IPPORT_RESERVED}
  312. (*
  313. * Link numbers
  314. *)
  315. IMPLINK_IP = 155;
  316. {$EXTERNALSYM IMPLINK_IP}
  317. IMPLINK_LOWEXPER = 156;
  318. {$EXTERNALSYM IMPLINK_LOWEXPER}
  319. IMPLINK_HIGHEXPER = 158;
  320. {$EXTERNALSYM IMPLINK_HIGHEXPER}
  321. (*
  322. * Internet address (old style... should be updated)
  323. *)
  324. type
  325. SunB = packed record
  326. s_b1, s_b2, s_b3, s_b4: u_char;
  327. end;
  328. {$EXTERNALSYM SunB}
  329. SunW = packed record
  330. s_w1, s_w2: u_short;
  331. end;
  332. {$EXTERNALSYM SunW}
  333. in_addr = record
  334. case Integer of
  335. 0: (S_un_b: SunB);
  336. 1: (S_un_w: SunW);
  337. 2: (S_addr: u_long);
  338. // #define s_addr S_un.S_addr // can be used for most tcp & ip code
  339. // #define s_host S_un.S_un_b.s_b2 // host on imp
  340. // #define s_net S_un.S_un_b.s_b1 // netword
  341. // #define s_imp S_un.S_un_w.s_w2 // imp
  342. // #define s_impno S_un.S_un_b.s_b4 // imp #
  343. // #define s_lh S_un.S_un_b.s_b3 // logical host
  344. end;
  345. {$EXTERNALSYM in_addr}
  346. TInAddr = in_addr;
  347. PInAddr = ^in_addr;
  348. (*
  349. * Definitions of bits in internet address integers.
  350. * On subnets, the decomposition of addresses to host and net parts
  351. * is done according to subnet mask, not the masks here.
  352. *)
  353. function IN_CLASSA(i: DWORD): Boolean;
  354. {$EXTERNALSYM IN_CLASSA}
  355. const
  356. IN_CLASSA_NET = DWORD($ff000000);
  357. {$EXTERNALSYM IN_CLASSA_NET}
  358. IN_CLASSA_NSHIFT = 24;
  359. {$EXTERNALSYM IN_CLASSA_NSHIFT}
  360. IN_CLASSA_HOST = $00ffffff;
  361. {$EXTERNALSYM IN_CLASSA_HOST}
  362. IN_CLASSA_MAX = 128;
  363. {$EXTERNALSYM IN_CLASSA_MAX}
  364. function IN_CLASSB(i: DWORD): Boolean;
  365. {$EXTERNALSYM IN_CLASSB}
  366. const
  367. IN_CLASSB_NET = DWORD($ffff0000);
  368. {$EXTERNALSYM IN_CLASSB_NET}
  369. IN_CLASSB_NSHIFT = 16;
  370. {$EXTERNALSYM IN_CLASSB_NSHIFT}
  371. IN_CLASSB_HOST = $0000ffff;
  372. {$EXTERNALSYM IN_CLASSB_HOST}
  373. IN_CLASSB_MAX = 65536;
  374. {$EXTERNALSYM IN_CLASSB_MAX}
  375. function IN_CLASSC(i: DWORD): Boolean;
  376. {$EXTERNALSYM IN_CLASSC}
  377. const
  378. IN_CLASSC_NET = DWORD($ffffff00);
  379. {$EXTERNALSYM IN_CLASSC_NET}
  380. IN_CLASSC_NSHIFT = 8;
  381. {$EXTERNALSYM IN_CLASSC_NSHIFT}
  382. IN_CLASSC_HOST = $000000ff;
  383. {$EXTERNALSYM IN_CLASSC_HOST}
  384. const
  385. INADDR_ANY = u_long($00000000);
  386. {$EXTERNALSYM INADDR_ANY}
  387. INADDR_LOOPBACK = $7f000001;
  388. {$EXTERNALSYM INADDR_LOOPBACK}
  389. INADDR_BROADCAST = u_long($ffffffff);
  390. {$EXTERNALSYM INADDR_BROADCAST}
  391. INADDR_NONE = DWORD($ffffffff);
  392. {$EXTERNALSYM INADDR_NONE}
  393. (*
  394. * Socket address, internet style.
  395. *)
  396. type
  397. sockaddr_in = record
  398. sin_family: Smallint;
  399. sin_port: u_short;
  400. sin_addr: in_addr;
  401. sin_zero: array [0..7] of Char;
  402. end;
  403. {$EXTERNALSYM sockaddr_in}
  404. TSockAddrIn = sockaddr_in;
  405. PSockAddrIn = ^sockaddr_in;
  406. const
  407. WSADESCRIPTION_LEN = 256;
  408. {$EXTERNALSYM WSADESCRIPTION_LEN}
  409. WSASYS_STATUS_LEN = 128;
  410. {$EXTERNALSYM WSASYS_STATUS_LEN}
  411. type
  412. WSAData = record
  413. wVersion: WORD;
  414. wHighVersion: WORD;
  415. szDescription: array [0..WSADESCRIPTION_LEN] of Char;
  416. szSystemStatus: array [0..WSASYS_STATUS_LEN] of Char;
  417. iMaxSockets: Word;
  418. iMaxUdpDg: Word;
  419. lpVendorInfo: PChar;
  420. end;
  421. {$EXTERNALSYM WSAData}
  422. LPWSADATA = ^WSAData;
  423. {$EXTERNALSYM LPWSADATA}
  424. TWsaData = WSAData;
  425. PWsaData = LPWSADATA;
  426. (*
  427. * Options for use with [gs]etsockopt at the IP level.
  428. *)
  429. const
  430. IP_OPTIONS = 1; (* set/get IP per-packet options *)
  431. {$EXTERNALSYM IP_OPTIONS}
  432. IP_MULTICAST_IF = 2; (* set/get IP multicast interface *)
  433. {$EXTERNALSYM IP_MULTICAST_IF}
  434. IP_MULTICAST_TTL = 3; (* set/get IP multicast timetolive *)
  435. {$EXTERNALSYM IP_MULTICAST_TTL}
  436. IP_MULTICAST_LOOP = 4; (* set/get IP multicast loopback *)
  437. {$EXTERNALSYM IP_MULTICAST_LOOP}
  438. IP_ADD_MEMBERSHIP = 5; (* add an IP group membership *)
  439. {$EXTERNALSYM IP_ADD_MEMBERSHIP}
  440. IP_DROP_MEMBERSHIP = 6; (* drop an IP group membership *)
  441. {$EXTERNALSYM IP_DROP_MEMBERSHIP}
  442. IP_TTL = 7; (* set/get IP Time To Live *)
  443. {$EXTERNALSYM IP_TTL}
  444. IP_TOS = 8; (* set/get IP Type Of Service *)
  445. {$EXTERNALSYM IP_TOS}
  446. IP_DONTFRAGMENT = 9; (* set/get IP Don't Fragment flag *)
  447. {$EXTERNALSYM IP_DONTFRAGMENT}
  448. IP_DEFAULT_MULTICAST_TTL = 1; (* normally limit m'casts to 1 hop *)
  449. {$EXTERNALSYM IP_DEFAULT_MULTICAST_TTL}
  450. IP_DEFAULT_MULTICAST_LOOP = 1; (* normally hear sends if a member *)
  451. {$EXTERNALSYM IP_DEFAULT_MULTICAST_LOOP}
  452. IP_MAX_MEMBERSHIPS = 20; (* per socket; must fit in one mbuf *)
  453. {$EXTERNALSYM IP_MAX_MEMBERSHIPS}
  454. (*
  455. * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
  456. *)
  457. type
  458. ip_mreq = record
  459. imr_multiaddr: in_addr; (* IP multicast address of group *)
  460. mr_interface: in_addr; (* local IP address of interface *)
  461. end;
  462. {$EXTERNALSYM ip_mreq}
  463. TIpMReq = ip_mreq;
  464. PIpMReq = ^ip_mreq;
  465. (*
  466. * Definitions related to sockets: types, address families, options,
  467. * taken from the BSD file sys/socket.h.
  468. *)
  469. (*
  470. * This is used instead of -1, since the
  471. * SOCKET type is unsigned.
  472. *)
  473. const
  474. INVALID_SOCKET = TSocket(not 0);
  475. {$EXTERNALSYM INVALID_SOCKET}
  476. SOCKET_ERROR = -1;
  477. {$EXTERNALSYM SOCKET_ERROR}
  478. (*
  479. * Types
  480. *)
  481. SOCK_STREAM = 1; // stream socket
  482. {$EXTERNALSYM SOCK_STREAM}
  483. SOCK_DGRAM = 2; // datagram socket
  484. {$EXTERNALSYM SOCK_DGRAM}
  485. SOCK_RAW = 3; // raw-protocol interface
  486. {$EXTERNALSYM SOCK_RAW}
  487. SOCK_RDM = 4; // reliably-delivered message
  488. {$EXTERNALSYM SOCK_RDM}
  489. SOCK_SEQPACKET = 5; // sequenced packet stream
  490. {$EXTERNALSYM SOCK_SEQPACKET}
  491. (*
  492. * Option flags per-socket.
  493. *)
  494. SO_DEBUG = $0001; // turn on debugging info recording
  495. {$EXTERNALSYM SO_DEBUG}
  496. SO_ACCEPTCONN = $0002; // socket has had listen()
  497. {$EXTERNALSYM SO_ACCEPTCONN}
  498. SO_REUSEADDR = $0004; // allow local address reuse
  499. {$EXTERNALSYM SO_REUSEADDR}
  500. SO_KEEPALIVE = $0008; // keep connections alive
  501. {$EXTERNALSYM SO_KEEPALIVE}
  502. SO_DONTROUTE = $0010; // just use interface addresses
  503. {$EXTERNALSYM SO_DONTROUTE}
  504. SO_BROADCAST = $0020; // permit sending of broadcast msgs
  505. {$EXTERNALSYM SO_BROADCAST}
  506. SO_USELOOPBACK = $0040; // bypass hardware when possible
  507. {$EXTERNALSYM SO_USELOOPBACK}
  508. SO_LINGER = $0080; // linger on close if data present
  509. {$EXTERNALSYM SO_LINGER}
  510. SO_OOBINLINE = $0100; // leave received OOB data in line
  511. {$EXTERNALSYM SO_OOBINLINE}
  512. SO_DONTLINGER = DWORD(not SO_LINGER);
  513. {$EXTERNALSYM SO_DONTLINGER}
  514. (*
  515. * Additional options.
  516. *)
  517. SO_SNDBUF = $1001; // send buffer size
  518. {$EXTERNALSYM SO_SNDBUF}
  519. SO_RCVBUF = $1002; // receive buffer size
  520. {$EXTERNALSYM SO_RCVBUF}
  521. SO_SNDLOWAT = $1003; // send low-water mark
  522. {$EXTERNALSYM SO_SNDLOWAT}
  523. SO_RCVLOWAT = $1004; // receive low-water mark
  524. {$EXTERNALSYM SO_RCVLOWAT}
  525. SO_SNDTIMEO = $1005; // send timeout
  526. {$EXTERNALSYM SO_SNDTIMEO}
  527. SO_RCVTIMEO = $1006; // receive timeout
  528. {$EXTERNALSYM SO_RCVTIMEO}
  529. SO_ERROR = $1007; // get error status and clear
  530. {$EXTERNALSYM SO_ERROR}
  531. SO_TYPE = $1008; // get socket type
  532. {$EXTERNALSYM SO_TYPE}
  533. (*
  534. * Options for connect and disconnect data and options. Used only by
  535. * non-TCP/IP transports such as DECNet, OSI TP4, etc.
  536. *)
  537. SO_CONNDATA = $7000;
  538. {$EXTERNALSYM SO_CONNDATA}
  539. SO_CONNOPT = $7001;
  540. {$EXTERNALSYM SO_CONNOPT}
  541. SO_DISCDATA = $7002;
  542. {$EXTERNALSYM SO_DISCDATA}
  543. SO_DISCOPT = $7003;
  544. {$EXTERNALSYM SO_DISCOPT}
  545. SO_CONNDATALEN = $7004;
  546. {$EXTERNALSYM SO_CONNDATALEN}
  547. SO_CONNOPTLEN = $7005;
  548. {$EXTERNALSYM SO_CONNOPTLEN}
  549. SO_DISCDATALEN = $7006;
  550. {$EXTERNALSYM SO_DISCDATALEN}
  551. SO_DISCOPTLEN = $7007;
  552. {$EXTERNALSYM SO_DISCOPTLEN}
  553. (*
  554. * Option for opening sockets for synchronous access.
  555. *)
  556. SO_OPENTYPE = $7008;
  557. {$EXTERNALSYM SO_OPENTYPE}
  558. SO_SYNCHRONOUS_ALERT = $10;
  559. {$EXTERNALSYM SO_SYNCHRONOUS_ALERT}
  560. SO_SYNCHRONOUS_NONALERT = $20;
  561. {$EXTERNALSYM SO_SYNCHRONOUS_NONALERT}
  562. (*
  563. * Other NT-specific options.
  564. *)
  565. SO_MAXDG = $7009;
  566. {$EXTERNALSYM SO_MAXDG}
  567. SO_MAXPATHDG = $700A;
  568. {$EXTERNALSYM SO_MAXPATHDG}
  569. SO_UPDATE_ACCEPT_CONTEXT = $700B;
  570. {$EXTERNALSYM SO_UPDATE_ACCEPT_CONTEXT}
  571. SO_CONNECT_TIME = $700C;
  572. {$EXTERNALSYM SO_CONNECT_TIME}
  573. (*
  574. * TCP options.
  575. *)
  576. TCP_NODELAY = $0001;
  577. {$EXTERNALSYM TCP_NODELAY}
  578. TCP_BSDURGENT = $7000;
  579. {$EXTERNALSYM TCP_BSDURGENT}
  580. (*
  581. * Address families.
  582. *)
  583. AF_UNSPEC = 0; // unspecified
  584. {$EXTERNALSYM AF_UNSPEC}
  585. AF_UNIX = 1; // local to host (pipes, portals
  586. {$EXTERNALSYM AF_UNIX}
  587. AF_INET = 2; // internetwork: UDP, TCP, etc.
  588. {$EXTERNALSYM AF_INET}
  589. AF_IMPLINK = 3; // arpanet imp addresses
  590. {$EXTERNALSYM AF_IMPLINK}
  591. AF_PUP = 4; // pup protocols: e.g. BSP
  592. {$EXTERNALSYM AF_PUP}
  593. AF_CHAOS = 5; // mit CHAOS protocols
  594. {$EXTERNALSYM AF_CHAOS}
  595. AF_NS = 6; // XEROX NS protocols
  596. {$EXTERNALSYM AF_NS}
  597. AF_IPX = AF_NS; // IPX protocols: IPX, SPX, etc.
  598. {$EXTERNALSYM AF_IPX}
  599. AF_ISO = 7; // ISO protocols
  600. {$EXTERNALSYM AF_ISO}
  601. AF_OSI = AF_ISO; // OSI is ISO
  602. {$EXTERNALSYM AF_OSI}
  603. AF_ECMA = 8; // european computer manufacturers
  604. {$EXTERNALSYM AF_ECMA}
  605. AF_DATAKIT = 9; // datakit protocols
  606. {$EXTERNALSYM AF_DATAKIT}
  607. AF_CCITT = 10; // CCITT protocols, X.25 etc
  608. {$EXTERNALSYM AF_CCITT}
  609. AF_SNA = 11; // IBM SNA
  610. {$EXTERNALSYM AF_SNA}
  611. AF_DECnet = 12; // DECnet
  612. {$EXTERNALSYM AF_DECnet}
  613. AF_DLI = 13; // Direct data link interface
  614. {$EXTERNALSYM AF_DLI}
  615. AF_LAT = 14; // LAT
  616. {$EXTERNALSYM AF_LAT}
  617. AF_HYLINK = 15; // NSC Hyperchannel
  618. {$EXTERNALSYM AF_HYLINK}
  619. AF_APPLETALK = 16; // AppleTalk
  620. {$EXTERNALSYM AF_APPLETALK}
  621. AF_NETBIOS = 17; // NetBios-style addresses
  622. {$EXTERNALSYM AF_NETBIOS}
  623. AF_VOICEVIEW = 18; // VoiceView
  624. {$EXTERNALSYM AF_VOICEVIEW}
  625. AF_FIREFOX = 19; // Protocols from Firefox
  626. {$EXTERNALSYM AF_FIREFOX}
  627. AF_UNKNOWN1 = 20; // Somebody is using this!
  628. {$EXTERNALSYM AF_UNKNOWN1}
  629. AF_BAN = 21; // Banyan
  630. {$EXTERNALSYM AF_BAN}
  631. AF_MAX = 22;
  632. {$EXTERNALSYM AF_MAX}
  633. (*
  634. * Structure used by kernel to store most
  635. * addresses.
  636. *)
  637. type
  638. sockaddr = record
  639. sa_family: u_short; // address family
  640. sa_data: array [0..13] of Char; // up to 14 bytes of direct address
  641. end;
  642. {$EXTERNALSYM sockaddr}
  643. TSockAddr = sockaddr;
  644. PSockAddr = ^sockaddr;
  645. (*
  646. * Structure used by kernel to pass protocol
  647. * information in raw sockets.
  648. *)
  649. sockproto = record
  650. sp_family: u_short; // address family
  651. sp_protocol: u_short; // protocol
  652. end;
  653. {$EXTERNALSYM sockproto}
  654. TSockProto = sockproto;
  655. PSockProto = ^sockproto;
  656. (*
  657. * Protocol families, same as address families for now.
  658. *)
  659. const
  660. PF_UNSPEC = AF_UNSPEC;
  661. {$EXTERNALSYM PF_UNSPEC}
  662. PF_UNIX = AF_UNIX;
  663. {$EXTERNALSYM PF_UNIX}
  664. PF_INET = AF_INET;
  665. {$EXTERNALSYM PF_INET}
  666. PF_IMPLINK = AF_IMPLINK;
  667. {$EXTERNALSYM PF_IMPLINK}
  668. PF_PUP = AF_PUP;
  669. {$EXTERNALSYM PF_PUP}
  670. PF_CHAOS = AF_CHAOS;
  671. {$EXTERNALSYM PF_CHAOS}
  672. PF_NS = AF_NS;
  673. {$EXTERNALSYM PF_NS}
  674. PF_IPX = AF_IPX;
  675. {$EXTERNALSYM PF_IPX}
  676. PF_ISO = AF_ISO;
  677. {$EXTERNALSYM PF_ISO}
  678. PF_OSI = AF_OSI;
  679. {$EXTERNALSYM PF_OSI}
  680. PF_ECMA = AF_ECMA;
  681. {$EXTERNALSYM PF_ECMA}
  682. PF_DATAKIT = AF_DATAKIT;
  683. {$EXTERNALSYM PF_DATAKIT}
  684. PF_CCITT = AF_CCITT;
  685. {$EXTERNALSYM PF_CCITT}
  686. PF_SNA = AF_SNA;
  687. {$EXTERNALSYM PF_SNA}
  688. PF_DECnet = AF_DECnet;
  689. {$EXTERNALSYM PF_DECnet}
  690. PF_DLI = AF_DLI;
  691. {$EXTERNALSYM PF_DLI}
  692. PF_LAT = AF_LAT;
  693. {$EXTERNALSYM PF_LAT}
  694. PF_HYLINK = AF_HYLINK;
  695. {$EXTERNALSYM PF_HYLINK}
  696. PF_APPLETALK = AF_APPLETALK;
  697. {$EXTERNALSYM PF_APPLETALK}
  698. PF_VOICEVIEW = AF_VOICEVIEW;
  699. {$EXTERNALSYM PF_VOICEVIEW}
  700. PF_FIREFOX = AF_FIREFOX;
  701. {$EXTERNALSYM PF_FIREFOX}
  702. PF_UNKNOWN1 = AF_UNKNOWN1;
  703. {$EXTERNALSYM PF_UNKNOWN1}
  704. PF_BAN = AF_BAN;
  705. {$EXTERNALSYM PF_BAN}
  706. PF_MAX = AF_MAX;
  707. {$EXTERNALSYM PF_MAX}
  708. (*
  709. * Structure used for manipulating linger option.
  710. *)
  711. type
  712. linger = record
  713. l_onoff: u_short; // option on/off
  714. l_linger: u_short; // linger time
  715. end;
  716. {$EXTERNALSYM linger}
  717. TLinger = linger;
  718. PLinger = ^linger;
  719. (*
  720. * Level number for (get/set)sockopt() to apply to socket itself.
  721. *)
  722. const
  723. SOL_SOCKET = $ffff; // options for socket level
  724. {$EXTERNALSYM SOL_SOCKET}
  725. (*
  726. * Maximum queue length specifiable by listen.
  727. *)
  728. SOMAXCONN = $7fffffff;
  729. {$EXTERNALSYM SOMAXCONN}
  730. MSG_OOB = $1; // process out-of-band data
  731. {$EXTERNALSYM MSG_OOB}
  732. MSG_PEEK = $2; // peek at incoming message
  733. {$EXTERNALSYM MSG_PEEK}
  734. MSG_DONTROUTE = $4; // send without using routing tables
  735. {$EXTERNALSYM MSG_DONTROUTE}
  736. MSG_MAXIOVLEN = 16;
  737. {$EXTERNALSYM MSG_MAXIOVLEN}
  738. MSG_PARTIAL = $8000; // partial send or recv for message xport
  739. {$EXTERNALSYM MSG_PARTIAL}
  740. (*
  741. * Define constant based on rfc883, used by gethostbyxxxx() calls.
  742. *)
  743. MAXGETHOSTSTRUCT = 1024;
  744. {$EXTERNALSYM MAXGETHOSTSTRUCT}
  745. (*
  746. * Define flags to be used with the WSAAsyncSelect() call.
  747. *)
  748. FD_READ = $01;
  749. {$EXTERNALSYM FD_READ}
  750. FD_WRITE = $02;
  751. {$EXTERNALSYM FD_WRITE}
  752. FD_OOB = $04;
  753. {$EXTERNALSYM FD_OOB}
  754. FD_ACCEPT = $08;
  755. {$EXTERNALSYM FD_ACCEPT}
  756. FD_CONNECT = $10;
  757. {$EXTERNALSYM FD_CONNECT}
  758. FD_CLOSE = $20;
  759. {$EXTERNALSYM FD_CLOSE}
  760. (*
  761. * All Windows Sockets error constants are biased by WSABASEERR from
  762. * the "normal"
  763. *)
  764. WSABASEERR = 10000;
  765. {$EXTERNALSYM WSABASEERR}
  766. (*
  767. * Windows Sockets definitions of regular Microsoft C error constants
  768. *)
  769. WSAEINTR = WSABASEERR + 4;
  770. {$EXTERNALSYM WSAEINTR}
  771. WSAEBADF = WSABASEERR + 9;
  772. {$EXTERNALSYM WSAEBADF}
  773. WSAEACCES = WSABASEERR + 13;
  774. {$EXTERNALSYM WSAEACCES}
  775. WSAEFAULT = WSABASEERR + 14;
  776. {$EXTERNALSYM WSAEFAULT}
  777. WSAEINVAL = WSABASEERR + 22;
  778. {$EXTERNALSYM WSAEINVAL}
  779. WSAEMFILE = WSABASEERR + 24;
  780. {$EXTERNALSYM WSAEMFILE}
  781. (*
  782. * Windows Sockets definitions of regular Berkeley error constants
  783. *)
  784. WSAEWOULDBLOCK = WSABASEERR + 35;
  785. {$EXTERNALSYM WSAEWOULDBLOCK}
  786. WSAEINPROGRESS = WSABASEERR + 36;
  787. {$EXTERNALSYM WSAEINPROGRESS}
  788. WSAEALREADY = WSABASEERR + 37;
  789. {$EXTERNALSYM WSAEALREADY}
  790. WSAENOTSOCK = WSABASEERR + 38;
  791. {$EXTERNALSYM WSAENOTSOCK}
  792. WSAEDESTADDRREQ = WSABASEERR + 39;
  793. {$EXTERNALSYM WSAEDESTADDRREQ}
  794. WSAEMSGSIZE = WSABASEERR + 40;
  795. {$EXTERNALSYM WSAEMSGSIZE}
  796. WSAEPROTOTYPE = WSABASEERR + 41;
  797. {$EXTERNALSYM WSAEPROTOTYPE}
  798. WSAENOPROTOOPT = WSABASEERR + 42;
  799. {$EXTERNALSYM WSAENOPROTOOPT}
  800. WSAEPROTONOSUPPORT = WSABASEERR + 43;
  801. {$EXTERNALSYM WSAEPROTONOSUPPORT}
  802. WSAESOCKTNOSUPPORT = WSABASEERR + 44;
  803. {$EXTERNALSYM WSAESOCKTNOSUPPORT}
  804. WSAEOPNOTSUPP = WSABASEERR + 45;
  805. {$EXTERNALSYM WSAEOPNOTSUPP}
  806. WSAEPFNOSUPPORT = WSABASEERR + 46;
  807. {$EXTERNALSYM WSAEPFNOSUPPORT}
  808. WSAEAFNOSUPPORT = WSABASEERR + 47;
  809. {$EXTERNALSYM WSAEAFNOSUPPORT}
  810. WSAEADDRINUSE = WSABASEERR + 48;
  811. {$EXTERNALSYM WSAEADDRINUSE}
  812. WSAEADDRNOTAVAIL = WSABASEERR + 49;
  813. {$EXTERNALSYM WSAEADDRNOTAVAIL}
  814. WSAENETDOWN = WSABASEERR + 50;
  815. {$EXTERNALSYM WSAENETDOWN}
  816. WSAENETUNREACH = WSABASEERR + 51;
  817. {$EXTERNALSYM WSAENETUNREACH}
  818. WSAENETRESET = WSABASEERR + 52;
  819. {$EXTERNALSYM WSAENETRESET}
  820. WSAECONNABORTED = WSABASEERR + 53;
  821. {$EXTERNALSYM WSAECONNABORTED}
  822. WSAECONNRESET = WSABASEERR + 54;
  823. {$EXTERNALSYM WSAECONNRESET}
  824. WSAENOBUFS = WSABASEERR + 55;
  825. {$EXTERNALSYM WSAENOBUFS}
  826. WSAEISCONN = WSABASEERR + 56;
  827. {$EXTERNALSYM WSAEISCONN}
  828. WSAENOTCONN = WSABASEERR + 57;
  829. {$EXTERNALSYM WSAENOTCONN}
  830. WSAESHUTDOWN = WSABASEERR + 58;
  831. {$EXTERNALSYM WSAESHUTDOWN}
  832. WSAETOOMANYREFS = WSABASEERR + 59;
  833. {$EXTERNALSYM WSAETOOMANYREFS}
  834. WSAETIMEDOUT = WSABASEERR + 60;
  835. {$EXTERNALSYM WSAETIMEDOUT}
  836. WSAECONNREFUSED = WSABASEERR + 61;
  837. {$EXTERNALSYM WSAECONNREFUSED}
  838. WSAELOOP = WSABASEERR + 62;
  839. {$EXTERNALSYM WSAELOOP}
  840. WSAENAMETOOLONG = WSABASEERR + 63;
  841. {$EXTERNALSYM WSAENAMETOOLONG}
  842. WSAEHOSTDOWN = WSABASEERR + 64;
  843. {$EXTERNALSYM WSAEHOSTDOWN}
  844. WSAEHOSTUNREACH = WSABASEERR + 65;
  845. {$EXTERNALSYM WSAEHOSTUNREACH}
  846. WSAENOTEMPTY = WSABASEERR + 66;
  847. {$EXTERNALSYM WSAENOTEMPTY}
  848. WSAEPROCLIM = WSABASEERR + 67;
  849. {$EXTERNALSYM WSAEPROCLIM}
  850. WSAEUSERS = WSABASEERR + 68;
  851. {$EXTERNALSYM WSAEUSERS}
  852. WSAEDQUOT = WSABASEERR + 69;
  853. {$EXTERNALSYM WSAEDQUOT}
  854. WSAESTALE = WSABASEERR + 70;
  855. {$EXTERNALSYM WSAESTALE}
  856. WSAEREMOTE = WSABASEERR + 71;
  857. {$EXTERNALSYM WSAEREMOTE}
  858. WSAEDISCON = WSABASEERR + 101;
  859. {$EXTERNALSYM WSAEDISCON}
  860. (*
  861. * Extended Windows Sockets error constant definitions
  862. *)
  863. WSASYSNOTREADY = WSABASEERR + 91;
  864. {$EXTERNALSYM WSASYSNOTREADY}
  865. WSAVERNOTSUPPORTED = WSABASEERR + 92;
  866. {$EXTERNALSYM WSAVERNOTSUPPORTED}
  867. WSANOTINITIALISED = WSABASEERR + 93;
  868. {$EXTERNALSYM WSANOTINITIALISED}
  869. (*
  870. * Error return codes from gethostbyname() and gethostbyaddr()
  871. * (when using the resolver). Note that these errors are
  872. * retrieved via WSAGetLastError() and must therefore follow
  873. * the rules for avoiding clashes with error numbers from
  874. * specific implementations or language run-time systems.
  875. * For this reason the codes are based at WSABASEERR+1001.
  876. * Note also that [WSA]NO_ADDRESS is defined only for
  877. * compatibility purposes.
  878. *)
  879. // Authoritative Answer: Host not found
  880. WSAHOST_NOT_FOUND = WSABASEERR + 1001;
  881. {$EXTERNALSYM WSAHOST_NOT_FOUND}
  882. // Non-Authoritative: Host not found, or SERVERFAIL
  883. WSATRY_AGAIN = WSABASEERR + 1002;
  884. {$EXTERNALSYM WSATRY_AGAIN}
  885. // Non-recoverable errors, FORMERR, REFUSED, NOTIMP
  886. WSANO_RECOVERY = WSABASEERR + 1003;
  887. {$EXTERNALSYM WSANO_RECOVERY}
  888. // Valid name, no data record of requested type
  889. WSANO_DATA = WSABASEERR + 1004;
  890. {$EXTERNALSYM WSANO_DATA}
  891. (*
  892. * Compatibility macros.
  893. *)
  894. function h_errno: Integer;
  895. {$EXTERNALSYM h_errno}
  896. const
  897. HOST_NOT_FOUND = WSAHOST_NOT_FOUND;
  898. {$EXTERNALSYM HOST_NOT_FOUND}
  899. TRY_AGAIN = WSATRY_AGAIN;
  900. {$EXTERNALSYM TRY_AGAIN}
  901. NO_RECOVERY = WSANO_RECOVERY;
  902. {$EXTERNALSYM NO_RECOVERY}
  903. NO_DATA = WSANO_DATA;
  904. {$EXTERNALSYM NO_DATA}
  905. // no address, look for MX record
  906. WSANO_ADDRESS = WSANO_DATA;
  907. {$EXTERNALSYM WSANO_ADDRESS}
  908. NO_ADDRESS = WSANO_ADDRESS;
  909. {$EXTERNALSYM NO_ADDRESS}
  910. (*
  911. * Windows Sockets errors redefined as regular Berkeley error constants.
  912. * These are commented out in Windows NT to avoid conflicts with errno.h.
  913. * Use the WSA constants instead.
  914. *)
  915. {$IFDEF FALSE}
  916. const
  917. EWOULDBLOCK = WSAEWOULDBLOCK;
  918. {$EXTERNALSYM EWOULDBLOCK}
  919. EINPROGRESS = WSAEINPROGRESS;
  920. {$EXTERNALSYM EINPROGRESS}
  921. EALREADY = WSAEALREADY;
  922. {$EXTERNALSYM EALREADY}
  923. ENOTSOCK = WSAENOTSOCK;
  924. {$EXTERNALSYM ENOTSOCK}
  925. EDESTADDRREQ = WSAEDESTADDRREQ;
  926. {$EXTERNALSYM EDESTADDRREQ}
  927. EMSGSIZE = WSAEMSGSIZE;
  928. {$EXTERNALSYM EMSGSIZE}
  929. EPROTOTYPE = WSAEPROTOTYPE;
  930. {$EXTERNALSYM EPROTOTYPE}
  931. ENOPROTOOPT = WSAENOPROTOOPT;
  932. {$EXTERNALSYM ENOPROTOOPT}
  933. EPROTONOSUPPORT = WSAEPROTONOSUPPORT;
  934. {$EXTERNALSYM EPROTONOSUPPORT}
  935. ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT;
  936. {$EXTERNALSYM ESOCKTNOSUPPORT}
  937. EOPNOTSUPP = WSAEOPNOTSUPP;
  938. {$EXTERNALSYM EOPNOTSUPP}
  939. EPFNOSUPPORT = WSAEPFNOSUPPORT;
  940. {$EXTERNALSYM EPFNOSUPPORT}
  941. EAFNOSUPPORT = WSAEAFNOSUPPORT;
  942. {$EXTERNALSYM EAFNOSUPPORT}
  943. EADDRINUSE = WSAEADDRINUSE;
  944. {$EXTERNALSYM EADDRINUSE}
  945. EADDRNOTAVAIL = WSAEADDRNOTAVAIL;
  946. {$EXTERNALSYM EADDRNOTAVAIL}
  947. ENETDOWN = WSAENETDOWN;
  948. {$EXTERNALSYM ENETDOWN}
  949. ENETUNREACH = WSAENETUNREACH;
  950. {$EXTERNALSYM ENETUNREACH}
  951. ENETRESET = WSAENETRESET;
  952. {$EXTERNALSYM ENETRESET}
  953. ECONNABORTED = WSAECONNABORTED;
  954. {$EXTERNALSYM ECONNABORTED}
  955. ECONNRESET = WSAECONNRESET;
  956. {$EXTERNALSYM ECONNRESET}
  957. ENOBUFS = WSAENOBUFS;
  958. {$EXTERNALSYM ENOBUFS}
  959. EISCONN = WSAEISCONN;
  960. {$EXTERNALSYM EISCONN}
  961. ENOTCONN = WSAENOTCONN;
  962. {$EXTERNALSYM ENOTCONN}
  963. ESHUTDOWN = WSAESHUTDOWN;
  964. {$EXTERNALSYM ESHUTDOWN}
  965. ETOOMANYREFS = WSAETOOMANYREFS;
  966. {$EXTERNALSYM ETOOMANYREFS}
  967. ETIMEDOUT = WSAETIMEDOUT;
  968. {$EXTERNALSYM ETIMEDOUT}
  969. ECONNREFUSED = WSAECONNREFUSED;
  970. {$EXTERNALSYM ECONNREFUSED}
  971. ELOOP = WSAELOOP;
  972. {$EXTERNALSYM ELOOP}
  973. ENAMETOOLONG = WSAENAMETOOLONG;
  974. {$EXTERNALSYM ENAMETOOLONG}
  975. EHOSTDOWN = WSAEHOSTDOWN;
  976. {$EXTERNALSYM EHOSTDOWN}
  977. EHOSTUNREACH = WSAEHOSTUNREACH;
  978. {$EXTERNALSYM EHOSTUNREACH}
  979. ENOTEMPTY = WSAENOTEMPTY;
  980. {$EXTERNALSYM ENOTEMPTY}
  981. EPROCLIM = WSAEPROCLIM;
  982. {$EXTERNALSYM EPROCLIM}
  983. EUSERS = WSAEUSERS;
  984. {$EXTERNALSYM EUSERS}
  985. EDQUOT = WSAEDQUOT;
  986. {$EXTERNALSYM EDQUOT}
  987. ESTALE = WSAESTALE;
  988. {$EXTERNALSYM ESTALE}
  989. EREMOTE = WSAEREMOTE;
  990. {$EXTERNALSYM EREMOTE}
  991. {$ENDIF FALSE}
  992. (* Socket function prototypes *)
  993. function accept(s: TSocket; addr: PSockAddr; addrlen: PINT): TSocket; stdcall;
  994. {$EXTERNALSYM accept}
  995. function bind(s: TSocket; name: PSockAddr; namelen: Integer): Integer; stdcall;
  996. {$EXTERNALSYM bind}
  997. function closesocket(s: TSocket): Integer; stdcall;
  998. {$EXTERNALSYM closesocket}
  999. function connect(s: TSocket; name: PSockAddr; namelen: Integer): Integer; stdcall;
  1000. {$EXTERNALSYM connect}
  1001. function ioctlsocket(s: TSocket; cmd: Longint; var argp: u_long): Integer; stdcall;
  1002. {$EXTERNALSYM ioctlsocket}
  1003. function getpeername(s: TSocket; name: PSockAddr; var namelen: Integer): Integer; stdcall;
  1004. {$EXTERNALSYM getpeername}
  1005. function getsockname(s: TSocket; name: PSockAddr; var namelen: Integer): Integer; stdcall;
  1006. {$EXTERNALSYM getsockname}
  1007. function getsockopt(s: TSocket; level, optname: Integer; optval: PChar; var optlen: Integer): Integer; stdcall;
  1008. {$EXTERNALSYM getsockopt}
  1009. function htonl(hostlong: u_long): u_long; stdcall;
  1010. {$EXTERNALSYM htonl}
  1011. function htons(hostshort: u_short): u_short; stdcall;
  1012. {$EXTERNALSYM htons}
  1013. function inet_addr(cp: PChar): u_long; stdcall;
  1014. {$EXTERNALSYM inet_addr}
  1015. function inet_ntoa(inaddr: in_addr): PChar; stdcall;
  1016. {$EXTERNALSYM inet_ntoa}
  1017. function listen(s: TSocket; backlog: Integer): Integer; stdcall;
  1018. {$EXTERNALSYM listen}
  1019. function ntohl(netlong: u_long): u_long; stdcall;
  1020. {$EXTERNALSYM ntohl}
  1021. function ntohs(netshort: u_short): u_short; stdcall;
  1022. {$EXTERNALSYM ntohs}
  1023. function recv(s: TSocket; var buf; len, flags: Integer): Integer; stdcall;
  1024. {$EXTERNALSYM recv}
  1025. function recvfrom(s: TSocket; var buf; len, flags: Integer; from: PSockAddr; var fromlen: Integer): Integer; stdcall;
  1026. {$EXTERNALSYM recvfrom}
  1027. function select(nfds: Integer; readfds, writefds, exceptfds: PFdSet; timeout: PTimeVal): Integer; stdcall;
  1028. {$EXTERNALSYM select}
  1029. function send(s: TSocket; var buf; len, flags: Integer): Integer; stdcall;
  1030. {$EXTERNALSYM send}
  1031. function sendto(s: TSocket; var buf; len, flags: Integer; toaddr: PSockAddr; tolen: Integer): Integer; stdcall;
  1032. {$EXTERNALSYM sendto}
  1033. function setsockopt(s: TSocket; level, optname: Integer; optval: PChar; optlen: Integer): Integer; stdcall;
  1034. {$EXTERNALSYM setsockopt}
  1035. function shutdown(s: TSocket; how: Integer): Integer; stdcall;
  1036. {$EXTERNALSYM shutdown}
  1037. function socket(af, type_, protocol: Integer): TSocket; stdcall;
  1038. {$EXTERNALSYM socket}
  1039. (* Database function prototypes *)
  1040. function gethostbyaddr(addr: PChar; len, type_: Integer): PHostEnt; stdcall;
  1041. {$EXTERNALSYM gethostbyaddr}
  1042. function gethostbyname(name: PChar): PHostEnt; stdcall;
  1043. {$EXTERNALSYM gethostbyname}
  1044. function gethostname(name: PChar; namelen: Integer): Integer; stdcall;
  1045. {$EXTERNALSYM gethostname}
  1046. function getservbyport(port: Integer; proto: PChar): PServEnt; stdcall;
  1047. {$EXTERNALSYM getservbyport}
  1048. function getservbyname(name, proto: PChar): PServEnt; stdcall;
  1049. {$EXTERNALSYM getservbyname}
  1050. function getprotobynumber(number: Integer): PProtoEnt; stdcall;
  1051. {$EXTERNALSYM getprotobynumber}
  1052. function getprotobyname(name: PChar): PProtoEnt; stdcall;
  1053. {$EXTERNALSYM getprotobyname}
  1054. (* Microsoft Windows Extension function prototypes *)
  1055. function WSAStartup(wVersionRequired: WORD; var lpWSAData: TWSAData): Integer; stdcall;
  1056. {$EXTERNALSYM WSAStartup}
  1057. function WSACleanup: Integer; stdcall;
  1058. {$EXTERNALSYM WSACleanup}
  1059. procedure WSASetLastError(iError: Integer); stdcall;
  1060. {$EXTERNALSYM WSASetLastError}
  1061. function WSAGetLastError: Integer; stdcall;
  1062. {$EXTERNALSYM WSAGetLastError}
  1063. function WSAIsBlocking: BOOL; stdcall;
  1064. {$EXTERNALSYM WSAIsBlocking}
  1065. function WSAUnhookBlockingHook: Integer; stdcall;
  1066. {$EXTERNALSYM WSAUnhookBlockingHook}
  1067. function WSASetBlockingHook(lpBlockFunc: FARPROC): FARPROC; stdcall;
  1068. {$EXTERNALSYM WSASetBlockingHook}
  1069. function WSACancelBlockingCall: Integer; stdcall;
  1070. {$EXTERNALSYM WSACancelBlockingCall}
  1071. function WSAAsyncGetServByName(hWnd: HWND; wMsg: u_int; name, proto, buf: PChar;
  1072. buflen: Integer): HANDLE; stdcall;
  1073. {$EXTERNALSYM WSAAsyncGetServByName}
  1074. function WSAAsyncGetServByPort(hWnd: HWND; wMsg: u_int; port: Integer;
  1075. proto, buf: PChar; buflen: Integer): HANDLE; stdcall;
  1076. {$EXTERNALSYM WSAAsyncGetServByPort}
  1077. function WSAAsyncGetProtoByName(hWnd: HWND; wMsg: u_int; name, buf: PChar;
  1078. buflen: Integer): HANDLE; stdcall;
  1079. {$EXTERNALSYM WSAAsyncGetProtoByName}
  1080. function WSAAsyncGetProtoByNumber(hWnd: HWND; wMsg: u_int; number: Integer;
  1081. buf: PChar; buflen: Integer): HANDLE; stdcall;
  1082. {$EXTERNALSYM WSAAsyncGetProtoByNumber}
  1083. function WSAAsyncGetHostByName(hWnd: HWND; wMsg: u_int; name, buf: PChar;
  1084. buflen: Integer): HANDLE; stdcall;
  1085. {$EXTERNALSYM WSAAsyncGetHostByName}
  1086. function WSAAsyncGetHostByAddr(hWnd: HWND; wMsg: u_int; addr: PChar;
  1087. len, type_: Integer; buf: PChar; buflen: Integer): HANDLE; stdcall;
  1088. {$EXTERNALSYM WSAAsyncGetHostByAddr}
  1089. function WSACancelAsyncRequest(hAsyncTaskHandle: HANDLE): Integer; stdcall;
  1090. {$EXTERNALSYM WSACancelAsyncRequest}
  1091. function WSAAsyncSelect(s: TSocket; hWnd: HWND; wMsg: u_int; lEvent: Longint): Integer; stdcall;
  1092. {$EXTERNALSYM WSAAsyncSelect}
  1093. function WSARecvEx(s: TSocket; var buf; len: Integer; var flags: Integer): Integer; stdcall;
  1094. {$EXTERNALSYM WSARecvEx}
  1095. type
  1096. _TRANSMIT_FILE_BUFFERS = record
  1097. Head: LPVOID;
  1098. HeadLength: DWORD;
  1099. Tail: LPVOID;
  1100. TailLength: DWORD;
  1101. end;
  1102. {$EXTERNALSYM _TRANSMIT_FILE_BUFFERS}
  1103. TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS;
  1104. {$EXTERNALSYM TRANSMIT_FILE_BUFFERS}
  1105. PTRANSMIT_FILE_BUFFERS = ^TRANSMIT_FILE_BUFFERS;
  1106. {$EXTERNALSYM PTRANSMIT_FILE_BUFFERS}
  1107. LPTRANSMIT_FILE_BUFFERS = ^TRANSMIT_FILE_BUFFERS;
  1108. {$EXTERNALSYM LPTRANSMIT_FILE_BUFFERS}
  1109. TTransmitFileBuffers = TRANSMIT_FILE_BUFFERS;
  1110. PTransmitFileBuffers = LPTRANSMIT_FILE_BUFFERS;
  1111. const
  1112. TF_DISCONNECT = $01;
  1113. {$EXTERNALSYM TF_DISCONNECT}
  1114. TF_REUSE_SOCKET = $02;
  1115. {$EXTERNALSYM TF_REUSE_SOCKET}
  1116. TF_WRITE_BEHIND = $04;
  1117. {$EXTERNALSYM TF_WRITE_BEHIND}
  1118. function TransmitFile(hSocket: TSocket; hFile: HANDLE; nNumberOfBytesToWrite: DWORD;
  1119. nNumberOfBytesPerSend: DWORD; lpOverlapped: LPOVERLAPPED;
  1120. lpTransmitBuffers: LPTRANSMIT_FILE_BUFFERS; dwReserved: DWORD): BOOL; stdcall;
  1121. {$EXTERNALSYM TransmitFile}
  1122. function AcceptEx(sListenSocket, sAcceptSocket: TSocket;
  1123. lpOutputBuffer: LPVOID; dwReceiveDataLength, dwLocalAddressLength,
  1124. dwRemoteAddressLength: DWORD; var lpdwBytesReceived: DWORD;
  1125. lpOverlapped: LPOVERLAPPED): BOOL; stdcall;
  1126. {$EXTERNALSYM AcceptEx}
  1127. procedure GetAcceptExSockaddrs(lpOutputBuffer: Pointer;
  1128. dwReceiveDataLength, dwLocalAddressLength, dwRemoteAddressLength: DWORD;
  1129. out LocalSockaddr: PSockAddr; var LocalSockaddrLength: Integer;
  1130. out RemoteSockaddr: PSockAddr; var RemoteSockaddrLength: Integer); stdcall;
  1131. {$EXTERNALSYM GetAcceptExSockaddrs}
  1132. (* Microsoft Windows Extended data types *)
  1133. type
  1134. PSOCKADDR_IN = ^sockaddr_in;
  1135. {$EXTERNALSYM PSOCKADDR_IN}
  1136. LPSOCKADDR_IN = ^sockaddr_in;
  1137. {$EXTERNALSYM LPSOCKADDR_IN}
  1138. LPLINGER = PLINGER;
  1139. {$EXTERNALSYM LPLINGER}
  1140. PIN_ADDR = ^in_addr;
  1141. {$EXTERNALSYM PIN_ADDR}
  1142. LPIN_ADDR = ^in_addr;
  1143. {$EXTERNALSYM LPIN_ADDR}
  1144. PFD_SET = ^fd_set;
  1145. {$EXTERNALSYM PFD_SET}
  1146. LPFD_SET = ^fd_set;
  1147. {$EXTERNALSYM LPFD_SET}
  1148. LPHOSTENT = PHOSTENT;
  1149. {$EXTERNALSYM LPHOSTENT}
  1150. LPSERVENT = PSERVENT;
  1151. {$EXTERNALSYM LPSERVENT}
  1152. LPPROTOENT = PPROTOENT;
  1153. {$EXTERNALSYM LPPROTOENT}
  1154. LPTIMEVAL = PTIMEVAL;
  1155. {$EXTERNALSYM LPTIMEVAL}
  1156. (*
  1157. * Windows message parameter composition and decomposition
  1158. * macros.
  1159. *
  1160. * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  1161. * when constructing the response to a WSAAsyncGetXByY() routine.
  1162. *)
  1163. function WSAMAKEASYNCREPLY(buflen, error: WORD): DWORD;
  1164. {$EXTERNALSYM WSAMAKEASYNCREPLY}
  1165. (*
  1166. * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  1167. * when constructing the response to WSAAsyncSelect().
  1168. *)
  1169. function WSAMAKESELECTREPLY(event, error: WORD): DWORD;
  1170. {$EXTERNALSYM WSAMAKESELECTREPLY}
  1171. (*
  1172. * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  1173. * to extract the buffer length from the lParam in the response
  1174. * to a WSAGetXByY().
  1175. *)
  1176. function WSAGETASYNCBUFLEN(lParam: DWORD): WORD;
  1177. {$EXTERNALSYM WSAGETASYNCBUFLEN}
  1178. (*
  1179. * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  1180. * to extract the error code from the lParam in the response
  1181. * to a WSAGetXByY().
  1182. *)
  1183. function WSAGETASYNCERROR(lParam: DWORD): WORD;
  1184. {$EXTERNALSYM WSAGETASYNCERROR}
  1185. (*
  1186. * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  1187. * to extract the event code from the lParam in the response
  1188. * to a WSAAsyncSelect().
  1189. *)
  1190. function WSAGETSELECTEVENT(lParam: DWORD): WORD;
  1191. {$EXTERNALSYM WSAGETSELECTEVENT}
  1192. (*
  1193. * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  1194. * to extract the error code from the lParam in the response
  1195. * to a WSAAsyncSelect().
  1196. *)
  1197. function WSAGETSELECTERROR(lParam: DWORD): WORD;
  1198. {$EXTERNALSYM WSAGETSELECTERROR}
  1199. implementation
  1200. const
  1201. wsock32 = 'wsock32.dll';
  1202. procedure FD_CLR(fd: TSocket; var fdset: TFdSet);
  1203. var
  1204. I: Cardinal;
  1205. begin
  1206. I := 0;
  1207. while I < fdset.fd_count do
  1208. begin
  1209. if fdset.fd_array[I] = fd then
  1210. begin
  1211. while I < fdset.fd_count - 1 do
  1212. begin
  1213. fdset.fd_array[I] := fdset.fd_array[I + 1];
  1214. Inc(I);
  1215. end;
  1216. fdset.fd_count := fdset.fd_count - 1;
  1217. Break;
  1218. end;
  1219. Inc(I);
  1220. end;
  1221. end;
  1222. procedure _FD_SET(fd: TSocket; var fdset: TFDSet);
  1223. var
  1224. I: Cardinal;
  1225. begin
  1226. I := 0;
  1227. while I < fdset.fd_count do
  1228. begin
  1229. if fdset.fd_array[I] = fd then
  1230. Break;
  1231. Inc(I);
  1232. end;
  1233. if I = fdset.fd_count then
  1234. begin
  1235. if fdset.fd_count < FD_SETSIZE then
  1236. begin
  1237. fdset.fd_array[I] := fd;
  1238. fdset.fd_count := fdset.fd_count + 1;
  1239. end;
  1240. end;
  1241. end;
  1242. procedure FD_ZERO(var fdset: TFdSet);
  1243. begin
  1244. fdset.fd_count := 0;
  1245. end;
  1246. function FD_ISSET(fd: TSocket; var fdset: TFdSet): Boolean;
  1247. begin
  1248. Result := __WSAFDIsSet(fd, fdset) <> 0;
  1249. end;
  1250. function timerisset(const tvp: TTimeVal): Boolean;
  1251. begin
  1252. Result := (tvp.tv_sec <> 0) or (tvp.tv_usec <> 0);
  1253. end;
  1254. procedure timerclear(var tvp: TTimeVal);
  1255. begin
  1256. tvp.tv_sec := 0;
  1257. tvp.tv_usec := 0;
  1258. end;
  1259. function _IO(x, y: DWORD): DWORD;
  1260. begin
  1261. Result := IOC_VOID or (x shl 8) or y;
  1262. end;
  1263. function _IOR(x, y, t: DWORD): DWORD;
  1264. begin
  1265. Result := IOC_OUT or ((T and IOCPARM_MASK) shl 16) or (x shl 8) or y;
  1266. end;
  1267. function _IOW(x, y, t: DWORD): DWORD;
  1268. begin
  1269. Result := DWORD(IOC_IN or ((T and IOCPARM_MASK) shl 16) or (x shl 8) or y);
  1270. end;
  1271. function IN_CLASSA(i: DWORD): Boolean;
  1272. begin
  1273. Result := i and DWORD($80000000) = 0;
  1274. end;
  1275. function IN_CLASSB(i: DWORD): Boolean;
  1276. begin
  1277. Result := i and DWORD($C0000000) = DWORD($80000000);
  1278. end;
  1279. function IN_CLASSC(i: DWORD): Boolean;
  1280. begin
  1281. Result := (i and DWORD($e0000000)) = DWORD($C0000000);
  1282. end;
  1283. function h_errno: Integer;
  1284. begin
  1285. Result := WSAGetLastError;
  1286. end;
  1287. function WSAMAKEASYNCREPLY(buflen, error: WORD): DWORD;
  1288. begin
  1289. Result := MAKELONG(buflen, error);
  1290. end;
  1291. function WSAMAKESELECTREPLY(event, error: WORD): DWORD;
  1292. begin
  1293. Result := MAKELONG(event, error);
  1294. end;
  1295. function WSAGETASYNCBUFLEN(lParam: DWORD): WORD;
  1296. begin
  1297. Result := LOWORD(lParam);
  1298. end;
  1299. function WSAGETASYNCERROR(lParam: DWORD): WORD;
  1300. begin
  1301. Result := HIWORD(lParam);
  1302. end;
  1303. function WSAGETSELECTEVENT(lParam: DWORD): WORD;
  1304. begin
  1305. Result := LOWORD(lParam);
  1306. end;
  1307. function WSAGETSELECTERROR(lParam: DWORD): WORD;
  1308. begin
  1309. Result := HIWORD(lParam);
  1310. end;
  1311. {$IFDEF DYNAMIC_LINK}
  1312. var
  1313. ___WSAFDIsSet: Pointer;
  1314. function __WSAFDIsSet;
  1315. begin
  1316. GetProcedureAddress(___WSAFDIsSet, wsock32, '__WSAFDIsSet');
  1317. asm
  1318. MOV ESP, EBP
  1319. POP EBP
  1320. JMP [___WSAFDIsSet]
  1321. end;
  1322. end;
  1323. var
  1324. _accept: Pointer;
  1325. function accept;
  1326. begin
  1327. GetProcedureAddress(_accept, wsock32, 'accept');
  1328. asm
  1329. MOV ESP, EBP
  1330. POP EBP
  1331. JMP [_accept]
  1332. end;
  1333. end;
  1334. var
  1335. _bind: Pointer;
  1336. function bind;
  1337. begin
  1338. GetProcedureAddress(_bind, wsock32, 'bind');
  1339. asm
  1340. MOV ESP, EBP
  1341. POP EBP
  1342. JMP [_bind]
  1343. end;
  1344. end;
  1345. var
  1346. _closesocket: Pointer;
  1347. function closesocket;
  1348. begin
  1349. GetProcedureAddress(_closesocket, wsock32, 'closesocket');
  1350. asm
  1351. MOV ESP, EBP
  1352. POP EBP
  1353. JMP [_closesocket]
  1354. end;
  1355. end;
  1356. var
  1357. _connect: Pointer;
  1358. function connect;
  1359. begin
  1360. GetProcedureAddress(_connect, wsock32, 'connect');
  1361. asm
  1362. MOV ESP, EBP
  1363. POP EBP
  1364. JMP [_connect]
  1365. end;
  1366. end;
  1367. var
  1368. _ioctlsocket: Pointer;
  1369. function ioctlsocket;
  1370. begin
  1371. GetProcedureAddress(_ioctlsocket, wsock32, 'ioctlsocket');
  1372. asm
  1373. MOV ESP, EBP
  1374. POP EBP
  1375. JMP [_ioctlsocket]
  1376. end;
  1377. end;
  1378. var
  1379. _getpeername: Pointer;
  1380. function getpeername;
  1381. begin
  1382. GetProcedureAddress(_getpeername, wsock32, 'getpeername');
  1383. asm
  1384. MOV ESP, EBP
  1385. POP EBP
  1386. JMP [_getpeername]
  1387. end;
  1388. end;
  1389. var
  1390. _getsockname: Pointer;
  1391. function getsockname;
  1392. begin
  1393. GetProcedureAddress(_getsockname, wsock32, 'getsockname');
  1394. asm
  1395. MOV ESP, EBP
  1396. POP EBP
  1397. JMP [_getsockname]
  1398. end;
  1399. end;
  1400. var
  1401. _getsockopt: Pointer;
  1402. function getsockopt;
  1403. begin
  1404. GetProcedureAddress(_getsockopt, wsock32, 'getsockopt');
  1405. asm
  1406. MOV ESP, EBP
  1407. POP EBP
  1408. JMP [_getsockopt]
  1409. end;
  1410. end;
  1411. var
  1412. _htonl: Pointer;
  1413. function htonl;
  1414. begin
  1415. GetProcedureAddress(_htonl, wsock32, 'htonl');
  1416. asm
  1417. MOV ESP, EBP
  1418. POP EBP
  1419. JMP [_htonl]
  1420. end;
  1421. end;
  1422. var
  1423. _htons: Pointer;
  1424. function htons;
  1425. begin
  1426. GetProcedureAddress(_htons, wsock32, 'htons');
  1427. asm
  1428. MOV ESP, EBP
  1429. POP EBP
  1430. JMP [_htons]
  1431. end;
  1432. end;
  1433. var
  1434. _inet_addr: Pointer;
  1435. function inet_addr;
  1436. begin
  1437. GetProcedureAddress(_inet_addr, wsock32, 'inet_addr');
  1438. asm
  1439. MOV ESP, EBP
  1440. POP EBP
  1441. JMP [_inet_addr]
  1442. end;
  1443. end;
  1444. var
  1445. _inet_ntoa: Pointer;
  1446. function inet_ntoa;
  1447. begin
  1448. GetProcedureAddress(_inet_ntoa, wsock32, 'inet_ntoa');
  1449. asm
  1450. MOV ESP, EBP
  1451. POP EBP
  1452. JMP [_inet_ntoa]
  1453. end;
  1454. end;
  1455. var
  1456. _listen: Pointer;
  1457. function listen;
  1458. begin
  1459. GetProcedureAddress(_listen, wsock32, 'listen');
  1460. asm
  1461. MOV ESP, EBP
  1462. POP EBP
  1463. JMP [_listen]
  1464. end;
  1465. end;
  1466. var
  1467. _ntohl: Pointer;
  1468. function ntohl;
  1469. begin
  1470. GetProcedureAddress(_ntohl, wsock32, 'ntohl');
  1471. asm
  1472. MOV ESP, EBP
  1473. POP EBP
  1474. JMP [_ntohl]
  1475. end;
  1476. end;
  1477. var
  1478. _ntohs: Pointer;
  1479. function ntohs;
  1480. begin
  1481. GetProcedureAddress(_ntohs, wsock32, 'ntohs');
  1482. asm
  1483. MOV ESP, EBP
  1484. POP EBP
  1485. JMP [_ntohs]
  1486. end;
  1487. end;
  1488. var
  1489. _recv: Pointer;
  1490. function recv;
  1491. begin
  1492. GetProcedureAddress(_recv, wsock32, 'recv');
  1493. asm
  1494. MOV ESP, EBP
  1495. POP EBP
  1496. JMP [_recv]
  1497. end;
  1498. end;
  1499. var
  1500. _recvfrom: Pointer;
  1501. function recvfrom;
  1502. begin
  1503. GetProcedureAddress(_recvfrom, wsock32, 'recvfrom');
  1504. asm
  1505. MOV ESP, EBP
  1506. POP EBP
  1507. JMP [_recvfrom]
  1508. end;
  1509. end;
  1510. var
  1511. _select: Pointer;
  1512. function select;
  1513. begin
  1514. GetProcedureAddress(_select, wsock32, 'select');
  1515. asm
  1516. MOV ESP, EBP
  1517. POP EBP
  1518. JMP [_select]
  1519. end;
  1520. end;
  1521. var
  1522. _send: Pointer;
  1523. function send;
  1524. begin
  1525. GetProcedureAddress(_send, wsock32, 'send');
  1526. asm
  1527. MOV ESP, EBP
  1528. POP EBP
  1529. JMP [_send]
  1530. end;
  1531. end;
  1532. var
  1533. _sendto: Pointer;
  1534. function sendto;
  1535. begin
  1536. GetProcedureAddress(_sendto, wsock32, 'sendto');
  1537. asm
  1538. MOV ESP, EBP
  1539. POP EBP
  1540. JMP [_sendto]
  1541. end;
  1542. end;
  1543. var
  1544. _setsockopt: Pointer;
  1545. function setsockopt;
  1546. begin
  1547. GetProcedureAddress(_setsockopt, wsock32, 'setsockopt');
  1548. asm
  1549. MOV ESP, EBP
  1550. POP EBP
  1551. JMP [_setsockopt]
  1552. end;
  1553. end;
  1554. var
  1555. _shutdown: Pointer;
  1556. function shutdown;
  1557. begin
  1558. GetProcedureAddress(_shutdown, wsock32, 'shutdown');
  1559. asm
  1560. MOV ESP, EBP
  1561. POP EBP
  1562. JMP [_shutdown]
  1563. end;
  1564. end;
  1565. var
  1566. _socket: Pointer;
  1567. function socket;
  1568. begin
  1569. GetProcedureAddress(_socket, wsock32, 'socket');
  1570. asm
  1571. MOV ESP, EBP
  1572. POP EBP
  1573. JMP [_socket]
  1574. end;
  1575. end;
  1576. var
  1577. _gethostbyaddr: Pointer;
  1578. function gethostbyaddr;
  1579. begin
  1580. GetProcedureAddress(_gethostbyaddr, wsock32, 'gethostbyaddr');
  1581. asm
  1582. MOV ESP, EBP
  1583. POP EBP
  1584. JMP [_gethostbyaddr]
  1585. end;
  1586. end;
  1587. var
  1588. _gethostbyname: Pointer;
  1589. function gethostbyname;
  1590. begin
  1591. GetProcedureAddress(_gethostbyname, wsock32, 'gethostbyname');
  1592. asm
  1593. MOV ESP, EBP
  1594. POP EBP
  1595. JMP [_gethostbyname]
  1596. end;
  1597. end;
  1598. var
  1599. _gethostname: Pointer;
  1600. function gethostname;
  1601. begin
  1602. GetProcedureAddress(_gethostname, wsock32, 'gethostname');
  1603. asm
  1604. MOV ESP, EBP
  1605. POP EBP
  1606. JMP [_gethostname]
  1607. end;
  1608. end;
  1609. var
  1610. _getservbyport: Pointer;
  1611. function getservbyport;
  1612. begin
  1613. GetProcedureAddress(_getservbyport, wsock32, 'getservbyport');
  1614. asm
  1615. MOV ESP, EBP
  1616. POP EBP
  1617. JMP [_getservbyport]
  1618. end;
  1619. end;
  1620. var
  1621. _getservbyname: Pointer;
  1622. function getservbyname;
  1623. begin
  1624. GetProcedureAddress(_getservbyname, wsock32, 'getservbyname');
  1625. asm
  1626. MOV ESP, EBP
  1627. POP EBP
  1628. JMP [_getservbyname]
  1629. end;
  1630. end;
  1631. var
  1632. _getprotobynumber: Pointer;
  1633. function getprotobynumber;
  1634. begin
  1635. GetProcedureAddress(_getprotobynumber, wsock32, 'getprotobynumber');
  1636. asm
  1637. MOV ESP, EBP
  1638. POP EBP
  1639. JMP [_getprotobynumber]
  1640. end;
  1641. end;
  1642. var
  1643. _getprotobyname: Pointer;
  1644. function getprotobyname;
  1645. begin
  1646. GetProcedureAddress(_getprotobyname, wsock32, 'getprotobyname');
  1647. asm
  1648. MOV ESP, EBP
  1649. POP EBP
  1650. JMP [_getprotobyname]
  1651. end;
  1652. end;
  1653. var
  1654. _WSAStartup: Pointer;
  1655. function WSAStartup;
  1656. begin
  1657. GetProcedureAddress(_WSAStartup, wsock32, 'WSAStartup');
  1658. asm
  1659. MOV ESP, EBP
  1660. POP EBP
  1661. JMP [_WSAStartup]
  1662. end;
  1663. end;
  1664. var
  1665. _WSACleanup: Pointer;
  1666. function WSACleanup;
  1667. begin
  1668. GetProcedureAddress(_WSACleanup, wsock32, 'WSACleanup');
  1669. asm
  1670. MOV ESP, EBP
  1671. POP EBP
  1672. JMP [_WSACleanup]
  1673. end;
  1674. end;
  1675. var
  1676. _WSASetLastError: Pointer;
  1677. procedure WSASetLastError;
  1678. begin
  1679. GetProcedureAddress(_WSASetLastError, wsock32, 'WSASetLastError');
  1680. asm
  1681. MOV ESP, EBP
  1682. POP EBP
  1683. JMP [_WSASetLastError]
  1684. end;
  1685. end;
  1686. var
  1687. _WSAGetLastError: Pointer;
  1688. function WSAGetLastError;
  1689. begin
  1690. GetProcedureAddress(_WSAGetLastError, wsock32, 'WSAGetLastError');
  1691. asm
  1692. MOV ESP, EBP
  1693. POP EBP
  1694. JMP [_WSAGetLastError]
  1695. end;
  1696. end;
  1697. var
  1698. _WSAIsBlocking: Pointer;
  1699. function WSAIsBlocking;
  1700. begin
  1701. GetProcedureAddress(_WSAIsBlocking, wsock32, 'WSAIsBlocking');
  1702. asm
  1703. MOV ESP, EBP
  1704. POP EBP
  1705. JMP [_WSAIsBlocking]
  1706. end;
  1707. end;
  1708. var
  1709. _WSAUnhookBlockingHook: Pointer;
  1710. function WSAUnhookBlockingHook;
  1711. begin
  1712. GetProcedureAddress(_WSAUnhookBlockingHook, wsock32, 'WSAUnhookBlockingHook');
  1713. asm
  1714. MOV ESP, EBP
  1715. POP EBP
  1716. JMP [_WSAUnhookBlockingHook]
  1717. end;
  1718. end;
  1719. var
  1720. _WSASetBlockingHook: Pointer;
  1721. function WSASetBlockingHook;
  1722. begin
  1723. GetProcedureAddress(_WSASetBlockingHook, wsock32, 'WSASetBlockingHook');
  1724. asm
  1725. MOV ESP, EBP
  1726. POP EBP
  1727. JMP [_WSASetBlockingHook]
  1728. end;
  1729. end;
  1730. var
  1731. _WSACancelBlockingCall: Pointer;
  1732. function WSACancelBlockingCall;
  1733. begin
  1734. GetProcedureAddress(_WSACancelBlockingCall, wsock32, 'WSACancelBlockingCall');
  1735. asm
  1736. MOV ESP, EBP
  1737. POP EBP
  1738. JMP [_WSACancelBlockingCall]
  1739. end;
  1740. end;
  1741. var
  1742. _WSAAsyncGetServByName: Pointer;
  1743. function WSAAsyncGetServByName;
  1744. begin
  1745. GetProcedureAddress(_WSAAsyncGetServByName, wsock32, 'WSAAsyncGetServByName');
  1746. asm
  1747. MOV ESP, EBP
  1748. POP EBP
  1749. JMP [_WSAAsyncGetServByName]
  1750. end;
  1751. end;
  1752. var
  1753. _WSAAsyncGetServByPort: Pointer;
  1754. function WSAAsyncGetServByPort;
  1755. begin
  1756. GetProcedureAddress(_WSAAsyncGetServByPort, wsock32, 'WSAAsyncGetServByPort');
  1757. asm
  1758. MOV ESP, EBP
  1759. POP EBP
  1760. JMP [_WSAAsyncGetServByPort]
  1761. end;
  1762. end;
  1763. var
  1764. _WSAAsyncGetProtoByName: Pointer;
  1765. function WSAAsyncGetProtoByName;
  1766. begin
  1767. GetProcedureAddress(_WSAAsyncGetProtoByName, wsock32, 'WSAAsyncGetProtoByName');
  1768. asm
  1769. MOV ESP, EBP
  1770. POP EBP
  1771. JMP [_WSAAsyncGetProtoByName]
  1772. end;
  1773. end;
  1774. var
  1775. _WSAAsyncGetProtoByNumber: Pointer;
  1776. function WSAAsyncGetProtoByNumber;
  1777. begin
  1778. GetProcedureAddress(_WSAAsyncGetProtoByNumber, wsock32, 'WSAAsyncGetProtoByNumber');
  1779. asm
  1780. MOV ESP, EBP
  1781. POP EBP
  1782. JMP [_WSAAsyncGetProtoByNumber]
  1783. end;
  1784. end;
  1785. var
  1786. _WSAAsyncGetHostByName: Pointer;
  1787. function WSAAsyncGetHostByName;
  1788. begin
  1789. GetProcedureAddress(_WSAAsyncGetHostByName, wsock32, 'WSAAsyncGetHostByName');
  1790. asm
  1791. MOV ESP, EBP
  1792. POP EBP
  1793. JMP [_WSAAsyncGetHostByName]
  1794. end;
  1795. end;
  1796. var
  1797. _WSAAsyncGetHostByAddr: Pointer;
  1798. function WSAAsyncGetHostByAddr;
  1799. begin
  1800. GetProcedureAddress(_WSAAsyncGetHostByAddr, wsock32, 'WSAAsyncGetHostByAddr');
  1801. asm
  1802. MOV ESP, EBP
  1803. POP EBP
  1804. JMP [_WSAAsyncGetHostByAddr]
  1805. end;
  1806. end;
  1807. var
  1808. _WSACancelAsyncRequest: Pointer;
  1809. function WSACancelAsyncRequest;
  1810. begin
  1811. GetProcedureAddress(_WSACancelAsyncRequest, wsock32, 'WSACancelAsyncRequest');
  1812. asm
  1813. MOV ESP, EBP
  1814. POP EBP
  1815. JMP [_WSACancelAsyncRequest]
  1816. end;
  1817. end;
  1818. var
  1819. _WSAAsyncSelect: Pointer;
  1820. function WSAAsyncSelect;
  1821. begin
  1822. GetProcedureAddress(_WSAAsyncSelect, wsock32, 'WSAAsyncSelect');
  1823. asm
  1824. MOV ESP, EBP
  1825. POP EBP
  1826. JMP [_WSAAsyncSelect]
  1827. end;
  1828. end;
  1829. var
  1830. _WSARecvEx: Pointer;
  1831. function WSARecvEx;
  1832. begin
  1833. GetProcedureAddress(_WSARecvEx, wsock32, 'WSARecvEx');
  1834. asm
  1835. MOV ESP, EBP
  1836. POP EBP
  1837. JMP [_WSARecvEx]
  1838. end;
  1839. end;
  1840. var
  1841. _TransmitFile: Pointer;
  1842. function TransmitFile;
  1843. begin
  1844. GetProcedureAddress(_TransmitFile, wsock32, 'TransmitFile');
  1845. asm
  1846. MOV ESP, EBP
  1847. POP EBP
  1848. JMP [_TransmitFile]
  1849. end;
  1850. end;
  1851. var
  1852. _AcceptEx: Pointer;
  1853. function AcceptEx;
  1854. begin
  1855. GetProcedureAddress(_AcceptEx, wsock32, 'AcceptEx');
  1856. asm
  1857. MOV ESP, EBP
  1858. POP EBP
  1859. JMP [_AcceptEx]
  1860. end;
  1861. end;
  1862. var
  1863. _GetAcceptExSockaddrs: Pointer;
  1864. procedure GetAcceptExSockaddrs;
  1865. begin
  1866. GetProcedureAddress(_GetAcceptExSockaddrs, wsock32, 'GetAcceptExSockaddrs');
  1867. asm
  1868. MOV ESP, EBP
  1869. POP EBP
  1870. JMP [_GetAcceptExSockaddrs]
  1871. end;
  1872. end;
  1873. {$ELSE}
  1874. function __WSAFDIsSet; external wsock32 name '__WSAFDIsSet';
  1875. function accept; external wsock32 name 'accept';
  1876. function bind; external wsock32 name 'bind';
  1877. function closesocket; external wsock32 name 'closesocket';
  1878. function connect; external wsock32 name 'connect';
  1879. function ioctlsocket; external wsock32 name 'ioctlsocket';
  1880. function getpeername; external wsock32 name 'getpeername';
  1881. function getsockname; external wsock32 name 'getsockname';
  1882. function getsockopt; external wsock32 name 'getsockopt';
  1883. function htonl; external wsock32 name 'htonl';
  1884. function htons; external wsock32 name 'htons';
  1885. function inet_addr; external wsock32 name 'inet_addr';
  1886. function inet_ntoa; external wsock32 name 'inet_ntoa';
  1887. function listen; external wsock32 name 'listen';
  1888. function ntohl; external wsock32 name 'ntohl';
  1889. function ntohs; external wsock32 name 'ntohs';
  1890. function recv; external wsock32 name 'recv';
  1891. function recvfrom; external wsock32 name 'recvfrom';
  1892. function select; external wsock32 name 'select';
  1893. function send; external wsock32 name 'send';
  1894. function sendto; external wsock32 name 'sendto';
  1895. function setsockopt; external wsock32 name 'setsockopt';
  1896. function shutdown; external wsock32 name 'shutdown';
  1897. function socket; external wsock32 name 'socket';
  1898. function gethostbyaddr; external wsock32 name 'gethostbyaddr';
  1899. function gethostbyname; external wsock32 name 'gethostbyname';
  1900. function gethostname; external wsock32 name 'gethostname';
  1901. function getservbyport; external wsock32 name 'getservbyport';
  1902. function getservbyname; external wsock32 name 'getservbyname';
  1903. function getprotobynumber; external wsock32 name 'getprotobynumber';
  1904. function getprotobyname; external wsock32 name 'getprotobyname';
  1905. function WSAStartup; external wsock32 name 'WSAStartup';
  1906. function WSACleanup; external wsock32 name 'WSACleanup';
  1907. procedure WSASetLastError; external wsock32 name 'WSASetLastError';
  1908. function WSAGetLastError; external wsock32 name 'WSAGetLastError';
  1909. function WSAIsBlocking; external wsock32 name 'WSAIsBlocking';
  1910. function WSAUnhookBlockingHook; external wsock32 name 'WSAUnhookBlockingHook';
  1911. function WSASetBlockingHook; external wsock32 name 'WSASetBlockingHook';
  1912. function WSACancelBlockingCall; external wsock32 name 'WSACancelBlockingCall';
  1913. function WSAAsyncGetServByName; external wsock32 name 'WSAAsyncGetServByName';
  1914. function WSAAsyncGetServByPort; external wsock32 name 'WSAAsyncGetServByPort';
  1915. function WSAAsyncGetProtoByName; external wsock32 name 'WSAAsyncGetProtoByName';
  1916. function WSAAsyncGetProtoByNumber; external wsock32 name 'WSAAsyncGetProtoByNumber';
  1917. function WSAAsyncGetHostByName; external wsock32 name 'WSAAsyncGetHostByName';
  1918. function WSAAsyncGetHostByAddr; external wsock32 name 'WSAAsyncGetHostByAddr';
  1919. function WSACancelAsyncRequest; external wsock32 name 'WSACancelAsyncRequest';
  1920. function WSAAsyncSelect; external wsock32 name 'WSAAsyncSelect';
  1921. function WSARecvEx; external wsock32 name 'WSARecvEx';
  1922. function TransmitFile; external wsock32 name 'TransmitFile';
  1923. function AcceptEx; external wsock32 name 'AcceptEx';
  1924. procedure GetAcceptExSockaddrs; external wsock32 name 'GetAcceptExSockaddrs';
  1925. {$ENDIF DYNAMIC_LINK}
  1926. end.