1*5bbd2a12Schristos.\" $NetBSD: getipnodebyname.3,v 1.1.1.2 2012/09/09 16:07:43 christos Exp $ 2b5677b36Schristos.\" 3b5677b36Schristos.\" Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") 4b5677b36Schristos.\" 5b5677b36Schristos.\" Permission to use, copy, modify, and/or distribute this software for any 6b5677b36Schristos.\" purpose with or without fee is hereby granted, provided that the above 7b5677b36Schristos.\" copyright notice and this permission notice appear in all copies. 8b5677b36Schristos.\" 9b5677b36Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10b5677b36Schristos.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11b5677b36Schristos.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12b5677b36Schristos.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13b5677b36Schristos.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14b5677b36Schristos.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15b5677b36Schristos.\" PERFORMANCE OF THIS SOFTWARE. 16b5677b36Schristos.\" 17b5677b36Schristos.\" Id: getipnodebyname.3,v 1.3 2009/01/22 23:49:23 tbox Exp 18b5677b36Schristos.\" 19b5677b36Schristos.Dd September 17, 1999 20b5677b36Schristos.Dt GETIPNODEBYNAME @LIB_NETWORK_EXT_U@ 21b5677b36Schristos.Os BSD 4 22b5677b36Schristos.Sh NAME 23b5677b36Schristos.Nm getipnodebyname , 24b5677b36Schristos.Nm getipnodebyaddr 25b5677b36Schristos.Nd get network host entry 26b5677b36Schristos.br 27b5677b36Schristos.Nm freehostent 28b5677b36Schristos.Nd free network host entry 29b5677b36Schristos.Sh SYNOPSIS 30b5677b36Schristos.Fd #include <netdb.h> 31b5677b36Schristos.Pp 32b5677b36Schristos.Ft struct hostent * 33b5677b36Schristos.Fn getipnodebyname "const char *name" "int af" "int flags" "int *error" 34b5677b36Schristos.Ft struct hostent * 35b5677b36Schristos.Fn getipnodebyaddr "const void *addr" "size_t len" "int af" "int *error" 36b5677b36Schristos.Ft void 37b5677b36Schristos.Fn freehostent "struct hostent *he" 38b5677b36Schristos.Sh DESCRIPTION 39b5677b36Schristos.Fn Getipnodebyname , 40b5677b36Schristosand 41b5677b36Schristos.Fn getipnodebyaddr 42b5677b36Schristoseach return a pointer to a 43b5677b36Schristos.Ft hostent 44b5677b36Schristosstructure (see below) describing an internet host 45b5677b36Schristosreferenced by name or by address, as the function names indicate. 46b5677b36SchristosThis structure contains either the information obtained from the name server, 47b5677b36Schristosor broken-out fields from a line in 48b5677b36Schristos.Pa /etc/hosts . 49b5677b36SchristosIf the local name server is not running, these routines do a lookup in 50b5677b36Schristos.Pa /etc/hosts . 51b5677b36Schristos.Bd -literal -offset indent 52b5677b36Schristosstruct hostent { 53b5677b36Schristos char *h_name; /* official name of host */ 54b5677b36Schristos char **h_aliases; /* alias list */ 55b5677b36Schristos int h_addrtype; /* host address type */ 56b5677b36Schristos int h_length; /* length of address */ 57b5677b36Schristos char **h_addr_list; /* list of addresses from name server */ 58b5677b36Schristos}; 59b5677b36Schristos 60b5677b36Schristos#define h_addr h_addr_list[0] /* address, for backward compatibility */ 61b5677b36Schristos.Ed 62b5677b36Schristos.Pp 63b5677b36SchristosThe members of this structure are: 64b5677b36Schristos.Bl -tag -width "h_addr_list" 65b5677b36Schristos.It h_name 66b5677b36SchristosOfficial name of the host. 67b5677b36Schristos.It h_aliases 68b5677b36SchristosA zero-terminated array of alternate names for the host. 69b5677b36Schristos.It h_addrtype 70b5677b36SchristosThe type of address being returned. 71b5677b36Schristos.It h_length 72b5677b36SchristosThe length, in bytes, of the address. 73b5677b36Schristos.It h_addr_list 74b5677b36SchristosA zero-terminated array of network addresses for the host. 75b5677b36SchristosHost addresses are returned in network byte order. 76b5677b36Schristos.It h_addr 77b5677b36SchristosThe first address in 78b5677b36Schristos.Li h_addr_list ; 79b5677b36Schristosthis is for backward compatibility. 80b5677b36Schristos.El 81b5677b36Schristos.Pp 82b5677b36SchristosThis structure should be freed after use by calling 83b5677b36Schristos.Fn freehostent . 84b5677b36Schristos.Pp 85b5677b36SchristosWhen using the nameserver, 86b5677b36Schristos.Fn getiphostbyaddr 87b5677b36Schristoswill search for the named host in each parent domain given in the 88b5677b36Schristos.Dq Li search 89b5677b36Schristosdirective of 90b5677b36Schristos.Xr resolv.conf @FORMAT_EXT@ 91b5677b36Schristosunless the name contains a dot 92b5677b36Schristos.Pq Dq \&. . 93b5677b36SchristosIf the name contains no dot, and if the environment variable 94b5677b36Schristos.Ev HOSTALIASES 95b5677b36Schristoscontains the name of an alias file, the alias file will first be searched 96b5677b36Schristosfor an alias matching the input name. 97b5677b36SchristosSee 98b5677b36Schristos.Xr hostname @DESC_EXT@ 99b5677b36Schristosfor the domain search procedure and the alias file format. 100b5677b36Schristos.Pp 101b5677b36Schristos.Fn Getiphostbyaddr 102b5677b36Schristoscan be told to look for IPv4 addresses, IPv6 addresses or both IPv4 and IPv6. 103b5677b36SchristosIf IPv4 addresses only are to be looked up then 104b5677b36Schristos.Fa af 105b5677b36Schristosshould be set to 106b5677b36Schristos.Dv AF_INET , 107b5677b36Schristosotherwise it should be set to 108b5677b36Schristos.Dv AF_INET6 . 109b5677b36Schristos.Pp 110b5677b36SchristosThere are three flags that can be set 111b5677b36Schristos.Bl -tag -width "AI_ADDRCONFIG" 112b5677b36Schristos.It Dv AI_V4MAPPED 113b5677b36SchristosReturn IPv4 addresses if no IPv6 addresses are found. 114b5677b36SchristosThis flag is ignored unless 115b5677b36Schristos.Fa af 116b5677b36Schristosis 117b5677b36Schristos.Dv AF_INET6 . 118b5677b36Schristos.It Dv AI_ALL 119b5677b36SchristosReturn IPv4 addresses as well IPv6 addresses if 120b5677b36Schristos.Dv AI_V4MAPPED 121b5677b36Schristosis set. 122b5677b36SchristosThis flag is ignored unless 123b5677b36Schristos.Fa af 124b5677b36Schristosis 125b5677b36Schristos.Dv AF_INET6 . 126b5677b36Schristos.It Dv AI_ADDRCONFIG 127b5677b36SchristosOnly return addresses of a given type if the system has an active interface 128b5677b36Schristoswith that type. 129b5677b36Schristos.El 130b5677b36Schristos.Pp 131b5677b36SchristosAlso 132b5677b36Schristos.Dv AI_DEFAULT 133b5677b36Schristosis defined to be 134b5677b36Schristos.Dv (AI_V4MAPPED|AI_ADDRCONFIG) . 135b5677b36Schristos.Pp 136b5677b36Schristos.Fn Getipnodebyaddr 137b5677b36Schristoswill lookup IPv4 mapped and compatible addresses in the IPv4 name 138b5677b36Schristosspace and IPv6 name space 139b5677b36Schristos.Pp 140b5677b36Schristos.Fn Freehostent 141b5677b36Schristosfrees the hostent structure allocated be 142b5677b36Schristos.Fn getipnodebyname 143b5677b36Schristosand 144b5677b36Schristos.Fn getipnodebyaddr . 145b5677b36SchristosThe structures returned by 146b5677b36Schristos.Fn gethostbyname , 147b5677b36Schristos.Fn gethostbyname2 , 148b5677b36Schristos.Fn gethostbyaddr 149b5677b36Schristosand 150b5677b36Schristos.Fn gethostent 151b5677b36Schristosshould not be passed to 152b5677b36Schristos.Fn freehostent 153b5677b36Schristosas they are pointers to static areas. 154b5677b36Schristos.Sh ENVIRONMENT 155b5677b36Schristos.Bl -tag -width "HOSTALIASES " -compact 156b5677b36Schristos.It Ev HOSTALIASES 157b5677b36SchristosName of file containing 158b5677b36Schristos.Pq Ar host alias , full hostname 159b5677b36Schristospairs. 160b5677b36Schristos.El 161b5677b36Schristos.Sh FILES 162b5677b36Schristos.Bl -tag -width "HOSTALIASES " -compact 163b5677b36Schristos.It Pa /etc/hosts 164b5677b36SchristosSee 165b5677b36Schristos.Xr hosts @FORMAT_EXT@ . 166b5677b36Schristos.El 167b5677b36Schristos.Sh DIAGNOSTICS 168b5677b36Schristos.Pp 169b5677b36SchristosError return status from 170b5677b36Schristos.Fn getipnodebyname 171b5677b36Schristosand 172b5677b36Schristos.Fn getipnodebyaddr 173b5677b36Schristosis indicated by return of a null pointer. 174b5677b36SchristosIn this case 175b5677b36Schristos.Ft error 176b5677b36Schristosmay then be checked to see whether this is a temporary failure 177b5677b36Schristosor an invalid or unknown host. 178b5677b36Schristos.Ft errno 179b5677b36Schristoscan have the following values: 180b5677b36Schristos.Bl -tag -width "HOST_NOT_FOUND " -offset indent 181b5677b36Schristos.It Dv NETDB_INTERNAL 182b5677b36SchristosThis indicates an internal error in the library, unrelated to the network 183b5677b36Schristosor name service. 184b5677b36Schristos.Ft errno 185b5677b36Schristoswill be valid in this case; see 186b5677b36Schristos.Xr perror @SYSCALL_EXT@ . 187b5677b36Schristos.It Dv HOST_NOT_FOUND 188b5677b36SchristosNo such host is known. 189b5677b36Schristos.It Dv TRY_AGAIN 190b5677b36SchristosThis is usually a temporary error 191b5677b36Schristosand means that the local server did not receive 192b5677b36Schristosa response from an authoritative server. 193b5677b36SchristosA retry at some later time may succeed. 194b5677b36Schristos.It Dv NO_RECOVERY 195b5677b36SchristosSome unexpected server failure was encountered. 196b5677b36SchristosThis is a non-recoverable error, as one might expect. 197b5677b36Schristos.It Dv NO_ADDRESS 198b5677b36SchristosThe requested name is valid but does not have an IP address; 199b5677b36Schristosthis is not a temporary error. 200b5677b36SchristosThis means that the name is known to the name server but there is no address 201b5677b36Schristosassociated with this name. 202b5677b36SchristosAnother type of request to the name server using this domain name 203b5677b36Schristoswill result in an answer; 204b5677b36Schristosfor example, a mail-forwarder may be registered for this domain. 205b5677b36Schristos.El 206b5677b36Schristos.Sh SEE ALSO 207b5677b36Schristos.Xr hosts @FORMAT_EXT@ , 208b5677b36Schristos.Xr hostname @DESC_EXT@ , 209b5677b36Schristos.Xr resolver @LIB_NETWORK_EXT@ , 210b5677b36Schristos.Xr resolver @FORMAT_EXT@ , 211b5677b36Schristos.Xr gethostbyname @LIB_NETWORK_EXT@ , 212b5677b36Schristos.Xr RFC2553 . 213