cnetdb.pp 10 KB

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