PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/fpcbuild-2.6.0/fpcsrc/packages/fcl-net/src/cnetdb.pp

#
Pascal | 268 lines | 133 code | 41 blank | 94 comment | 0 complexity | c23e39d20225f4f6d044cf3a820a0b00 MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-2.0, LGPL-2.1
  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. {
  78. return codes from getaddrinfo()
  79. }
  80. EAI_AGAIN = 2; { address family for hostname not supported }
  81. EAI_BADFLAGS = 3; { invalid value for ai_flags }
  82. EAI_FAIL = 4; { non-recoverable failure in name resolution }
  83. EAI_FAMILY = 5; { ai_family not supported }
  84. EAI_MEMORY = 6; { memory allocation failure }
  85. EAI_NONAME = 8; { hostname nor servname provided, or not known }
  86. EAI_SERVICE = 9; { servname not supported for ai_socktype }
  87. EAI_SOCKTYPE = 10; { ai_socktype not supported }
  88. EAI_SYSTEM = 11; { system error returned in errno }
  89. EAI_BADHINTS = 12;
  90. EAI_PROTOCOL = 13;
  91. EAI_MAX = 14;
  92. {
  93. * Flag values for getaddrinfo()
  94. }
  95. { get address to use bind() }
  96. AI_PASSIVE = $00000001;
  97. { fill ai_canonname }
  98. AI_CANONNAME = $00000002;
  99. { prevent host name resolution }
  100. AI_NUMERICHOST = $00000004;
  101. { prevent service name resolution }
  102. AI_NUMERICSERV = $00000008;
  103. { IPv6 and IPv4-mapped (with AI_V4MAPPED) }
  104. AI_ALL = $00000100;
  105. { accept IPv4-mapped if kernel supports }
  106. AI_V4MAPPED_CFG = $00000200;
  107. { only if any address is assigned }
  108. AI_ADDRCONFIG = $00000400;
  109. { accept IPv4-mapped IPv6 address }
  110. AI_V4MAPPED = $00000800;
  111. { special recommended flags for getipnodebyname }
  112. AI_DEFAULT = AI_V4MAPPED_CFG or AI_ADDRCONFIG;
  113. { valid flags for addrinfo (not a standard def, apps should not use it) }
  114. AI_MASK = AI_PASSIVE or AI_CANONNAME or AI_NUMERICHOST or AI_NUMERICSERV or AI_ADDRCONFIG;
  115. {
  116. * Constants for getnameinfo()
  117. }
  118. NI_MAXHOST = 1025;
  119. NI_MAXSERV = 32;
  120. {
  121. * Flag values for getnameinfo()
  122. }
  123. NI_NOFQDN = $00000001;
  124. NI_NUMERICHOST = $00000002;
  125. NI_NAMEREQD = $00000004;
  126. NI_NUMERICSERV = $00000008;
  127. NI_DGRAM = $00000010;
  128. {
  129. * Scope delimit character
  130. }
  131. const
  132. SCOPE_DELIMITER = '%';
  133. //#define h_addr h_addr_list[0] /* address, for backward compatibility */
  134. type
  135. {*
  136. * Structures returned by network data base library. All addresses are
  137. * supplied in host order, and returned in network order (suitable for
  138. * use in system calls).
  139. *}
  140. hostent = record
  141. h_name: PChar; {/* official name of host *}
  142. h_aliases: PPChar; {* alias list *}
  143. h_addrtype: cInt; {* host address type *}
  144. h_length: cInt; {* length of address *}
  145. h_addr_list: PPChar;{* list of addresses from name server *}
  146. end;
  147. THostEnt = hostent;
  148. PHostEnt = ^THostEnt;
  149. PPHostEnt = ^PHostEnt;
  150. netent = record
  151. n_name: PChar; {* official name of net *}
  152. n_aliases: PPChar; {* alias list *}
  153. n_addrtype: cInt; {* net address type *}
  154. n_net: cuInt32; {* network # *}
  155. end;
  156. TNetEnt = netent;
  157. PNetEnt = ^TNetEnt;
  158. PPNetEnt = ^PNetEnt;
  159. servent = record
  160. s_name: PChar; {* official service name *}
  161. s_aliases: PPChar;{* alias list *}
  162. s_port: cInt; {* port # *}
  163. s_proto: PChar; {* protocol to use *}
  164. end;
  165. TServEnt = servent;
  166. PServEnt = ^TServEnt;
  167. PPServEnt = ^PServEnt;
  168. protoent = record
  169. p_name: PChar; {* official protocol name *}
  170. p_aliases: PPChar; {* alias list *}
  171. p_proto: cInt; {* protocol # *}
  172. end;
  173. TProtoEnt = protoent;
  174. PProtoEnt = ^TProtoEnt;
  175. PPProtoEnt = ^PProtoEnt;
  176. PAddrInfo = ^addrinfo;
  177. addrinfo = record
  178. ai_flags: cInt; {* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST *}
  179. ai_family: cInt; {* PF_xxx *}
  180. ai_socktype: cInt; {* SOCK_xxx *}
  181. ai_protocol: cInt; {* 0 or IPPROTO_xxx for IPv4 and IPv6 *}
  182. ai_addrlen: TSocklen; {* length of ai_addr *}
  183. ai_canonname: PChar; {* canonical name for hostname *}
  184. ai_addr: psockaddr; {* binary address *}
  185. ai_next: PAddrInfo; {* next structure in linked list *}
  186. end;
  187. TAddrInfo = addrinfo;
  188. PPAddrInfo = ^PAddrInfo;
  189. procedure endhostent; cdecl; external LIB_C name 'endhostent';
  190. procedure endnetent; cdecl; external LIB_C name 'endnetent';
  191. procedure endnetgrent; cdecl; external LIB_C name 'endnetgrent';
  192. procedure endprotoent; cdecl; external LIB_C name 'endprotoent';
  193. procedure endservent; cdecl; external LIB_C name 'endservent';
  194. procedure freehostent(ptr: PHostEnt); cdecl; external LIB_C name 'freehostent';
  195. function gethostbyaddr(addr: PChar; len, typ: cInt): PHostEnt; cdecl; external LIB_C name 'gethostbyaddr';
  196. function gethostbyname(name: PChar): PHostEnt; cdecl; external LIB_C name 'gethostbyname';
  197. function gethostbyname2(name: PChar; af: cInt): PHostEnt; cdecl; external LIB_C name 'gethostbyname2';
  198. function gethostent: PHostEnt; cdecl; external LIB_C name 'gethostent';
  199. function getipnodebyaddr(src: Pointer; len: size_t; af: cInt; error_num: PcInt): PHostEnt; cdecl; external LIB_C name 'getipnodebyaddr';
  200. function getipnodebyname(name: PChar; af, flags: cInt; error_num: PcInt): PHostEnt; cdecl; external LIB_C name 'getipnodebyname';
  201. function getnetbyaddr(net: cint32; typ: cInt): PNetEnt; cdecl; external LIB_C name 'getnetbyaddr';
  202. function getnetbyname(name: PChar): PNetEnt; cdecl; external LIB_C name 'getnetbyname';
  203. function getnetent: PNetEnt; cdecl; external LIB_C name 'getnetent';
  204. function getnetgrent(host, user, domain: PPChar): cInt; cdecl; external LIB_C name 'getnetgrent';
  205. function getprotobyname(name: PChar): PProtoEnt; cdecl; external LIB_C name 'getprotobyname';
  206. function getprotobynumber(proto: cInt): PProtoEnt; cdecl; external LIB_C name 'getprotobynumber';
  207. function getprotoent: PProtoEnt; cdecl; external LIB_C name 'getprotoent';
  208. function getservbyname(name, proto: PChar): PServEnt; cdecl; external LIB_C name 'getservbyname';
  209. function getservbyport(port: cInt; proto: PChar): PServEnt; cdecl; external LIB_C name 'getservbyport';
  210. function getservent: PServEnt; cdecl; external LIB_C name 'getservent';
  211. procedure herror(erstring: PChar); cdecl; external LIB_C name 'herror';
  212. function hstrerror(err: cInt): PChar; cdecl; external LIB_C name 'hstrerror';
  213. function innetgr(netgroup, host, user, domain: PChar): cInt; cdecl; external LIB_C name 'innetgr';
  214. procedure sethostent(i: cInt); cdecl; external LIB_C name 'sethostent';
  215. {* void sethostfile(const char *); *}
  216. procedure setnetent(stayopen: cInt); cdecl; external LIB_C name 'setnetent';
  217. procedure setprotoent(stayopen: cInt); cdecl; external LIB_C name 'setprotoent';
  218. function getaddrinfo(hostname, servname: PChar;
  219. hints: PAddrInfo; res: PPAddrInfo): cInt; cdecl; external LIB_C name 'getaddrinfo';
  220. function getnameinfo(sa: PSockAddr; salen: TSockLen; host: PChar; hostlen: TSize;
  221. serv: PChar; servlen: TSize; flags: cInt): cInt; cdecl; external LIB_C name 'getnameinfo';
  222. procedure freeaddrinfo(ai: PAddrInfo); cdecl; external LIB_C name 'freeaddrinfo';
  223. function gai_strerror(ecode: cInt): PChar; cdecl; external LIB_C name 'gai_strerror';
  224. procedure setnetgrent(netgroup: PChar); cdecl; external LIB_C name 'setnetgrent';
  225. procedure setservent(stayopen: cInt); cdecl; external LIB_C name 'setservent';
  226. implementation
  227. end.