winsock.pp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. This unit contains the declarations for the Win32 Socket Library
  5. Copyright (c) 1999-2000 by Florian Klaempfl,
  6. member of the Free Pascal development team.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$PACKRECORDS 1}
  14. unit winsock;
  15. {$ifndef VER0_99_14}
  16. {$ifndef NO_SMART_LINK}
  17. {$define support_smartlink}
  18. {$endif}
  19. {$endif}
  20. {$ifdef support_smartlink}
  21. {$smartlink on}
  22. {$endif}
  23. interface
  24. uses
  25. windows;
  26. const
  27. {
  28. Default maximium number of sockets.
  29. this does not
  30. mean that the underlying Windows Sockets implementation has to
  31. support that many!
  32. }
  33. FD_SETSIZE = 64;
  34. type
  35. tOS_INT = LongInt;
  36. tOS_UINT = DWord;
  37. ptOS_INT = ^tOS_INT;
  38. ptOS_UINT = ^tOS_UINT;
  39. u_char = char;
  40. u_short = word;
  41. u_int = tOS_UINT;
  42. u_long = dword;
  43. pu_long = ^u_long;
  44. plongint = ^longint;
  45. TSocket = u_long;
  46. { there is already a procedure called FD_SET, so this
  47. record was renamed (FK) }
  48. fdset = record
  49. fd_count : u_int;
  50. fd_array : array[0..(FD_SETSIZE)-1] of TSocket;
  51. end;
  52. TFDSet = fdset;
  53. PFDSet = ^fdset;
  54. timeval = record
  55. tv_sec : longint;
  56. tv_usec : longint;
  57. end;
  58. TTimeVal = timeval;
  59. PTimeVal = ^TTimeVal;
  60. { found no reference to this type in c header files and here. AlexS }
  61. { minutes west of Greenwich }
  62. { type of dst correction }
  63. timezone = record
  64. tz_minuteswest : longint;
  65. tz_dsttime : longint;
  66. end;
  67. TTimeZone = timezone;
  68. PTimeZone = ^TTimeZone;
  69. const
  70. IOCPARM_MASK = $7f;
  71. IOC_VOID = $20000000;
  72. IOC_OUT = $40000000;
  73. IOC_IN = $80000000;
  74. IOC_INOUT = IOC_IN or IOC_OUT;
  75. FIONREAD = IOC_OUT or
  76. ((4 and IOCPARM_MASK) shl 16) or
  77. (102 shl 8) or 127;
  78. FIONBIO = IOC_IN or
  79. ((4 and IOCPARM_MASK) shl 16) or
  80. (102 shl 8) or 126;
  81. FIOASYNC = IOC_IN or
  82. ((4 and IOCPARM_MASK) shl 16) or
  83. (102 shl 8) or 125;
  84. {
  85. Structures returned by network data base library, taken from the
  86. BSD file netdb.h. All addresses are supplied in host order, and
  87. returned in network order (suitable for use in system calls).
  88. Slight modifications for differences between Linux and winsock.h
  89. }
  90. type
  91. hostent = record
  92. { official name of host }
  93. h_name: pchar;
  94. { alias list }
  95. h_aliases: ^pchar;
  96. { host address type }
  97. h_addrtype: SmallInt;
  98. { length of address }
  99. h_length: SmallInt;
  100. { list of addresses }
  101. case byte of
  102. 0: (h_addr_list: ^pchar);
  103. 1: (h_addr: ^pchar)
  104. end;
  105. THostEnt = hostent;
  106. PHostEnt = ^THostEnt;
  107. {
  108. Assumption here is that a network number
  109. fits in an unsigned long -- someday that won't be true!
  110. }
  111. netent = record
  112. { official name of net }
  113. n_name : ^char;
  114. { alias list }
  115. n_aliases : ^pchar;
  116. { net address type }
  117. n_addrtype : SmallInt;
  118. n_pad1 : SmallInt; { ensure right packaging }
  119. { network # }
  120. n_net : u_long;
  121. end;
  122. TNetEnt = netent;
  123. PNetEnt = ^TNetEnt;
  124. servent = record
  125. { official service name }
  126. s_name : ^char;
  127. { alias list }
  128. s_aliases : ^pchar;
  129. { port # }
  130. s_port : SmallInt;
  131. n_pad1 : SmallInt; { ensure right packaging }
  132. { protocol to use }
  133. s_proto : ^char;
  134. end;
  135. TServEnt = servent;
  136. PServEnt = ^TServEnt;
  137. protoent = record
  138. { official protocol name }
  139. p_name : ^char;
  140. { alias list }
  141. p_aliases : ^pchar;
  142. { protocol # }
  143. p_proto : SmallInt;
  144. p_pad1 : SmallInt; { ensure packaging }
  145. end;
  146. TProtoEnt = protoent;
  147. PProtoEnt = ^TProtoEnt;
  148. const
  149. {
  150. Standard well-known IP protocols.
  151. For some reason there are differences between Linx and winsock.h
  152. }
  153. IPPROTO_IP = 0;
  154. IPPROTO_ICMP = 1;
  155. IPPROTO_IGMP = 2;
  156. IPPROTO_GGP = 3;
  157. IPPROTO_TCP = 6;
  158. IPPORT_ECHO = 7;
  159. IPPORT_DISCARD = 9;
  160. IPPORT_SYSTAT = 11;
  161. IPPROTO_PUP = 12;
  162. IPPORT_DAYTIME = 13;
  163. IPPORT_NETSTAT = 15;
  164. IPPROTO_UDP = 17;
  165. IPPROTO_IDP = 22;
  166. IPPROTO_ND = 77;
  167. IPPROTO_RAW = 255;
  168. IPPROTO_MAX = 256;
  169. IPPORT_FTP = 21;
  170. IPPORT_TELNET = 23;
  171. IPPORT_SMTP = 25;
  172. IPPORT_TIMESERVER = 37;
  173. IPPORT_NAMESERVER = 42;
  174. IPPORT_WHOIS = 43;
  175. IPPORT_MTP = 57;
  176. IPPORT_TFTP = 69;
  177. IPPORT_RJE = 77;
  178. IPPORT_FINGER = 79;
  179. IPPORT_TTYLINK = 87;
  180. IPPORT_SUPDUP = 95;
  181. IPPORT_EXECSERVER = 512;
  182. IPPORT_LOGINSERVER = 513;
  183. IPPORT_CMDSERVER = 514;
  184. IPPORT_EFSSERVER = 520;
  185. IPPORT_BIFFUDP = 512;
  186. IPPORT_WHOSERVER = 513;
  187. IPPORT_ROUTESERVER = 520;
  188. IPPORT_RESERVED = 1024;
  189. const
  190. IMPLINK_IP = 155;
  191. IMPLINK_LOWEXPER = 156;
  192. IMPLINK_HIGHEXPER = 158;
  193. type
  194. SunB = packed record
  195. s_b1,s_b2,s_b3,s_b4 : u_char;
  196. end;
  197. SunW = packed record
  198. s_w1,s_w2 : u_short;
  199. end;
  200. in_addr = record
  201. case integer of
  202. 0 : (S_un_b : SunB);
  203. 1 : (S_un_w : SunW);
  204. 2 : (S_addr : u_long);
  205. end;
  206. TInAddr = in_addr;
  207. PInAddr = ^TInAddr;
  208. sockaddr_in = record
  209. case integer of
  210. 0 : ( (* equals to sockaddr_in, size is 16 byte *)
  211. sin_family : SmallInt; (* 2 byte *)
  212. sin_port : u_short; (* 2 byte *)
  213. sin_addr : TInAddr; (* 4 byte *)
  214. sin_zero : array[0..8-1] of char; (* 8 byte *)
  215. );
  216. 1 : ((* equals to sockaddr, size is 16 byte *)
  217. sa_family : Smallint; (* 2 byte *)
  218. sa_data : array[0..14-1] of char; (* 14 byte *)
  219. );
  220. end;
  221. TSockAddrIn = sockaddr_in;
  222. PSockAddrIn = ^TSockAddrIn;
  223. TSockAddr = sockaddr_in;
  224. PSockAddr = ^TSockAddr;
  225. const
  226. INADDR_ANY = $00000000;
  227. INADDR_LOOPBACK = $7F000001;
  228. INADDR_BROADCAST = $FFFFFFFF;
  229. IN_CLASSA_NET = $ff000000;
  230. IN_CLASSA_NSHIFT = 24;
  231. IN_CLASSA_HOST = $00ffffff;
  232. IN_CLASSA_MAX = 128;
  233. IN_CLASSB_NET = $ffff0000;
  234. IN_CLASSB_NSHIFT = 16;
  235. IN_CLASSB_HOST = $0000ffff;
  236. IN_CLASSB_MAX = 65536;
  237. IN_CLASSC_NET = $ffffff00;
  238. IN_CLASSC_NSHIFT = 8;
  239. IN_CLASSC_HOST = $000000ff;
  240. INADDR_NONE = $ffffffff;
  241. WSADESCRIPTION_LEN = 256;
  242. WSASYS_STATUS_LEN = 128;
  243. type
  244. WSADATA = record
  245. wVersion : WORD; { 2 byte, ofs 0 }
  246. wHighVersion : WORD; { 2 byte, ofs 2 }
  247. szDescription : array[0..(WSADESCRIPTION_LEN+1)-1] of char; { 257 byte, ofs 4 }
  248. szSystemStatus : array[0..(WSASYS_STATUS_LEN+1)-1] of char; { 129 byte, ofs 261 }
  249. iMaxSockets : word; { 2 byte, ofs 390 }
  250. iMaxUdpDg : word; { 2 byte, ofs 392 }
  251. pad1 : SmallInt; { 2 byte, ofs 394 } { ensure right packaging }
  252. lpVendorInfo : pchar; { 4 byte, ofs 396 }
  253. end; { total size 400 }
  254. TWSAData = WSADATA;
  255. PWSAData = TWSAData;
  256. const
  257. IP_OPTIONS = 1;
  258. IP_MULTICAST_IF = 2;
  259. IP_MULTICAST_TTL = 3;
  260. IP_MULTICAST_LOOP = 4;
  261. IP_ADD_MEMBERSHIP = 5;
  262. IP_DROP_MEMBERSHIP = 6;
  263. IP_DEFAULT_MULTICAST_TTL = 1;
  264. IP_DEFAULT_MULTICAST_LOOP = 1;
  265. IP_MAX_MEMBERSHIPS = 20;
  266. type
  267. ip_mreq = record
  268. imr_multiaddr : in_addr;
  269. imr_interface : in_addr;
  270. end;
  271. {
  272. Definitions related to sockets: types, address families, options,
  273. taken from the BSD file sys/socket.h.
  274. }
  275. const
  276. INVALID_SOCKET = longint(not(1));
  277. SOCKET_ERROR = -1;
  278. SOCK_STREAM = 1;
  279. SOCK_DGRAM = 2;
  280. SOCK_RAW = 3;
  281. SOCK_RDM = 4;
  282. SOCK_SEQPACKET = 5;
  283. { For setsockoptions(2) }
  284. SO_DEBUG = $0001;
  285. SO_ACCEPTCONN = $0002;
  286. SO_REUSEADDR = $0004;
  287. SO_KEEPALIVE = $0008;
  288. SO_DONTROUTE = $0010;
  289. SO_BROADCAST = $0020;
  290. SO_USELOOPBACK = $0040;
  291. SO_LINGER = $0080;
  292. SO_OOBINLINE = $0100;
  293. {
  294. Additional options.
  295. }
  296. { send buffer size }
  297. SO_SNDBUF = $1001;
  298. { receive buffer size }
  299. SO_RCVBUF = $1002;
  300. { send low-water mark }
  301. SO_SNDLOWAT = $1003;
  302. { receive low-water mark }
  303. SO_RCVLOWAT = $1004;
  304. { send timeout }
  305. SO_SNDTIMEO = $1005;
  306. { receive timeout }
  307. SO_RCVTIMEO = $1006;
  308. { get error status and clear }
  309. SO_ERROR = $1007;
  310. { get socket type }
  311. SO_TYPE = $1008;
  312. {
  313. Options for connect and disconnect data and options. Used only by
  314. non-TCP/IP transports such as DECNet, OSI TP4, etc.
  315. }
  316. SO_CONNDATA = $7000;
  317. SO_CONNOPT = $7001;
  318. SO_DISCDATA = $7002;
  319. SO_DISCOPT = $7003;
  320. SO_CONNDATALEN = $7004;
  321. SO_CONNOPTLEN = $7005;
  322. SO_DISCDATALEN = $7006;
  323. SO_DISCOPTLEN = $7007;
  324. {
  325. Option for opening sockets for synchronous access.
  326. }
  327. SO_OPENTYPE = $7008;
  328. SO_SYNCHRONOUS_ALERT = $10;
  329. SO_SYNCHRONOUS_NONALERT = $20;
  330. {
  331. Other NT-specific options.
  332. }
  333. SO_MAXDG = $7009;
  334. SO_MAXPATHDG = $700A;
  335. SO_UPDATE_ACCEPT_CONTEXT = $700B;
  336. SO_CONNECT_TIME = $700C;
  337. {
  338. TCP options.
  339. }
  340. TCP_NODELAY = $0001;
  341. TCP_BSDURGENT = $7000;
  342. {
  343. Address families.
  344. }
  345. { unspecified }
  346. AF_UNSPEC = 0;
  347. { local to host (pipes, portals) }
  348. AF_UNIX = 1;
  349. { internetwork: UDP, TCP, etc. }
  350. AF_INET = 2;
  351. { arpanet imp addresses }
  352. AF_IMPLINK = 3;
  353. { pup protocols: e.g. BSP }
  354. AF_PUP = 4;
  355. { mit CHAOS protocols }
  356. AF_CHAOS = 5;
  357. { IPX and SPX }
  358. AF_IPX = 6;
  359. { XEROX NS protocols }
  360. AF_NS = 6;
  361. { ISO protocols }
  362. AF_ISO = 7;
  363. { OSI is ISO }
  364. AF_OSI = AF_ISO;
  365. { european computer manufacturers }
  366. AF_ECMA = 8;
  367. { datakit protocols }
  368. AF_DATAKIT = 9;
  369. { CCITT protocols, X.25 etc }
  370. AF_CCITT = 10;
  371. { IBM SNA }
  372. AF_SNA = 11;
  373. { DECnet }
  374. AF_DECnet = 12;
  375. { Direct data link interface }
  376. AF_DLI = 13;
  377. { LAT }
  378. AF_LAT = 14;
  379. { NSC Hyperchannel }
  380. AF_HYLINK = 15;
  381. { AppleTalk }
  382. AF_APPLETALK = 16;
  383. { NetBios-style addresses }
  384. AF_NETBIOS = 17;
  385. { VoiceView }
  386. AF_VOICEVIEW = 18;
  387. { FireFox }
  388. AF_FIREFOX = 19;
  389. { Somebody is using this! }
  390. AF_UNKNOWN1 = 20;
  391. { Banyan }
  392. AF_BAN = 21;
  393. AF_MAX = 22;
  394. type
  395. {
  396. Structure used by kernel to pass protocol
  397. information in raw sockets.
  398. }
  399. sockproto = record
  400. sp_family : u_short;
  401. sp_protocol : u_short;
  402. end;
  403. TSockProto = sockproto;
  404. PSockProto = ^TSockProto;
  405. const
  406. {
  407. Protocol families, same as address families for now.
  408. }
  409. PF_UNSPEC = AF_UNSPEC;
  410. PF_UNIX = AF_UNIX;
  411. PF_INET = AF_INET;
  412. PF_IMPLINK = AF_IMPLINK;
  413. PF_PUP = AF_PUP;
  414. PF_CHAOS = AF_CHAOS;
  415. PF_NS = AF_NS;
  416. PF_IPX = AF_IPX;
  417. PF_ISO = AF_ISO;
  418. PF_OSI = AF_OSI;
  419. PF_ECMA = AF_ECMA;
  420. PF_DATAKIT = AF_DATAKIT;
  421. PF_CCITT = AF_CCITT;
  422. PF_SNA = AF_SNA;
  423. PF_DECnet = AF_DECnet;
  424. PF_DLI = AF_DLI;
  425. PF_LAT = AF_LAT;
  426. PF_HYLINK = AF_HYLINK;
  427. PF_APPLETALK = AF_APPLETALK;
  428. PF_VOICEVIEW = AF_VOICEVIEW;
  429. PF_FIREFOX = AF_FIREFOX;
  430. PF_UNKNOWN1 = AF_UNKNOWN1;
  431. PF_BAN = AF_BAN;
  432. PF_MAX = AF_MAX;
  433. type
  434. {
  435. Structure used for manipulating linger option.
  436. }
  437. linger = record
  438. l_onoff : u_short;
  439. l_linger : u_short;
  440. end;
  441. TLinger = linger;
  442. PLinger = ^TLinger;
  443. const
  444. {
  445. Level number for (get/set)sockopt() to apply to socket itself.
  446. }
  447. { options for socket level }
  448. SOL_SOCKET = $ffff;
  449. {
  450. Maximum queue length specifiable by listen.
  451. }
  452. SOMAXCONN = 5;
  453. { process out-of-band data }
  454. MSG_OOB = $1;
  455. { peek at incoming message }
  456. MSG_PEEK = $2;
  457. { send without using routing tables }
  458. MSG_DONTROUTE = $4;
  459. MSG_MAXIOVLEN = 16;
  460. { partial send or recv for message xport }
  461. MSG_PARTIAL = $8000;
  462. {
  463. Define constant based on rfc883, used by gethostbyxxxx() calls.
  464. }
  465. MAXGETHOSTSTRUCT = 1024;
  466. MAXHOSTNAMELEN = MAXGETHOSTSTRUCT;
  467. {
  468. Define flags to be used with the WSAAsyncSelect() call.
  469. }
  470. FD_READ = $01;
  471. FD_WRITE = $02;
  472. FD_OOB = $04;
  473. FD_ACCEPT = $08;
  474. FD_CONNECT = $10;
  475. FD_CLOSE = $20;
  476. {
  477. All Windows Sockets error constants are biased by WSABASEERR from
  478. the "normal"
  479. }
  480. WSABASEERR = 10000;
  481. {
  482. Windows Sockets definitions of regular Microsoft C error constants
  483. }
  484. WSAEINTR = WSABASEERR + 4;
  485. WSAEBADF = WSABASEERR + 9;
  486. WSAEACCES = WSABASEERR + 13;
  487. WSAEFAULT = WSABASEERR + 14;
  488. WSAEINVAL = WSABASEERR + 22;
  489. WSAEMFILE = WSABASEERR + 24;
  490. {
  491. Windows Sockets definitions of regular Berkeley error constants
  492. }
  493. WSAEWOULDBLOCK = WSABASEERR + 35;
  494. WSAEINPROGRESS = WSABASEERR + 36;
  495. WSAEALREADY = WSABASEERR + 37;
  496. WSAENOTSOCK = WSABASEERR + 38;
  497. WSAEDESTADDRREQ = WSABASEERR + 39;
  498. WSAEMSGSIZE = WSABASEERR + 40;
  499. WSAEPROTOTYPE = WSABASEERR + 41;
  500. WSAENOPROTOOPT = WSABASEERR + 42;
  501. WSAEPROTONOSUPPORT = WSABASEERR + 43;
  502. WSAESOCKTNOSUPPORT = WSABASEERR + 44;
  503. WSAEOPNOTSUPP = WSABASEERR + 45;
  504. WSAEPFNOSUPPORT = WSABASEERR + 46;
  505. WSAEAFNOSUPPORT = WSABASEERR + 47;
  506. WSAEADDRINUSE = WSABASEERR + 48;
  507. WSAEADDRNOTAVAIL = WSABASEERR + 49;
  508. WSAENETDOWN = WSABASEERR + 50;
  509. WSAENETUNREACH = WSABASEERR + 51;
  510. WSAENETRESET = WSABASEERR + 52;
  511. WSAECONNABORTED = WSABASEERR + 53;
  512. WSAECONNRESET = WSABASEERR + 54;
  513. WSAENOBUFS = WSABASEERR + 55;
  514. WSAEISCONN = WSABASEERR + 56;
  515. WSAENOTCONN = WSABASEERR + 57;
  516. WSAESHUTDOWN = WSABASEERR + 58;
  517. WSAETOOMANYREFS = WSABASEERR + 59;
  518. WSAETIMEDOUT = WSABASEERR + 60;
  519. WSAECONNREFUSED = WSABASEERR + 61;
  520. WSAELOOP = WSABASEERR + 62;
  521. WSAENAMETOOLONG = WSABASEERR + 63;
  522. WSAEHOSTDOWN = WSABASEERR + 64;
  523. WSAEHOSTUNREACH = WSABASEERR + 65;
  524. WSAENOTEMPTY = WSABASEERR + 66;
  525. WSAEPROCLIM = WSABASEERR + 67;
  526. WSAEUSERS = WSABASEERR + 68;
  527. WSAEDQUOT = WSABASEERR + 69;
  528. WSAESTALE = WSABASEERR + 70;
  529. WSAEREMOTE = WSABASEERR + 71;
  530. WSAEDISCON = WSABASEERR + 101;
  531. {
  532. Extended Windows Sockets error constant definitions
  533. }
  534. WSASYSNOTREADY = WSABASEERR + 91;
  535. WSAVERNOTSUPPORTED = WSABASEERR + 92;
  536. WSANOTINITIALISED = WSABASEERR + 93;
  537. {
  538. Error return codes from gethostbyname() and gethostbyaddr()
  539. (when using the resolver). Note that these errors are
  540. retrieved via WSAGetLastError() and must therefore follow
  541. the rules for avoiding clashes with error numbers from
  542. specific implementations or language run-time systems.
  543. For this reason the codes are based at WSABASEERR+1001.
  544. Note also that [WSA]NO_ADDRESS is defined only for
  545. compatibility purposes.
  546. }
  547. WSAHOST_NOT_FOUND = WSABASEERR + 1001;
  548. HOST_NOT_FOUND = WSAHOST_NOT_FOUND;
  549. { Non-Authoritative: Host not found, or SERVERFAIL }
  550. WSATRY_AGAIN = WSABASEERR + 1002;
  551. TRY_AGAIN = WSATRY_AGAIN;
  552. { Non recoverable errors, FORMERR, REFUSED, NOTIMP }
  553. WSANO_RECOVERY = WSABASEERR + 1003;
  554. NO_RECOVERY = WSANO_RECOVERY;
  555. { Valid name, no data record of requested type }
  556. WSANO_DATA = WSABASEERR + 1004;
  557. NO_DATA = WSANO_DATA;
  558. { no address, look for MX record }
  559. WSANO_ADDRESS = WSANO_DATA;
  560. NO_ADDRESS = WSANO_ADDRESS;
  561. const
  562. {
  563. Windows Sockets errors redefined as regular Berkeley error constants.
  564. }
  565. EWOULDBLOCK = WSAEWOULDBLOCK;
  566. EINPROGRESS = WSAEINPROGRESS;
  567. EALREADY = WSAEALREADY;
  568. ENOTSOCK = WSAENOTSOCK;
  569. EDESTADDRREQ = WSAEDESTADDRREQ;
  570. EMSGSIZE = WSAEMSGSIZE;
  571. EPROTOTYPE = WSAEPROTOTYPE;
  572. ENOPROTOOPT = WSAENOPROTOOPT;
  573. EPROTONOSUPPORT = WSAEPROTONOSUPPORT;
  574. ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT;
  575. EOPNOTSUPP = WSAEOPNOTSUPP;
  576. EPFNOSUPPORT = WSAEPFNOSUPPORT;
  577. EAFNOSUPPORT = WSAEAFNOSUPPORT;
  578. EADDRINUSE = WSAEADDRINUSE;
  579. EADDRNOTAVAIL = WSAEADDRNOTAVAIL;
  580. ENETDOWN = WSAENETDOWN;
  581. ENETUNREACH = WSAENETUNREACH;
  582. ENETRESET = WSAENETRESET;
  583. ECONNABORTED = WSAECONNABORTED;
  584. ECONNRESET = WSAECONNRESET;
  585. ENOBUFS = WSAENOBUFS;
  586. EISCONN = WSAEISCONN;
  587. ENOTCONN = WSAENOTCONN;
  588. ESHUTDOWN = WSAESHUTDOWN;
  589. ETOOMANYREFS = WSAETOOMANYREFS;
  590. ETIMEDOUT = WSAETIMEDOUT;
  591. ECONNREFUSED = WSAECONNREFUSED;
  592. ELOOP = WSAELOOP;
  593. ENAMETOOLONG = WSAENAMETOOLONG;
  594. EHOSTDOWN = WSAEHOSTDOWN;
  595. EHOSTUNREACH = WSAEHOSTUNREACH;
  596. ENOTEMPTY = WSAENOTEMPTY;
  597. EPROCLIM = WSAEPROCLIM;
  598. EUSERS = WSAEUSERS;
  599. EDQUOT = WSAEDQUOT;
  600. ESTALE = WSAESTALE;
  601. EREMOTE = WSAEREMOTE;
  602. TF_DISCONNECT = $01;
  603. TF_REUSE_SOCKET = $02;
  604. TF_WRITE_BEHIND = $04;
  605. {
  606. Options for use with [gs]etsockopt at the IP level.
  607. }
  608. IP_TTL = 7;
  609. IP_TOS = 8;
  610. IP_DONTFRAGMENT = 9;
  611. type
  612. _TRANSMIT_FILE_BUFFERS = record
  613. Head : Pointer;
  614. HeadLength : dword;
  615. Tail : Pointer;
  616. TailLength : dword;
  617. end;
  618. TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS;
  619. TTransmitFileBuffers = _TRANSMIT_FILE_BUFFERS;
  620. PTransmitFileBuffers = ^TTransmitFileBuffers;
  621. { Socket function prototypes }
  622. const
  623. winsockdll = 'wsock32.dll';
  624. function accept(s:TSocket; addr: PSockAddr; addrlen : ptOS_INT) : TSocket;stdcall;external winsockdll name 'accept';
  625. function accept(s:TSocket; addr: PSockAddr; var addrlen : tOS_INT) : TSocket;stdcall;external winsockdll name 'accept';
  626. function bind(s:TSocket; addr: PSockaddr;namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'bind';
  627. function bind(s:TSocket; const addr: TSockaddr;namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'bind';
  628. function closesocket(s:TSocket):tOS_INT;stdcall;external winsockdll name 'closesocket';
  629. function connect(s:TSocket; addr:PSockAddr; namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'connect';
  630. function connect(s:TSocket; Const name:TSockAddr; namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'connect';
  631. function ioctlsocket(s:TSocket; cmd:longint; var arg:u_long):tOS_INT;stdcall;external winsockdll name 'ioctlsocket'; { really a c-long }
  632. function ioctlsocket(s:TSocket; cmd:longint; var arg:longint):tOS_INT;stdcall;external winsockdll name 'ioctlsocket'; { really a c-long }
  633. function ioctlsocket(s:TSocket; cmd:longint; argp:pu_long):tOS_INT;stdcall;external winsockdll name 'ioctlsocket'; { really a c-long }
  634. function getpeername(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;stdcall;
  635. external winsockdll name 'getpeername';
  636. function getsockname(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;stdcall;
  637. external winsockdll name 'getsockname';
  638. function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pchar;var optlen:tOS_INT):tOS_INT;stdcall;
  639. external winsockdll name 'getsockopt';
  640. function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;var optval;var optlen:tOS_INT):tOS_INT;stdcall;
  641. external winsockdll name 'getsockopt';
  642. function htonl(hostlong:u_long):u_long;stdcall;external winsockdll name 'htonl';
  643. function htons(hostshort:u_short):u_short;external winsockdll name 'htons';
  644. function inet_addr(cp:pchar):cardinal;stdcall;external winsockdll name 'inet_addr';
  645. function inet_ntoa(i : TInAddr):pchar;stdcall;external winsockdll name 'inet_ntoa';
  646. function listen(s:TSocket; backlog:tOS_INT):tOS_INT;stdcall;external winsockdll name 'listen';
  647. function ntohl(netlong:u_long):u_long;stdcall;external winsockdll name 'ntohl';
  648. function ntohs(netshort:u_short):u_short;stdcall;external winsockdll name 'ntohs';
  649. function recv(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall;external winsockdll name 'recv';
  650. function recv(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall;external winsockdll name 'recv';
  651. function recvfrom(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT;stdcall;
  652. external winsockdll name 'recvfrom';
  653. function recvfrom(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT;Const from:TSockAddr; var fromlen:tOS_INT):tOS_INT;stdcall;
  654. external winsockdll name 'recvfrom';
  655. function select(nfds:tOS_INT; readfds,writefds,exceptfds : PFDSet;timeout: PTimeVal):tOS_INT;stdcall;
  656. external winsockdll name 'select';
  657. function send(s:TSocket;Const buf; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall;
  658. external winsockdll name 'send';
  659. function sendto(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT;stdcall;
  660. external winsockdll name 'sendto';
  661. function sendto(s:TSocket; Const buf; len:tOS_INT; flags:tOS_INT;Const toaddr:TSockAddr; tolen:tOS_INT):tOS_INT;stdcall;
  662. external winsockdll name 'sendto';
  663. function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pchar; optlen:tOS_INT):tOS_INT;stdcall;
  664. external winsockdll name 'setsockopt';
  665. function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; Const optval; optlen:tOS_INT):tOS_INT;stdcall;
  666. external winsockdll name 'setsockopt';
  667. function shutdown(s:TSocket; how:tOS_INT):tOS_INT;stdcall;
  668. external winsockdll name 'shutdown';
  669. function socket(af:tOS_INT; t:tOS_INT; protocol:tOS_INT):TSocket;stdcall;
  670. external winsockdll name 'socket';
  671. { Database function prototypes }
  672. function gethostbyaddr(addr:pchar; len:tOS_INT; t:tOS_INT): PHostEnt;stdcall;external winsockdll name 'gethostbyaddr';
  673. function gethostbyname(name:pchar):PHostEnt;stdcall;external winsockdll name 'gethostbyname';
  674. function gethostname(name:pchar; namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'gethostname';
  675. function getservbyport(port:tOS_INT; proto:pchar):PServEnt;stdcall;external winsockdll name 'getservbyport';
  676. function getservbyname(name:pchar; proto:pchar):PServEnt;stdcall;external winsockdll name 'getservbyname';
  677. function getprotobynumber(proto:tOS_INT):PProtoEnt;stdcall;external winsockdll name 'getprotobynumber';
  678. function getprotobyname(name:pchar):PProtoEnt;stdcall;external winsockdll name 'getprotobyname';
  679. { Microsoft Windows Extension function prototypes }
  680. function WSAStartup(wVersionRequired:word;var WSAData:TWSADATA):tOS_INT;stdcall;
  681. external winsockdll name 'WSAStartup';
  682. function WSACleanup:tOS_INT;stdcall;external winsockdll name 'WSACleanup';
  683. procedure WSASetLastError(iError:tOS_INT);stdcall;external winsockdll name 'WSASetLastError';
  684. function WSAGetLastError:tOS_INT;stdcall;external winsockdll name 'WSAGetLastError';
  685. function WSAIsBlocking:BOOL;stdcall;external winsockdll name 'WSAIsBlocking';
  686. function WSAUnhookBlockingHook:tOS_INT;stdcall;external winsockdll name 'WSAUnhookBlockingHook';
  687. function WSASetBlockingHook(lpBlockFunc:TFarProc):TFarProc;stdcall;external winsockdll name 'WSASetBlockingHook';
  688. function WSACancelBlockingCall:tOS_INT;stdcall;external winsockdll name 'WSACancelBlockingCall';
  689. function WSAAsyncGetServByName(hWnd:HWND; wMsg:u_int; name:pchar; proto:pchar; buf:pchar;
  690. buflen:tOS_INT):THandle;stdcall;external winsockdll name 'WSAAsyncGetServByName';
  691. function WSAAsyncGetServByPort(hWnd:HWND; wMsg:u_int; port:tOS_INT; proto:pchar; buf:pchar;
  692. buflen:tOS_INT):THandle;stdcall;external winsockdll name 'WSAAsyncGetServByPort';
  693. function WSAAsyncGetProtoByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;stdcall;
  694. external winsockdll name 'WSAAsyncGetProtoByName';
  695. function WSAAsyncGetProtoByNumber(hWnd:HWND; wMsg:u_int; number:tOS_INT; buf:pchar; buflen:tOS_INT):THandle;stdcall;
  696. external winsockdll name 'WSAAsyncGetProtoByNumber';
  697. function WSAAsyncGetHostByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;stdcall;
  698. external winsockdll name 'WSAAsyncGetHostByName';
  699. function WSAAsyncGetHostByAddr(hWnd:HWND; wMsg:u_int; addr:pchar; len:tOS_INT; t:tOS_INT;
  700. buf:pchar; buflen:tOS_INT):THandle;stdcall;
  701. external winsockdll name 'WSAAsyncGetHostByAddr';
  702. function WSACancelAsyncRequest(hAsyncTaskHandle:THandle):tOS_INT;stdcall;
  703. external winsockdll name 'WSACancelAsyncRequest';
  704. function WSAAsyncSelect(s:TSocket; hWnd:HWND; wMsg:u_int; lEvent:longint):tOS_INT;stdcall; { really a c-long }
  705. external winsockdll name 'WSAAsyncSelect';
  706. function WSARecvEx(s:TSocket;var buf; len:tOS_INT; flags:ptOS_INT):tOS_INT;stdcall;
  707. external winsockdll name 'WSARecvEx';
  708. function __WSAFDIsSet(s:TSocket; var FDSet:TFDSet):Bool;stdcall;
  709. external winsockdll name '__WSAFDIsSet';
  710. function __WSAFDIsSet_(s:TSocket; var FDSet:TFDSet):tOS_INT;stdcall;
  711. external winsockdll name '__WSAFDIsSet';
  712. function TransmitFile(hSocket:TSocket; hFile:THandle; nNumberOfBytesToWrite:dword;
  713. nNumberOfBytesPerSend:DWORD; lpOverlapped:POverlapped;
  714. lpTransmitBuffers:PTransmitFileBuffers; dwReserved:dword):Bool;stdcall;
  715. external winsockdll name 'TransmitFile';
  716. function AcceptEx(sListenSocket,sAcceptSocket:TSocket;
  717. lpOutputBuffer:Pointer; dwReceiveDataLength,dwLocalAddressLength,
  718. dwRemoteAddressLength:dword; var lpdwBytesReceived:dword;
  719. lpOverlapped:POverlapped):Bool;stdcall;
  720. external winsockdll name 'AcceptEx';
  721. procedure GetAcceptExSockaddrs(lpOutputBuffer:Pointer;
  722. dwReceiveDataLength,dwLocalAddressLength,dwRemoteAddressLength:dword;
  723. var LocalSockaddr:TSockAddr; var LocalSockaddrLength:tOS_INT;
  724. var RemoteSockaddr:TSockAddr; var RemoteSockaddrLength:tOS_INT);stdcall;
  725. external winsockdll name 'GetAcceptExSockaddrs';
  726. function WSAMakeSyncReply(Buflen,Error:Word):dword;
  727. function WSAMakeSelectReply(Event,Error:Word):dword;
  728. function WSAGetAsyncBuflen(Param:dword):Word;
  729. function WSAGetAsyncError(Param:dword):Word;
  730. function WSAGetSelectEvent(Param:dword):Word;
  731. function WSAGetSelectError(Param:dword):Word;
  732. procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet);
  733. function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean;
  734. procedure FD_SET(Socket:TSocket; var FDSet:TFDSet);
  735. procedure FD_ZERO(var FDSet:TFDSet);
  736. implementation
  737. {
  738. Implementation of the helper routines
  739. }
  740. function WSAMakeSyncReply(Buflen,Error:Word):dword;
  741. begin
  742. WSAMakeSyncReply:=MakeLong(Buflen, Error);
  743. end;
  744. function WSAMakeSelectReply(Event,Error:Word):dword;
  745. begin
  746. WSAMakeSelectReply:=MakeLong(Event,Error);
  747. end;
  748. function WSAGetAsyncBuflen(Param:dword):Word;
  749. begin
  750. WSAGetAsyncBuflen:=lo(Param);
  751. end;
  752. function WSAGetAsyncError(Param:dword):Word;
  753. begin
  754. WSAGetAsyncError:=hi(Param);
  755. end;
  756. function WSAGetSelectEvent(Param:dword):Word;
  757. begin
  758. WSAGetSelectEvent:=lo(Param);
  759. end;
  760. function WSAGetSelectError(Param:dword):Word;
  761. begin
  762. WSAGetSelectError:=hi(Param);
  763. end;
  764. procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet);
  765. var
  766. i : u_int;
  767. begin
  768. i:=0;
  769. while i<FDSet.fd_count do
  770. begin
  771. if FDSet.fd_array[i]=Socket then
  772. begin
  773. while i<FDSet.fd_count-1 do
  774. begin
  775. FDSet.fd_array[i]:=FDSet.fd_array[i+1];
  776. inc(i);
  777. end;
  778. dec(FDSet.fd_count);
  779. break;
  780. end;
  781. inc(i);
  782. end;
  783. end;
  784. function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean;
  785. begin
  786. FD_ISSET:=__WSAFDIsSet(Socket,FDSet);
  787. end;
  788. procedure FD_SET(Socket:TSocket; var FDSet:TFDSet);
  789. begin
  790. if FDSet.fd_count<FD_SETSIZE then
  791. begin
  792. FDSet.fd_array[FDSet.fd_count]:=Socket;
  793. Inc(FDSet.fd_count);
  794. end;
  795. end;
  796. procedure FD_ZERO(var FDSet:TFDSet);
  797. begin
  798. FDSet.fd_count:=0;
  799. end;
  800. end.
  801. {
  802. $Log$
  803. Revision 1.12 2003-01-01 14:34:22 peter
  804. * sendto overload
  805. Revision 1.11 2002/12/25 01:04:03 peter
  806. * sendto overload added
  807. Revision 1.10 2002/09/07 21:28:10 carl
  808. - removed os_types
  809. * fix range check errors
  810. Revision 1.9 2002/09/07 16:01:29 peter
  811. * old logs removed and tabs fixed
  812. Revision 1.8 2002/08/12 14:18:53 florian
  813. * ioctlselect overloaded to take a longint is second parameter
  814. Revision 1.7 2002/01/19 11:58:20 peter
  815. * more functions from webbugs
  816. }