xref: /netbsd-src/external/bsd/libbind/dist/doc/getipnodebyname.cat3 (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1*5bbd2a12SchristosGETIPNODEBYNAME(3)     FreeBSD Library Functions Manual     GETIPNODEBYNAME(3)
2b5677b36Schristos
3b5677b36SchristosNNAAMMEE
4*5bbd2a12Schristos     ggeettiippnnooddeebbyynnaammee, ggeettiippnnooddeebbyyaaddddrr -- get network host entry
5*5bbd2a12Schristos     ffrreeeehhoosstteenntt -- free network host entry
6b5677b36Schristos
7b5677b36SchristosSSYYNNOOPPSSIISS
8b5677b36Schristos     ##iinncclluuddee <<nneettddbb..hh>>
9b5677b36Schristos
10b5677b36Schristos     _s_t_r_u_c_t _h_o_s_t_e_n_t _*
11b5677b36Schristos     ggeettiippnnooddeebbyynnaammee(_c_o_n_s_t _c_h_a_r _*_n_a_m_e, _i_n_t _a_f, _i_n_t _f_l_a_g_s, _i_n_t _*_e_r_r_o_r);
12b5677b36Schristos
13b5677b36Schristos     _s_t_r_u_c_t _h_o_s_t_e_n_t _*
14b5677b36Schristos     ggeettiippnnooddeebbyyaaddddrr(_c_o_n_s_t _v_o_i_d _*_a_d_d_r, _s_i_z_e___t _l_e_n, _i_n_t _a_f, _i_n_t _*_e_r_r_o_r);
15b5677b36Schristos
16b5677b36Schristos     _v_o_i_d
17b5677b36Schristos     ffrreeeehhoosstteenntt(_s_t_r_u_c_t _h_o_s_t_e_n_t _*_h_e);
18b5677b36Schristos
19b5677b36SchristosDDEESSCCRRIIPPTTIIOONN
20b5677b36Schristos     GGeettiippnnooddeebbyynnaammee(), and ggeettiippnnooddeebbyyaaddddrr() each return a pointer to a
21b5677b36Schristos     _h_o_s_t_e_n_t structure (see below) describing an internet host referenced by
22*5bbd2a12Schristos     name or by address, as the function names indicate.  This structure con-
23b5677b36Schristos     tains either the information obtained from the name server, or broken-out
24*5bbd2a12Schristos     fields from a line in _/_e_t_c_/_h_o_s_t_s.  If the local name server is not run-
25b5677b36Schristos     ning, these routines do a lookup in _/_e_t_c_/_h_o_s_t_s.
26b5677b36Schristos
27b5677b36Schristos           struct  hostent {
28b5677b36Schristos                   char    *h_name;        /* official name of host */
29b5677b36Schristos                   char    **h_aliases;    /* alias list */
30b5677b36Schristos                   int     h_addrtype;     /* host address type */
31b5677b36Schristos                   int     h_length;       /* length of address */
32b5677b36Schristos                   char    **h_addr_list;  /* list of addresses from name server */
33b5677b36Schristos           };
34b5677b36Schristos
35b5677b36Schristos           #define h_addr  h_addr_list[0]  /* address, for backward compatibility */
36b5677b36Schristos
37b5677b36Schristos     The members of this structure are:
38b5677b36Schristos
39b5677b36Schristos     h_name       Official name of the host.
40b5677b36Schristos
41b5677b36Schristos     h_aliases    A zero-terminated array of alternate names for the host.
42b5677b36Schristos
43b5677b36Schristos     h_addrtype   The type of address being returned.
44b5677b36Schristos
45b5677b36Schristos     h_length     The length, in bytes, of the address.
46b5677b36Schristos
47b5677b36Schristos     h_addr_list  A zero-terminated array of network addresses for the host.
48b5677b36Schristos                  Host addresses are returned in network byte order.
49b5677b36Schristos
50*5bbd2a12Schristos     h_addr       The first address in h_addr_list; this is for backward com-
51b5677b36Schristos                  patibility.
52b5677b36Schristos
53b5677b36Schristos     This structure should be freed after use by calling ffrreeeehhoosstteenntt().
54b5677b36Schristos
55b5677b36Schristos     When using the nameserver, ggeettiipphhoossttbbyyaaddddrr() will search for the named
56*5bbd2a12Schristos     host in each parent domain given in the ``search'' directive of
57*5bbd2a12Schristos     resolv.conf(5) unless the name contains a dot (``.'').  If the name con-
58b5677b36Schristos     tains no dot, and if the environment variable HOSTALIASES contains the
59b5677b36Schristos     name of an alias file, the alias file will first be searched for an alias
60b5677b36Schristos     matching the input name.  See hostname(7) for the domain search procedure
61b5677b36Schristos     and the alias file format.
62b5677b36Schristos
63b5677b36Schristos     GGeettiipphhoossttbbyyaaddddrr() can be told to look for IPv4 addresses, IPv6 addresses
64b5677b36Schristos     or both IPv4 and IPv6.  If IPv4 addresses only are to be looked up then
65b5677b36Schristos     _a_f should be set to AF_INET, otherwise it should be set to AF_INET6.
66b5677b36Schristos
67b5677b36Schristos     There are three flags that can be set
68b5677b36Schristos
69b5677b36Schristos     AI_V4MAPPED    Return IPv4 addresses if no IPv6 addresses are found.
70b5677b36Schristos                    This flag is ignored unless _a_f is AF_INET6.
71b5677b36Schristos
72b5677b36Schristos     AI_ALL         Return IPv4 addresses as well IPv6 addresses if
73b5677b36Schristos                    AI_V4MAPPED is set.  This flag is ignored unless _a_f is
74b5677b36Schristos                    AF_INET6.
75b5677b36Schristos
76b5677b36Schristos     AI_ADDRCONFIG  Only return addresses of a given type if the system has an
77b5677b36Schristos                    active interface with that type.
78b5677b36Schristos
79b5677b36Schristos     Also AI_DEFAULT is defined to be (AI_V4MAPPED|AI_ADDRCONFIG).
80b5677b36Schristos
81b5677b36Schristos     GGeettiippnnooddeebbyyaaddddrr() will lookup IPv4 mapped and compatible addresses in the
82b5677b36Schristos     IPv4 name space and IPv6 name space
83b5677b36Schristos
84b5677b36Schristos     FFrreeeehhoosstteenntt() frees the hostent structure allocated be ggeettiippnnooddeebbyynnaammee()
85b5677b36Schristos     and ggeettiippnnooddeebbyyaaddddrr().  The structures returned by ggeetthhoossttbbyynnaammee(),
86b5677b36Schristos     ggeetthhoossttbbyynnaammee22(), ggeetthhoossttbbyyaaddddrr() and ggeetthhoosstteenntt() should not be passed
87b5677b36Schristos     to ffrreeeehhoosstteenntt() as they are pointers to static areas.
88b5677b36Schristos
89b5677b36SchristosEENNVVIIRROONNMMEENNTT
90b5677b36Schristos     HOSTALIASES    Name of file containing (_h_o_s_t _a_l_i_a_s, _f_u_l_l _h_o_s_t_n_a_m_e) pairs.
91b5677b36Schristos
92b5677b36SchristosFFIILLEESS
93b5677b36Schristos     /etc/hosts     See hosts(5).
94b5677b36Schristos
95b5677b36SchristosDDIIAAGGNNOOSSTTIICCSS
96*5bbd2a12Schristos     Error return status from ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() is indi-
97b5677b36Schristos     cated by return of a null pointer.  In this case _e_r_r_o_r may then be
98b5677b36Schristos     checked to see whether this is a temporary failure or an invalid or
99b5677b36Schristos     unknown host.  _e_r_r_n_o can have the following values:
100b5677b36Schristos
101b5677b36Schristos           NETDB_INTERNAL    This indicates an internal error in the library,
102b5677b36Schristos                             unrelated to the network or name service.  _e_r_r_n_o
103b5677b36Schristos                             will be valid in this case; see perror.
104b5677b36Schristos
105b5677b36Schristos           HOST_NOT_FOUND    No such host is known.
106b5677b36Schristos
107b5677b36Schristos           TRY_AGAIN         This is usually a temporary error and means that
108b5677b36Schristos                             the local server did not receive a response from
109b5677b36Schristos                             an authoritative server.  A retry at some later
110b5677b36Schristos                             time may succeed.
111b5677b36Schristos
112b5677b36Schristos           NO_RECOVERY       Some unexpected server failure was encountered.
113b5677b36Schristos                             This is a non-recoverable error, as one might
114b5677b36Schristos                             expect.
115b5677b36Schristos
116b5677b36Schristos           NO_ADDRESS        The requested name is valid but does not have an
117b5677b36Schristos                             IP address; this is not a temporary error.  This
118b5677b36Schristos                             means that the name is known to the name server
119b5677b36Schristos                             but there is no address associated with this
120b5677b36Schristos                             name.  Another type of request to the name server
121b5677b36Schristos                             using this domain name will result in an answer;
122b5677b36Schristos                             for example, a mail-forwarder may be registered
123b5677b36Schristos                             for this domain.
124b5677b36Schristos
125b5677b36SchristosSSEEEE AALLSSOO
126b5677b36Schristos     hosts(5), hostname(7), resolver(3), resolver(5), gethostbyname(3),
127b5677b36Schristos     RFC2553.
128b5677b36Schristos
129b5677b36Schristos4th Berkeley Distribution     September 17, 1999     4th Berkeley Distribution
130