cnetdb.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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;
  64. const
  65. LIB_C = 'c';
  66. const
  67. NETDB_INTERNAL = -(1);
  68. { no problem }
  69. NETDB_SUCCESS = 0;
  70. { Authoritative Answer Host not found }
  71. HOST_NOT_FOUND = 1;
  72. { Non-Authoritative Host not found, or SERVERFAIL }
  73. TRY_AGAIN = 2;
  74. { Non recoverable errors, FORMERR, REFUSED, NOTIMP }
  75. NO_RECOVERY = 3;
  76. { Valid name, no data record of requested type }
  77. NO_DATA = 4;
  78. { no address, look for MX record }
  79. NO_ADDRESS = NO_DATA;
  80. {
  81. * Error return codes from getaddrinfo()
  82. }
  83. EAI_AGAIN = 2;
  84. { invalid value for ai_flags }
  85. EAI_BADFLAGS = 3;
  86. { non-recoverable failure in name resolution }
  87. EAI_FAIL = 4;
  88. { ai_family not supported }
  89. EAI_FAMILY = 5;
  90. { memory allocation failure }
  91. EAI_MEMORY = 6;
  92. { hostname nor servname provided, or not known }
  93. EAI_NONAME = 8;
  94. { servname not supported for ai_socktype }
  95. EAI_SERVICE = 9;
  96. { ai_socktype not supported }
  97. EAI_SOCKTYPE = 10;
  98. { system error returned in errno }
  99. EAI_SYSTEM = 11;
  100. EAI_BADHINTS = 12;
  101. EAI_PROTOCOL = 13;
  102. EAI_MAX = 14;
  103. {
  104. * Flag values for getaddrinfo()
  105. }
  106. { get address to use bind() }
  107. AI_PASSIVE = $00000001;
  108. { fill ai_canonname }
  109. AI_CANONNAME = $00000002;
  110. { prevent host name resolution }
  111. AI_NUMERICHOST = $00000004;
  112. { prevent service name resolution }
  113. AI_NUMERICSERV = $00000008;
  114. { IPv6 and IPv4-mapped (with AI_V4MAPPED) }
  115. AI_ALL = $00000100;
  116. { accept IPv4-mapped if kernel supports }
  117. AI_V4MAPPED_CFG = $00000200;
  118. { only if any address is assigned }
  119. AI_ADDRCONFIG = $00000400;
  120. { accept IPv4-mapped IPv6 address }
  121. AI_V4MAPPED = $00000800;
  122. { special recommended flags for getipnodebyname }
  123. AI_DEFAULT = AI_V4MAPPED_CFG or AI_ADDRCONFIG;
  124. { valid flags for addrinfo (not a standard def, apps should not use it) }
  125. AI_MASK = AI_PASSIVE or AI_CANONNAME or AI_NUMERICHOST or AI_NUMERICSERV or AI_ADDRCONFIG;
  126. {
  127. * Constants for getnameinfo()
  128. }
  129. NI_MAXHOST = 1025;
  130. NI_MAXSERV = 32;
  131. {
  132. * Flag values for getnameinfo()
  133. }
  134. NI_NOFQDN = $00000001;
  135. NI_NUMERICHOST = $00000002;
  136. NI_NAMEREQD = $00000004;
  137. NI_NUMERICSERV = $00000008;
  138. NI_DGRAM = $00000010;
  139. {
  140. * Scope delimit character
  141. }
  142. const
  143. SCOPE_DELIMITER = '%';
  144. //#define h_addr h_addr_list[0] /* address, for backward compatibility */
  145. type
  146. {*
  147. * Structures returned by network data base library. All addresses are
  148. * supplied in host order, and returned in network order (suitable for
  149. * use in system calls).
  150. *}
  151. hostent = record
  152. h_name: PChar; {/* official name of host *}
  153. h_aliases: PPChar; {* alias list *}
  154. h_addrtype: cInt; {* host address type *}
  155. h_length: cInt; {* length of address *}
  156. h_addr_list: PPChar;{* list of addresses from name server *}
  157. end;
  158. THostEnt = hostent;
  159. PHostEnt = ^THostEnt;
  160. PPHostEnt = ^PHostEnt;
  161. netent = record
  162. n_name: PChar; {* official name of net *}
  163. n_aliases: PPChar; {* alias list *}
  164. n_addrtype: cInt; {* net address type *}
  165. n_net: cuInt32; {* network # *}
  166. end;
  167. TNetEnt = netent;
  168. PNetEnt = ^TNetEnt;
  169. PPNetEnt = ^PNetEnt;
  170. servent = record
  171. s_name: PChar; {* official service name *}
  172. s_aliases: PPChar;{* alias list *}
  173. s_port: cInt; {* port # *}
  174. s_proto: PChar; {* protocol to use *}
  175. end;
  176. TServEnt = servent;
  177. PServEnt = ^TServEnt;
  178. PPServEnt = ^PServEnt;
  179. protoent = record
  180. p_name: PChar; {* official protocol name *}
  181. p_aliases: PPChar; {* alias list *}
  182. p_proto: cInt; {* protocol # *}
  183. end;
  184. TProtoEnt = protoent;
  185. PProtoEnt = ^TProtoEnt;
  186. PPProtoEnt = ^PProtoEnt;
  187. PAddrInfo = ^addrinfo;
  188. addrinfo = record
  189. ai_flags: cInt; {* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST *}
  190. ai_family: cInt; {* PF_xxx *}
  191. ai_socktype: cInt; {* SOCK_xxx *}
  192. ai_protocol: cInt; {* 0 or IPPROTO_xxx for IPv4 and IPv6 *}
  193. ai_addrlen: TSocklen; {* length of ai_addr *}
  194. ai_canonname: PChar; {* canonical name for hostname *}
  195. ai_addr: psockaddr; {* binary address *}
  196. ai_next: PAddrInfo; {* next structure in linked list *}
  197. end;
  198. TAddrInfo = addrinfo;
  199. PPAddrInfo = ^PAddrInfo;
  200. procedure EndHostent; cdecl; external LIB_C name 'endhostent';
  201. procedure EndNetent; cdecl; external LIB_C name 'endnetent';
  202. procedure EndNetgrent; cdecl; external LIB_C name 'endnetgrent';
  203. procedure EndProtoent; cdecl; external LIB_C name 'endprotoent';
  204. procedure Endservent; cdecl; external LIB_C name 'endservent';
  205. procedure FreeHostent(ptr: PHostEnt); cdecl; external LIB_C name 'freehostent';
  206. function GetHostByAddr(Addr: PChar; len, Typ: cInt): PHostEnt; cdecl; external LIB_C name 'gethostbyaddr';
  207. function GetHostByName(Host: PChar): PHostEnt; cdecl; external LIB_C name 'gethostbyname';
  208. function GetHostByHost2(Host: PChar; af: cInt): PHostEnt; cdecl; external LIB_C name 'gethostbyname2';
  209. function GetHostent: PHostEnt; cdecl; external LIB_C name 'gethostent';
  210. function GetIPNodeByAddr(src: Pointer; len: size_t; af: cInt; error_num: PcInt): PHostEnt; cdecl; external LIB_C name 'getipnodebyaddr';
  211. function GetIPNodeByName(Name: PChar; af, flags: cInt; Error_num: PcInt): PHostEnt; cdecl; external LIB_C name 'getipnodebyname';
  212. function GetNetByAddr(Net: cint32; Typ: cInt): PNetEnt; cdecl; external LIB_C name 'getnetbyaddr';
  213. function GetNetByName(Name: PChar): PNetEnt; cdecl; external LIB_C name 'getnetbyname';
  214. function GetNetent: PNetEnt; cdecl; external LIB_C name 'getnetent';
  215. function GetNetgrent(Host, User, Domain: PPChar): cInt; cdecl; external LIB_C name 'getnetgrent';
  216. function GetProtoByName(Name: PChar): PProtoEnt; cdecl; external LIB_C name 'getprotobyname';
  217. function GetProtoBynumber(Proto: cInt): PProtoEnt; cdecl; external LIB_C name 'getprotobynumber';
  218. function GetProtoent: PProtoEnt; cdecl; external LIB_C name 'getprotoent';
  219. function GetServByName(Name, Proto: PChar): PServEnt; cdecl; external LIB_C name 'getservbyname';
  220. function GetServByport(Port: cInt; Proto: PChar): PServEnt; cdecl; external LIB_C name 'getservbyport';
  221. function GetServent: PServEnt; cdecl; external LIB_C name 'getservent';
  222. procedure herror(erString: PChar); cdecl; external LIB_C name 'herror';
  223. function hstrerror(err: cInt): PChar; cdecl; external LIB_C name 'hstrerror';
  224. function innetgr(NetGroup, Host, User, Domain: PChar): cInt; cdecl; external LIB_C name 'innetgr';
  225. procedure SetHostent(i: cInt); cdecl; external LIB_C name 'sethostent';
  226. {* void SetHostfile(const char *); *}
  227. procedure SetNetent(StayOpen: cInt); cdecl; external LIB_C name 'setnetent';
  228. procedure SetProtoent(StayOpen: cInt); cdecl; external LIB_C name 'setprotoent';
  229. function GetAddrInfo(HostName, ServName: PChar;
  230. Hints: PAddrInfo; res: PPAddrInfo): cInt; cdecl; external LIB_C name 'getaddrinfo';
  231. function GetNameInfo(sa: PSockAddr; salen: TSockLen; Host: PChar; Hostlen: TSize;
  232. Serv: PChar; Servlen: TSize; Flags: cInt): cInt; cdecl; external LIB_C name 'getnameinfo';
  233. procedure FreeAddrInfo(ai: PAddrInfo); cdecl; external LIB_C name 'freeaddrinfo';
  234. function gai_strerror(eCode: cInt): PChar; cdecl; external LIB_C name 'gai_strerror';
  235. procedure SetNetgrent(NetGroup: PChar); cdecl; external LIB_C name 'setnetgrent';
  236. procedure SetServent(StayOpen: cInt); cdecl; external LIB_C name 'setservent';
  237. implementation
  238. end.