cnetdb.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. unit cNetDB;
  2. {*-
  3. * Copyright (c) 1980, 1983, 1988, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed by the University of
  17. * California, Berkeley and its contributors.
  18. * 4. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * -
  35. * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  36. *
  37. * Permission to use, copy, modify, and distribute this software for any
  38. * purpose with or without fee is hereby granted, provided that the above
  39. * copyright notice and this permission notice appear in all copies, and that
  40. * the name of Digital Equipment Corporation not be used in advertising or
  41. * publicity pertaining to distribution of the document or software without
  42. * specific, written prior permission.
  43. *
  44. * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  45. * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  46. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  47. * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  48. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  49. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  50. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  51. * SOFTWARE.
  52. * -
  53. * --Copyright--
  54. *}
  55. {*
  56. * @(#)netdb.h 8.1 (Berkeley) 6/2/93
  57. * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
  58. * $FreeBSD: src/include/netdb.h,v 1.38.2.1 2005/07/22 20:17:30 ume Exp $
  59. *}
  60. {$mode objfpc}{$H+}
  61. interface
  62. uses
  63. BaseUnix, Sockets,initc;
  64. const
  65. LIB_C = clib; // use initc's idea of what libc is called. In the future overrides might be necessary here.
  66. // (older BSD convention is to have a separate libresolve that contains these functions)
  67. // Error return codes from gethostbyname() and gethostbyaddr()
  68. // (left in h_errno).
  69. const
  70. NETDB_INTERNAL = -(1); { see errno }
  71. NETDB_SUCCESS = 0; { no problem }
  72. HOST_NOT_FOUND = 1; { Authoritative Answer Host not found }
  73. TRY_AGAIN = 2; { Non-Authoritative Host not found, or SERVERFAIL }
  74. NO_RECOVERY = 3; { Non recoverable errors, FORMERR, REFUSED, NOTIMP }
  75. NO_DATA = 4; { Valid name, no data record of requested type }
  76. NO_ADDRESS = NO_DATA; { no address, look for MX record }
  77. {$IF DEFINED(FREEBSD)}
  78. AI_PASSIVE = $00000001;
  79. AI_CANONNAME = $00000002;
  80. AI_NUMERICHOST = $00000004;
  81. AI_V4MAPPED = $00000008;
  82. AI_ALL = $00000010;
  83. AI_ADDRCONFIG = $00000020;
  84. AI_DEFAULT = (AI_V4MAPPED OR AI_ADDRCONFIG);
  85. EAI_ADDRFAMILY = 1; (* address family for hostname not supported *)
  86. EAI_AGAIN = 2; (* temporary failure in name resolution *)
  87. EAI_BADFLAGS = 3; (* invalid value for ai_flags *)
  88. EAI_FAIL = 4; (* non-recoverable failure in name resolution *)
  89. EAI_FAMILY = 5; (* ai_family not supported *)
  90. EAI_MEMORY = 6; (* memory allocation failure *)
  91. EAI_NODATA = 7; (* no address associated with hostname *)
  92. EAI_NONAME = 8; (* hostname nor servname provided, or not known *)
  93. EAI_SERVICE = 9; (* servname not supported for ai_socktype *)
  94. EAI_SOCKTYPE = 10; (* ai_socktype not supported *)
  95. EAI_SYSTEM = 11; (* system error returned in errno *)
  96. EAI_BADHINTS = 12;
  97. EAI_PROTOCOL = 13;
  98. EAI_MAX = 14;
  99. {$ELSE}
  100. (* Possible values for `ai_flags' field in `addrinfo' structure. *)
  101. AI_PASSIVE = $0001; (* Socket address is intended for `bind'. *)
  102. AI_CANONNAME = $0002; (* Request for canonical name. *)
  103. AI_NUMERICHOST = $0004; (* Don't use name resolution. *)
  104. AI_V4MAPPED = $0008; (* IPv4 mapped addresses are acceptable. *)
  105. AI_ALL = $0010; (* Return IPv4 mapped and IPv6 addresses. *)
  106. AI_ADDRCONFIG = $0020; (* Use configuration of this host to choose returned address type.. *)
  107. AI_IDN = $0040; (* IDN encode input (assuming it is encoded in the current locale's character set) before looking it up. *)
  108. AI_CANONIDN = $0080; (* Translate canonical name from IDN format. *)
  109. AI_IDN_ALLOW_UNASSIGNED = $0100; (* Don't reject unassigned Unicode code points. *)
  110. AI_IDN_USE_STD3_ASCII_RULES = $0200; (* Validate strings according to STD3 rules. *)
  111. AI_NUMERICSERV = $0400; (* Don't use name resolution. *)
  112. (* Error values for `getaddrinfo' function. *)
  113. EAI_BADFLAGS = -1; (* Invalid value for `ai_flags' field. *)
  114. EAI_NONAME = -2; (* NAME or SERVICE is unknown. *)
  115. EAI_AGAIN = -3; (* Temporary failure in name resolution. *)
  116. EAI_FAIL = -4; (* Non-recoverable failure in name res. *)
  117. EAI_NODATA = -5; (* No address associated with NAME. *)
  118. EAI_FAMILY = -6; (* `ai_family' not supported. *)
  119. EAI_SOCKTYPE = -7; (* `ai_socktype' not supported. *)
  120. EAI_SERVICE = -8; (* SERVICE not supported for `ai_socktype'. *)
  121. EAI_ADDRFAMILY = -9; (* Address family for NAME not supported. *)
  122. EAI_MEMORY = -10; (* Memory allocation failure. *)
  123. EAI_SYSTEM = -11; (* System error returned in `errno'. *)
  124. EAI_OVERFLOW = -12; (* Argument buffer overflow. *)
  125. EAI_INPROGRESS = -100; (* Processing request in progress. *)
  126. EAI_CANCELED = -101; (* Request canceled. *)
  127. EAI_NOTCANCELED = -102; (* Request not canceled. *)
  128. EAI_ALLDONE = -103; (* All requests done. *)
  129. EAI_INTR = -104; (* Interrupted by a signal. *)
  130. EAI_IDN_ENCODE = -105; (* IDN encoding failed. *)
  131. {$ENDIF}
  132. (* Constants for getnameinfo() *)
  133. NI_MAXHOST = 1025;
  134. NI_MAXSERV = 32;
  135. (* Flag values for getnameinfo() *)
  136. {$IF DEFINED(FREEBSD)}
  137. NI_NOFQDN = $00000001;
  138. NI_NUMERICHOST = $00000002;
  139. NI_NAMEREQD = $00000004;
  140. NI_NUMERICSERV = $00000008;
  141. NI_DGRAM = $00000010;
  142. NI_NUMERICSCOPE = $00000020;
  143. {$ELSE}
  144. NI_NUMERICHOST = 1;
  145. NI_NUMERICSERV = 2;
  146. NI_NOFQDN = 4;
  147. NI_NAMEREQD = 8;
  148. NI_DGRAM = 16;
  149. {$ENDIF}
  150. {
  151. * Scope delimit character
  152. }
  153. const
  154. SCOPE_DELIMITER = '%';
  155. //#define h_addr h_addr_list[0] /* address, for backward compatibility */
  156. type
  157. {*
  158. * Structures returned by network data base library. All addresses are
  159. * supplied in host order, and returned in network order (suitable for
  160. * use in system calls).
  161. *}
  162. hostent = record
  163. h_name: PChar; {/* official name of host *}
  164. h_aliases: PPChar; {* alias list *}
  165. h_addrtype: cInt; {* host address type *}
  166. h_length: cInt; {* length of address *}
  167. h_addr_list: PPChar;{* list of addresses from name server *}
  168. end;
  169. THostEnt = hostent;
  170. PHostEnt = ^THostEnt;
  171. PPHostEnt = ^PHostEnt;
  172. netent = record
  173. n_name: PChar; {* official name of net *}
  174. n_aliases: PPChar; {* alias list *}
  175. n_addrtype: cInt; {* net address type *}
  176. n_net: cuInt32; {* network # *}
  177. end;
  178. TNetEnt = netent;
  179. PNetEnt = ^TNetEnt;
  180. PPNetEnt = ^PNetEnt;
  181. servent = record
  182. s_name: PChar; {* official service name *}
  183. s_aliases: PPChar;{* alias list *}
  184. s_port: cInt; {* port # *}
  185. s_proto: PChar; {* protocol to use *}
  186. end;
  187. TServEnt = servent;
  188. PServEnt = ^TServEnt;
  189. PPServEnt = ^PServEnt;
  190. protoent = record
  191. p_name: PChar; {* official protocol name *}
  192. p_aliases: PPChar; {* alias list *}
  193. p_proto: cInt; {* protocol # *}
  194. end;
  195. TProtoEnt = protoent;
  196. PProtoEnt = ^TProtoEnt;
  197. PPProtoEnt = ^PProtoEnt;
  198. {$if defined(LINUX) or defined(OPENBSD)}
  199. {$define FIRST_ADDR_THEN_CANONNAME}
  200. {$endif}
  201. {$if defined(FREEBSD) or defined(NETBSD) or defined(DRAGONFLY) or defined(SOLARIS)}
  202. {$define FIRST_CANONNAME_THEN_ADDR}
  203. {$endif}
  204. {$if not defined(FIRST_CANONNAME_THEN_ADDR) and not defined(FIRST_ADDR_THEN_CANONNAME)}
  205. {$error fatal 'Please consult the netdb.h file for your system to determine the order of ai_addr and ai_canonname'}
  206. {$endif}
  207. PAddrInfo = ^addrinfo;
  208. addrinfo = record
  209. ai_flags: cInt; {* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST *}
  210. ai_family: cInt; {* PF_xxx *}
  211. ai_socktype: cInt; {* SOCK_xxx *}
  212. ai_protocol: cInt; {* 0 or IPPROTO_xxx for IPv4 and IPv6 *}
  213. ai_addrlen: TSocklen; {* length of ai_addr *}
  214. {$ifdef FIRST_CANONNAME_THEN_ADDR}
  215. ai_canonname: PChar; {* canonical name for hostname *}
  216. ai_addr: psockaddr; {* binary address *}
  217. {$endif}
  218. {$ifdef FIRST_ADDR_THEN_CANONNAME}
  219. ai_addr: psockaddr; {* binary address *}
  220. ai_canonname: PChar; {* canonical name for hostname *}
  221. {$endif}
  222. ai_next: PAddrInfo; {* next structure in linked list *}
  223. end;
  224. TAddrInfo = addrinfo;
  225. PPAddrInfo = ^PAddrInfo;
  226. procedure endhostent; cdecl; external LIB_C name 'endhostent';
  227. procedure endnetent; cdecl; external LIB_C name 'endnetent';
  228. procedure endnetgrent; cdecl; external LIB_C name 'endnetgrent';
  229. procedure endprotoent; cdecl; external LIB_C name 'endprotoent';
  230. procedure endservent; cdecl; external LIB_C name 'endservent';
  231. procedure freehostent(ptr: PHostEnt); cdecl; external LIB_C name 'freehostent';
  232. function gethostbyaddr(addr: PChar; len, typ: cInt): PHostEnt; cdecl; external LIB_C name 'gethostbyaddr';
  233. function gethostbyname(name: PChar): PHostEnt; cdecl; external LIB_C name 'gethostbyname';
  234. function gethostbyname2(name: PChar; af: cInt): PHostEnt; cdecl; external LIB_C name 'gethostbyname2';
  235. function gethostent: PHostEnt; cdecl; external LIB_C name 'gethostent';
  236. function getipnodebyaddr(src: Pointer; len: size_t; af: cInt; error_num: PcInt): PHostEnt; cdecl; external LIB_C name 'getipnodebyaddr';
  237. function getipnodebyname(name: PChar; af, flags: cInt; error_num: PcInt): PHostEnt; cdecl; external LIB_C name 'getipnodebyname';
  238. function getnetbyaddr(net: cint32; typ: cInt): PNetEnt; cdecl; external LIB_C name 'getnetbyaddr';
  239. function getnetbyname(name: PChar): PNetEnt; cdecl; external LIB_C name 'getnetbyname';
  240. function getnetent: PNetEnt; cdecl; external LIB_C name 'getnetent';
  241. function getnetgrent(host, user, domain: PPChar): cInt; cdecl; external LIB_C name 'getnetgrent';
  242. function getprotobyname(name: PChar): PProtoEnt; cdecl; external LIB_C name 'getprotobyname';
  243. function getprotobynumber(proto: cInt): PProtoEnt; cdecl; external LIB_C name 'getprotobynumber';
  244. function getprotoent: PProtoEnt; cdecl; external LIB_C name 'getprotoent';
  245. function getservbyname(name, proto: PChar): PServEnt; cdecl; external LIB_C name 'getservbyname';
  246. function getservbyport(port: cInt; proto: PChar): PServEnt; cdecl; external LIB_C name 'getservbyport';
  247. function getservent: PServEnt; cdecl; external LIB_C name 'getservent';
  248. procedure herror(erstring: PChar); cdecl; external LIB_C name 'herror';
  249. function hstrerror(err: cInt): PChar; cdecl; external LIB_C name 'hstrerror';
  250. function innetgr(netgroup, host, user, domain: PChar): cInt; cdecl; external LIB_C name 'innetgr';
  251. procedure sethostent(i: cInt); cdecl; external LIB_C name 'sethostent';
  252. {* void sethostfile(const char *); *}
  253. procedure setnetent(stayopen: cInt); cdecl; external LIB_C name 'setnetent';
  254. procedure setprotoent(stayopen: cInt); cdecl; external LIB_C name 'setprotoent';
  255. function getaddrinfo(name, service: PChar; hints: PAddrInfo;
  256. res: PPAddrInfo): cInt; cdecl; external LIB_C name 'getaddrinfo';
  257. function getnameinfo(sa: PSockAddr; salen: TSockLen; host: PChar; hostlen: TSize;
  258. serv: PChar; servlen: TSize; flags: cInt): cInt; cdecl; external LIB_C name 'getnameinfo';
  259. procedure freeaddrinfo(ai: PAddrInfo); cdecl; external LIB_C name 'freeaddrinfo';
  260. function gai_strerror(ecode: cInt): PChar; cdecl; external LIB_C name 'gai_strerror';
  261. procedure setnetgrent(netgroup: PChar); cdecl; external LIB_C name 'setnetgrent';
  262. procedure setservent(stayopen: cInt); cdecl; external LIB_C name 'setservent';
  263. implementation
  264. end.