jwawinsock.pas 57 KB

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