pmwsock.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. {****************************************************************************
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyrigth (c) 2003 by Yuri Prokushev ([email protected])
  5. This file corresponds to version 1.1 of the Windows Sockets
  6. specification.
  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. unit pmwsock;
  14. Interface
  15. {$MACRO ON}
  16. Uses OS2Def;
  17. // The new type to be used in all instances which refer to sockets.
  18. type
  19. TSocket=Cardinal;
  20. // Select uses arrays of TSockets. These macros manipulate such
  21. // arrays. FD_SETSIZE may be defined by the user before including
  22. // this file, but the default here should be >= 64.
  23. //
  24. // CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  25. // INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  26. const
  27. FD_SETSIZE = 64;
  28. //#pragma pack(4)
  29. type
  30. fd_set=record
  31. fd_count: Word; // how many are SET?
  32. fd_array: Array[0..FD_SETSIZE-1] of TSocket; // an array of TSockets
  33. end;
  34. //#pragma pack()
  35. Function __WSAFDIsSet(a: TSocket;var b: fd_set): Longint; cdecl;
  36. external 'PMWSock' name '__WSAFDIsSet';
  37. Function FD_ISSET(a: TSocket;var b: fd_set): Longint; cdecl;
  38. external 'PMWSock' name '__WSAFDIsSet';
  39. Procedure FD_CLR(ASocket: TSocket; var aset: fd_set);
  40. Procedure FDSET(ASocket: TSocket; var FDSet: fd_set);
  41. // Structure used in select() call, taken from the BSD file sys/time.h.
  42. type
  43. timeval=record
  44. tv_sec: LongInt; // seconds
  45. tv_usec: LongInt; // and microseconds
  46. end;
  47. // Operations on timevals.
  48. // * NB: timercmp does not work for >= or <=.
  49. Function timerisset(tvp: timeval): Boolean;
  50. //Function timercmp(tvp, uvp, cmp);
  51. Procedure timerclear(var tvp: timeval);
  52. // Commands for ioctlsocket(), taken from the BSD file fcntl.h.
  53. //
  54. // Ioctl's have the command encoded in the lower word,
  55. // and the size of any in or out parameters in the upper
  56. // word. The high 2 bits of the upper word are used
  57. // to encode the in/out status of the parameter; for now
  58. // we restrict parameters to at most 128 bytes.
  59. const
  60. IOCPARM_MASK = $7f; // parameters must be < 128 bytes
  61. IOC_VOID = $20000000; // no parameters
  62. IOC_OUT = $40000000; // copy out parameters
  63. IOC_IN = $80000000; // copy in parameters
  64. IOC_INOUT = IOC_IN or IOC_OUT; // 0x20000000 distinguishes new &
  65. // old ioctl's
  66. {$define _IOR(x,y,t):=(IOC_OUT or ((Longint (sizeof(t)) and IOCPARM_MASK) shl 16) or (x shl 8) or y)}
  67. {$define _IOW(x,y,t):=(IOC_IN or ((Longint(sizeof(t)) and IOCPARM_MASK) shl 16) or (x shl 8) or y)}
  68. const
  69. // get # bytes to read
  70. FIONREAD=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 127);
  71. // set/clear non-blocking i/o
  72. FIONBIO=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 126);
  73. // set/clear async i/o
  74. FIOASYNC=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 125);
  75. // Socket I/O Controls
  76. const
  77. // set high watermark
  78. SIOCSHIWAT=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 0);
  79. // get high watermark
  80. SIOCGHIWAT=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 1);
  81. // set low watermark
  82. SIOCSLOWAT=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 2);
  83. // get low watermark
  84. SIOCGLOWAT=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 3);
  85. // at oob mark?
  86. SIOCATMARK=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 7);
  87. // Structures returned by network data base library, taken from the
  88. // BSD file netdb.h. All addresses are supplied in host order, and
  89. // returned in network order (suitable for use in system calls).
  90. type
  91. hostent=record
  92. h_name: PChar; // official name of host
  93. h_aliases: PPChar; // alias list
  94. h_addrtype: LongInt; // host address type
  95. h_length: LongInt; // length of address
  96. h_addr_list: PPChar; // list of addresses from name server
  97. {$define h_addr:=h_addr_list[0]} // address, for backward compatiblity
  98. end;
  99. phostent=^hostent;
  100. // It is assumed here that a network number
  101. // fits in 32 bits.
  102. type
  103. netent=record
  104. n_name: PChar; // official name of net
  105. n_aliases: PPChar; // alias list
  106. n_addrtype: Longint; // net address type
  107. n_net: Cardinal; // network #
  108. End;
  109. pnetent=^netent;
  110. servent=record
  111. s_name: PChar; // official service name
  112. s_aliases: PPChar; // alias list
  113. s_port: LongInt; // port #
  114. s_proto: PChar; // protocol to use
  115. end;
  116. pservent=^servent;
  117. protoent=record
  118. p_name: PChar; // official protocol name
  119. p_aliases: PPChar; // alias list
  120. p_proto: LongInt; // protocol #
  121. end;
  122. pprotoent=^protoent;
  123. // Constants and structures defined by the internet system,
  124. // Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  125. // Protocols
  126. const
  127. IPPROTO_IP =0; // dummy for IP
  128. IPPROTO_ICMP =1; // control message protocol
  129. IPPROTO_GGP =2; // gateway^2 (deprecated)
  130. IPPROTO_TCP =6; // tcp
  131. IPPROTO_PUP =12; // pup
  132. IPPROTO_UDP =17; // user datagram protocol
  133. IPPROTO_IDP =22; // xns idp
  134. IPPROTO_ND =77; // UNOFFICIAL net disk proto
  135. IPPROTO_RAW =255; // raw IP packet
  136. IPPROTO_MAX =256;
  137. // Port/socket numbers: network standard functions
  138. IPPORT_ECHO =7;
  139. IPPORT_DISCARD =9;
  140. IPPORT_SYSTAT =11;
  141. IPPORT_DAYTIME =13;
  142. IPPORT_NETSTAT =15;
  143. IPPORT_FTP =21;
  144. IPPORT_TELNET =23;
  145. IPPORT_SMTP =25;
  146. IPPORT_TIMESERVER =37;
  147. IPPORT_NAMESERVER =42;
  148. IPPORT_WHOIS =43;
  149. IPPORT_MTP =57;
  150. // Port/socket numbers: host specific functions
  151. IPPORT_TFTP =69;
  152. IPPORT_RJE =77;
  153. IPPORT_FINGER =79;
  154. IPPORT_TTYLINK =87;
  155. IPPORT_SUPDUP =95;
  156. // UNIX TCP sockets
  157. IPPORT_EXECSERVER =512;
  158. IPPORT_LOGINSERVER =513;
  159. IPPORT_CMDSERVER =514;
  160. IPPORT_EFSSERVER =520;
  161. // UNIX UDP sockets
  162. IPPORT_BIFFUDP =512;
  163. IPPORT_WHOSERVER =513;
  164. IPPORT_ROUTESERVER =520;
  165. // 520+1 also used
  166. // Ports < IPPORT_RESERVED are reserved for
  167. // privileged processes (e.g. root).
  168. IPPORT_RESERVED =1024;
  169. // Link numbers
  170. IMPLINK_IP =155;
  171. IMPLINK_LOWEXPER =156;
  172. IMPLINK_HIGHEXPER =158;
  173. // Internet address (old style... should be updated)
  174. type
  175. in_addr=record
  176. case Integer of
  177. 1:(S_un_b:record s_b1,s_b2,s_b3,s_b4: Byte; end;);
  178. 2:(s_un_w:record s_w1,s_w2: Word; end;);
  179. 3:(s_addr: Cardinal);
  180. end;
  181. {$define s_addr:=in_addr.S_addr} // can be used for most tcp & ip code
  182. {$define s_host:=in_addr.S_un_b.s_b2} // host on imp
  183. {$define s_net:=in_addr.S_un_b.s_b1} // network
  184. {$define s_imp:=in_addr.S_un_w.s_w2} // imp
  185. {$define s_impno:=in_addr.S_un_b.s_b4} // imp #
  186. {$define s_lh:=in_addr.S_un_b.s_b3} // logical host
  187. // Definitions of bits in internet address integers.
  188. // On subnets, the decomposition of addresses to host and net parts
  189. // is done according to subnet mask, not the masks here.
  190. const
  191. {$define IN_CLASSA(i):=((Longint(i) and $80000000) = 0)}
  192. IN_CLASSA_NET =$ff000000;
  193. IN_CLASSA_NSHIFT =24;
  194. IN_CLASSA_HOST =$00ffffff;
  195. IN_CLASSA_MAX =128;
  196. {$define IN_CLASSB(i):=((Longint(i) and $c0000000) = $80000000)}
  197. IN_CLASSB_NET =$ffff0000;
  198. IN_CLASSB_NSHIFT =16;
  199. IN_CLASSB_HOST =$0000ffff;
  200. IN_CLASSB_MAX =65536;
  201. {$define IN_CLASSC(i):=((Longint(i) and $e0000000) = $c0000000)}
  202. IN_CLASSC_NET =$ffffff00;
  203. IN_CLASSC_NSHIFT =8;
  204. IN_CLASSC_HOST =$000000ff;
  205. INADDR_ANY =$00000000;
  206. INADDR_LOOPBACK =$7f000001;
  207. INADDR_BROADCAST =$ffffffff;
  208. INADDR_NONE =$ffffffff;
  209. // Socket address, internet style.
  210. Type
  211. sockaddr_in=Record
  212. sin_family:Integer;
  213. sin_port:Word;
  214. sin_addr:in_addr;
  215. sin_zero:Array[0..7] of Char;
  216. End;
  217. const
  218. WSADESCRIPTION_LEN =256;
  219. WSASYS_STATUS_LEN =128;
  220. //#pragma pack(4)
  221. Type
  222. WSAData=Record
  223. wVersion:Word;
  224. wHighVersion:Word;
  225. szDescription: array[0..WSADESCRIPTION_LEN] of Char;
  226. szSystemStatus: array[0..WSASYS_STATUS_LEN] of Char;
  227. iMaxSockets:Word;
  228. iMaxUdpDg:Word;
  229. lpVendorInfo:PChar;
  230. End;
  231. PWSADATA=^WSAData;
  232. LPWSADATA=^WSAData;
  233. //#pragma pack()
  234. // Options for use with [gs]etsockopt at the IP level.
  235. Const
  236. IP_OPTIONS =1; // set/get IP per-packet options
  237. // Definitions related to sockets: types, address families, options,
  238. // taken from the BSD file sys/socket.h.
  239. // This is used instead of -1, since the
  240. // TSocket type is unsigned.
  241. Const
  242. INVALID_SOCKET = -1;
  243. SOCKET_ERROR = -1;
  244. // Types
  245. Const
  246. SOCK_STREAM =1; // stream socket
  247. SOCK_DGRAM =2; // datagram socket
  248. SOCK_RAW =3; // raw-protocol interface
  249. SOCK_RDM =4; // reliably-delivered message
  250. SOCK_SEQPACKET =5; // sequenced packet stream
  251. // Option flags per-socket.
  252. Const
  253. SO_DEBUG =$0001; // turn on debugging info recording
  254. SO_ACCEPTCONN =$0002; // socket has had listen()
  255. SO_REUSEADDR =$0004; // allow local address reuse
  256. SO_KEEPALIVE =$0008; // keep connections alive
  257. SO_DONTROUTE =$0010; // just use interface addresses
  258. SO_BROADCAST =$0020; // permit sending of broadcast msgs
  259. SO_USELOOPBACK =$0040; // bypass hardware when possible
  260. SO_LINGER =$0080; // linger on close if data present
  261. SO_OOBINLINE =$0100; // leave received OOB data in line
  262. SO_DONTLINGER =NOT SO_LINGER; // dont linger
  263. // Additional options.
  264. SO_SNDBUF =$1001; // send buffer size
  265. SO_RCVBUF =$1002; // receive buffer size
  266. SO_SNDLOWAT =$1003; // send low-water mark
  267. SO_RCVLOWAT =$1004; // receive low-water mark
  268. SO_SNDTIMEO =$1005; // send timeout
  269. SO_RCVTIMEO =$1006; // receive timeout
  270. SO_ERROR =$1007; // get error status and clear
  271. SO_TYPE =$1008; // get socket type
  272. // TCP options.
  273. Const
  274. TCP_NODELAY =$0001;
  275. // Address families.
  276. Const
  277. AF_UNSPEC =0; // unspecified
  278. AF_UNIX =1; // local to host (pipes, portals)
  279. AF_INET =2; // internetwork: UDP, TCP, etc.
  280. AF_IMPLINK =3; // arpanet imp addresses
  281. AF_PUP =4; // pup protocols: e.g. BSP
  282. AF_CHAOS =5; // mit CHAOS protocols
  283. AF_NS =6; // XEROX NS protocols
  284. AF_ISO =7; // ISO protocols
  285. AF_OSI =AF_ISO; // OSI is ISO
  286. AF_ECMA =8; // european computer manufacturers
  287. AF_DATAKIT =9; // datakit protocols
  288. AF_CCITT =10; // CCITT protocols, X.25 etc
  289. AF_SNA =11; // IBM SNA
  290. AF_DECnet =12; // DECnet
  291. AF_DLI =13; // Direct data link interface
  292. AF_LAT =14; // LAT
  293. AF_HYLINK =15; // NSC Hyperchannel
  294. AF_APPLETALK =16; // AppleTalk
  295. AF_NETBIOS =17; // NetBios-style addresses
  296. AF_MAX =18;
  297. // Structure used by kernel to store most
  298. // addresses.
  299. Type
  300. sockaddr=Record
  301. sa_family:Word; // address family
  302. sa_data:Array[0..13] of char; // up to 14 bytes of direct address
  303. End;
  304. // Structure used by kernel to pass protocol
  305. // information in raw sockets.
  306. sockproto=Record
  307. sp_family:Word; // address family
  308. sp_protocol:Word; // protocol
  309. End;
  310. // Protocol families, same as address families for now.
  311. Const
  312. PF_UNSPEC =AF_UNSPEC;
  313. PF_UNIX =AF_UNIX;
  314. PF_INET =AF_INET;
  315. PF_IMPLINK =AF_IMPLINK;
  316. PF_PUP =AF_PUP;
  317. PF_CHAOS =AF_CHAOS;
  318. PF_NS =AF_NS;
  319. PF_ISO =AF_ISO;
  320. PF_OSI =AF_OSI;
  321. PF_ECMA =AF_ECMA;
  322. PF_DATAKIT =AF_DATAKIT;
  323. PF_CCITT =AF_CCITT;
  324. PF_SNA =AF_SNA;
  325. PF_DECnet =AF_DECnet;
  326. PF_DLI =AF_DLI;
  327. PF_LAT =AF_LAT;
  328. PF_HYLINK =AF_HYLINK;
  329. PF_APPLETALK =AF_APPLETALK;
  330. PF_MAX =AF_MAX;
  331. // Structure used for manipulating linger option.
  332. Type
  333. linger=Record
  334. l_onoff:LongInt; // option on/off
  335. l_linger:LongInt; // linger time
  336. End;
  337. // Level number for (get/set)sockopt() to apply to socket itself.
  338. Const
  339. SOL_SOCKET =$ffff; // options for socket level
  340. // Maximum queue length specifiable by listen.
  341. SOMAXCONN =5;
  342. MSG_OOB =1; // process out-of-band data
  343. MSG_PEEK =2; // peek at incoming message
  344. MSG_DONTROUTE =4; // send without using routing tables
  345. MSG_MAXIOVLEN =16;
  346. // Define constant based on rfc883, used by gethostbyxxxx() calls.
  347. MAXGETHOSTSTRUCT =1024;
  348. // Define flags to be used with the WSAAsyncSelect() call.
  349. FD_READ =$01;
  350. FD_WRITE =$02;
  351. FD_OOB =$04;
  352. FD_ACCEPT =$08;
  353. FD_CONNECT =$10;
  354. FD_CLOSE =$20;
  355. // All Windows Sockets error constants are biased by WSABASEERR from
  356. // the "normal"
  357. WSABASEERR =10000;
  358. // Windows Sockets definitions of regular Microsoft C error constants
  359. WSAEINTR =(WSABASEERR+4);
  360. WSAEBADF =(WSABASEERR+9);
  361. WSAEACCES =(WSABASEERR+13);
  362. WSAEFAULT =(WSABASEERR+14);
  363. WSAEINVAL =(WSABASEERR+22);
  364. WSAEMFILE =(WSABASEERR+24);
  365. // Windows Sockets definitions of regular Berkeley error constants
  366. WSAEWOULDBLOCK =(WSABASEERR+35);
  367. WSAEINPROGRESS =(WSABASEERR+36);
  368. WSAEALREADY =(WSABASEERR+37);
  369. WSAENOTSOCK =(WSABASEERR+38);
  370. WSAEDESTADDRREQ =(WSABASEERR+39);
  371. WSAEMSGSIZE =(WSABASEERR+40);
  372. WSAEPROTOTYPE =(WSABASEERR+41);
  373. WSAENOPROTOOPT =(WSABASEERR+42);
  374. WSAEPROTONOSUPPORT =(WSABASEERR+43);
  375. WSAESOCKTNOSUPPORT =(WSABASEERR+44);
  376. WSAEOPNOTSUPP =(WSABASEERR+45);
  377. WSAEPFNOSUPPORT =(WSABASEERR+46);
  378. WSAEAFNOSUPPORT =(WSABASEERR+47);
  379. WSAEADDRINUSE =(WSABASEERR+48);
  380. WSAEADDRNOTAVAIL =(WSABASEERR+49);
  381. WSAENETDOWN =(WSABASEERR+50);
  382. WSAENETUNREACH =(WSABASEERR+51);
  383. WSAENETRESET =(WSABASEERR+52);
  384. WSAECONNABORTED =(WSABASEERR+53);
  385. WSAECONNRESET =(WSABASEERR+54);
  386. WSAENOBUFS =(WSABASEERR+55);
  387. WSAEISCONN =(WSABASEERR+56);
  388. WSAENOTCONN =(WSABASEERR+57);
  389. WSAESHUTDOWN =(WSABASEERR+58);
  390. WSAETOOMANYREFS =(WSABASEERR+59);
  391. WSAETIMEDOUT =(WSABASEERR+60);
  392. WSAECONNREFUSED =(WSABASEERR+61);
  393. WSAELOOP =(WSABASEERR+62);
  394. WSAENAMETOOLONG =(WSABASEERR+63);
  395. WSAEHOSTDOWN =(WSABASEERR+64);
  396. WSAEHOSTUNREACH =(WSABASEERR+65);
  397. WSAENOTEMPTY =(WSABASEERR+66);
  398. WSAEPROCLIM =(WSABASEERR+67);
  399. WSAEUSERS =(WSABASEERR+68);
  400. WSAEDQUOT =(WSABASEERR+69);
  401. WSAESTALE =(WSABASEERR+70);
  402. WSAEREMOTE =(WSABASEERR+71);
  403. // Extended Windows Sockets error constant definitions
  404. WSASYSNOTREADY =(WSABASEERR+91);
  405. WSAVERNOTSUPPORTED =(WSABASEERR+92);
  406. WSANOTINITIALISED =(WSABASEERR+93);
  407. // Error return codes from gethostbyname() and gethostbyaddr()
  408. // (when using the resolver). Note that these errors are
  409. // retrieved via WSAGetLastError() and must therefore follow
  410. // the rules for avoiding clashes with error numbers from
  411. // specific implementations or language run-time systems.
  412. // For this reason the codes are based at WSABASEERR+1001.
  413. // Note also that [WSA]NO_ADDRESS is defined only for
  414. // compatibility purposes.
  415. {$define h_errno:=WSAGetLastError()}
  416. // Authoritative Answer: Host not found
  417. WSAHOST_NOT_FOUND =(WSABASEERR+1001);
  418. HOST_NOT_FOUND =WSAHOST_NOT_FOUND;
  419. // Non-Authoritative: Host not found, or SERVERFAIL
  420. WSATRY_AGAIN =(WSABASEERR+1002);
  421. TRY_AGAIN =WSATRY_AGAIN;
  422. // Non recoverable errors, FORMERR, REFUSED, NOTIMP
  423. WSANO_RECOVERY =(WSABASEERR+1003);
  424. NO_RECOVERY =WSANO_RECOVERY;
  425. // Valid name, no data record of requested type
  426. WSANO_DATA =(WSABASEERR+1004);
  427. NO_DATA =WSANO_DATA;
  428. // no address, look for MX record
  429. WSANO_ADDRESS =WSANO_DATA;
  430. NO_ADDRESS =WSANO_ADDRESS;
  431. // Windows Sockets errors redefined as regular Berkeley error constants
  432. Const
  433. EWOULDBLOCK =WSAEWOULDBLOCK;
  434. EINPROGRESS =WSAEINPROGRESS;
  435. EALREADY =WSAEALREADY;
  436. ENOTSOCK =WSAENOTSOCK;
  437. EDESTADDRREQ =WSAEDESTADDRREQ;
  438. EMSGSIZE =WSAEMSGSIZE;
  439. EPROTOTYPE =WSAEPROTOTYPE;
  440. ENOPROTOOPT =WSAENOPROTOOPT;
  441. EPROTONOSUPPORT =WSAEPROTONOSUPPORT;
  442. ESOCKTNOSUPPORT =WSAESOCKTNOSUPPORT;
  443. EOPNOTSUPP =WSAEOPNOTSUPP;
  444. EPFNOSUPPORT =WSAEPFNOSUPPORT;
  445. EAFNOSUPPORT =WSAEAFNOSUPPORT;
  446. EADDRINUSE =WSAEADDRINUSE;
  447. EADDRNOTAVAIL =WSAEADDRNOTAVAIL;
  448. ENETDOWN =WSAENETDOWN;
  449. ENETUNREACH =WSAENETUNREACH;
  450. ENETRESET =WSAENETRESET;
  451. ECONNABORTED =WSAECONNABORTED;
  452. ECONNRESET =WSAECONNRESET;
  453. ENOBUFS =WSAENOBUFS;
  454. EISCONN =WSAEISCONN;
  455. ENOTCONN =WSAENOTCONN;
  456. ESHUTDOWN =WSAESHUTDOWN;
  457. ETOOMANYREFS =WSAETOOMANYREFS;
  458. ETIMEDOUT =WSAETIMEDOUT;
  459. ECONNREFUSED =WSAECONNREFUSED;
  460. ELOOP =WSAELOOP;
  461. ENAMETOOLONG =WSAENAMETOOLONG;
  462. EHOSTDOWN =WSAEHOSTDOWN;
  463. EHOSTUNREACH =WSAEHOSTUNREACH;
  464. ENOTEMPTY =WSAENOTEMPTY;
  465. EPROCLIM =WSAEPROCLIM;
  466. EUSERS =WSAEUSERS;
  467. EDQUOT =WSAEDQUOT;
  468. ESTALE =WSAESTALE;
  469. EREMOTE =WSAEREMOTE;
  470. // Socket function prototypes
  471. Function accept(s: TSocket; Var addr; Var addrlen: LongInt): TSocket; cdecl;
  472. external 'PMWSock' name 'accept';
  473. Function bind(s: TSocket; Const addr; namelen: LongInt): LongInt; cdecl;
  474. external 'PMWSock' name 'bind';
  475. Function closesocket(s: TSocket): LongInt; cdecl;
  476. external 'PMWSock' name 'closesocket';
  477. Function connect(s: TSocket; Const name: sockaddr; namelen: LongInt): LongInt; cdecl;
  478. external 'PMWSock' name 'connect';
  479. Function ioctlsocket(s: TSocket; cmd: LongInt; Var argp: Cardinal): LongInt; cdecl;
  480. external 'PMWSock' name 'ioctlsocket';
  481. Function getpeername(s: TSocket; Var name: sockaddr; Var nameLen: LongInt): LongInt; cdecl;
  482. external 'PMWSock' name 'getpeername';
  483. Function getsockname(s: TSocket;Var name: sockaddr; Var namelen: LongInt): LongInt; cdecl;
  484. external 'PMWSock' name 'getsockname';
  485. Function getsockopt(s: TSocket; level, optname: LongInt;Var optval; Var optlen: LongInt): LongInt; cdecl;
  486. external 'PMWSock' name 'getsockopt';
  487. Function htonl(hostlong: Cardinal): Cardinal; cdecl;
  488. external 'PMWSock' name 'htonl';
  489. Function htons(hostshort: Word): Word; cdecl;
  490. external 'PMWSock' name 'htons';
  491. Function inet_addr(Const cp: PChar): Cardinal; cdecl;
  492. external 'PMWSock' name 'inet_addr';
  493. Function inet_ntoa(Var _in: in_addr): PChar; cdecl;
  494. external 'PMWSock' name 'inet_ntoa';
  495. Function listen(s: TSocket; backlog: LongInt): LongInt; cdecl;
  496. external 'PMWSock' name 'listen';
  497. Function ntohl(netlong: Cardinal): Cardinal; cdecl;
  498. external 'PMWSock' name 'ntohl';
  499. Function ntohs(netshort: Word): Word; cdecl;
  500. external 'PMWSock' name 'ntohs';
  501. Function recv(s: TSocket;Var Buf; len, flags: LongInt): LongInt; cdecl;
  502. external 'PMWSock' name 'recv';
  503. Function recvfrom(s: TSocket; Var Buf: PChar; len, flags:LongInt;
  504. Var from: sockaddr; Var fromLen: LongInt): LongInt; cdecl;
  505. external 'PMWSock' name 'recvfrom';
  506. Function select(nfds: LongInt; Var readfds, writefds, exceptfds: fd_set;
  507. Const timeout: timeval): LongInt; cdecl;
  508. external 'PMWSock' name 'select';
  509. Function send(s: TSocket; Const Buf: PChar; len, flags: LongInt): LongInt; cdecl;
  510. external 'PMWSock' name 'send';
  511. Function sendto(s: TSocket; Const Buf: PChar; len, flags: LongInt;
  512. Const _to: sockaddr; tolen: LongInt): LongInt; cdecl;
  513. external 'PMWSock' name 'sendto';
  514. Function setsockopt(s: TSocket; level, optname: LongInt;
  515. Const optval: PChar; optlen: LongInt): LongInt; cdecl;
  516. external 'PMWSock' name 'setsockopt';
  517. Function shutdown(s: TSocket; how: LongInt): LongInt; cdecl;
  518. external 'PMWSock' name 'shutdown';
  519. Function socket(af, typ, protocol: LongInt): TSocket; cdecl;
  520. external 'PMWSock' name 'socket';
  521. // Database function prototypes
  522. Function gethostbyaddr(Var addr: PChar; len, typ: LongInt): phostent; cdecl;
  523. external 'PMWSock' name 'gethostbyaddr';
  524. Function gethostbyname(Const name: PChar): phostent; cdecl;
  525. external 'PMWSock' name 'gethostbyname';
  526. Function gethostname(Const name: PChar; namelen: LongInt): LongInt; cdecl;
  527. external 'PMWSock' name 'gethostname';
  528. Function getservbyport(port: LongInt;Const proto: PChar): pservent; cdecl;
  529. external 'PMWSock' name 'getservbyport';
  530. Function getservbyname(Const name, proto: PChar): pservent; cdecl;
  531. external 'PMWSock' name 'getservbyname';
  532. Function getprotobynumber(proto: LongInt): pprotoent; cdecl;
  533. external 'PMWSock' name 'getprotobynumber';
  534. Function getprotobyname(Const name: PChar): pprotoent; cdecl;
  535. external 'PMWSock' name 'getprotobyname';
  536. // Microsoft Windows Extension function prototypes
  537. Function WSAStartup(wVersionRequired: Word;Var aWSAData: WSAData): LongInt; cdecl;
  538. external 'PMWSock' name 'WSAStartup';
  539. Function WSACleanup: LongInt; cdecl;
  540. external 'PMWSock' name 'WSACleanup';
  541. Procedure WSASetLastError(iError: LongInt); cdecl;
  542. external 'PMWSock' name 'WSASetLastError';
  543. Function WSAGetLastError: LongInt; cdecl;
  544. external 'PMWSock' name 'WSAGetLastError';
  545. Function WSAIsBlocking: Longbool; cdecl;
  546. external 'PMWSock' name 'WSAIsBlocking';
  547. Function WSAUnhookBlockingHook: LongInt; cdecl;
  548. external 'PMWSock' name 'WSAUnhookBlockingHook';
  549. Function WSASetBlockingHook(lpBlockFunc: Pointer): Pointer; cdecl;
  550. external 'PMWSock' name 'WSASetBlockingHook';
  551. Function WSACancelBlockingCall: LongInt; cdecl;
  552. external 'PMWSock' name 'WSACancelBlockingCall';
  553. Function WSAAsyncGetServByName(ahWnd: HWND; wMsg: Cardinal;
  554. Const name, proto: PChar;
  555. Var Buf: PChar;
  556. buflen: LongInt): Cardinal; cdecl;
  557. external 'PMWSock' name 'WSAAsyncGetServByName';
  558. Function WSAAsyncGetServByPort(ahWnd: HWND; wMsg: Cardinal;
  559. port: LongInt;
  560. Const proto: PChar;
  561. Var Buf: PChar;
  562. buflen: LongInt): Cardinal; cdecl;
  563. external 'PMWSock' name 'WSAAsyncGetServByPort';
  564. Function WSAAsyncGetProtoByName(ahWnd: HWND; wMsg: Cardinal;
  565. Const name: PChar;
  566. Var Buf: PChar;
  567. buflen: LongInt): Cardinal; cdecl;
  568. external 'PMWSock' name 'WSAAsyncGetProtoByName';
  569. Function WSAAsyncGetProtoByNumber(ahWnd: HWND; wMsg: Cardinal;
  570. number:LongInt;
  571. Var Buf: PChar;
  572. buflen: LongInt): Cardinal; cdecl;
  573. external 'PMWSock' name 'WSAAsyncGetProtoByNumber';
  574. Function WSAAsyncGetHostByName(ahWnd: HWND; wMsg: Cardinal;
  575. Const name: PChar;
  576. Var Buf: PChar; buflen: LongInt): Cardinal; cdecl;
  577. external 'PMWSock' name 'WSAAsyncGetHostByName';
  578. Function WSAAsyncGetHostByAddr(ahWnd: HWND; wMsg: Cardinal;
  579. Const addr: PChar; len, typ: LongInt;
  580. Var Buf: PChar; buflen:LongInt): Cardinal; cdecl;
  581. external 'PMWSock' name 'WSAAsyncGetHostByAddr';
  582. Function WSACancelAsyncRequest(hAsyncTaskHandle: Cardinal): LongInt; cdecl;
  583. external 'PMWSock' name 'WSACancelAsyncRequest';
  584. Function WSAAsyncSelect(s: TSocket; ahWnd: HWND; wMsg: Cardinal; lEvent: LongInt): Cardinal; cdecl;
  585. external 'PMWSock' name 'WSAAsyncSelect';
  586. // Windows message parameter composition and decomposition
  587. // macros.
  588. //
  589. // WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  590. // when constructing the response to a WSAAsyncGetXByY() routine.
  591. (*
  592. #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
  593. /*
  594. * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  595. * when constructing the response to WSAAsyncSelect().
  596. */
  597. #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
  598. /*
  599. * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  600. * to extract the buffer length from the lParam in the response
  601. * to a WSAGetXByY().
  602. */
  603. #define WSAGETASYNCBUFLEN(lParam) LOUSHORT(lParam)
  604. /*
  605. * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  606. * to extract the error code from the lParam in the response
  607. * to a WSAGetXByY().
  608. */
  609. #define WSAGETASYNCERROR(lParam) HIUSHORT(lParam)
  610. /*
  611. * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  612. * to extract the event code from the lParam in the response
  613. * to a WSAAsyncSelect().
  614. */
  615. #define WSAGETSELECTEVENT(lParam) LOUSHORT(lParam)
  616. /*
  617. * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  618. * to extract the error code from the lParam in the response
  619. * to a WSAAsyncSelect().
  620. */
  621. #define WSAGETSELECTERROR(lParam) HIUSHORT(lParam)
  622. *)
  623. Procedure FD_ZERO(var aset: fd_set);
  624. Implementation
  625. Procedure FD_CLR(ASocket: TSocket; var aset: fd_set);
  626. var
  627. I: Cardinal;
  628. begin
  629. for I:=0 to aset.fd_count do
  630. begin
  631. if (aset.fd_array[i] = ASocket) then
  632. begin
  633. while (i < (aset.fd_count-1)) do
  634. begin
  635. aset.fd_array[I]:=aset.fd_array[i+1];
  636. Inc(I);
  637. end;
  638. Dec(aset.fd_count);
  639. break;
  640. end;
  641. end;
  642. end;
  643. Procedure FD_ZERO(var aset: fd_set);
  644. Begin
  645. aset.fd_count:=0;
  646. End;
  647. procedure FDSET(ASocket: TSocket; var FDSet: fd_set);
  648. begin
  649. if FDSet.fd_count < FD_SETSIZE then
  650. begin
  651. FDSet.fd_array[FDSet.fd_count] := ASocket;
  652. Inc(FDSet.fd_count);
  653. end;
  654. end;
  655. Function timerisset(tvp: timeval): Boolean;
  656. Begin
  657. TimerIsSet:=Boolean(tvp.tv_sec or tvp.tv_usec);
  658. End;
  659. (*
  660. Function timercmp(tvp, uvp, cmp): Boolean;
  661. Begin
  662. ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  663. (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  664. End;
  665. *)
  666. Procedure timerclear(var tvp: timeval);
  667. begin
  668. tvp.tv_sec:=0;
  669. tvp.tv_usec:=0;
  670. end;
  671. end.
  672. {
  673. $Log$
  674. Revision 1.1 2003-04-04 12:02:21 yuri
  675. + Initial import
  676. }