Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
GETHOSTBYNAME(3)       FreeBSD Library Functions Manual	      GETHOSTBYNAME(3)

     dnsres_init, dnsres_gethostbyname,	dnsres_gethostbyname2,
     dnsres_gethostbyaddr, dnsres_getaddrinfo -- non blocking DNS resolving

     #include <sys/types.h>
     #include <sys/socket.h>
     #include <netdb.h>
     #include <dnsres.h>

     dnsres_init(struct	dnsres *_resp);

     dnsres_gethostbyname(struct dnsres	*res, const char *name,
	 void (*cb)(struct hostent *hp,	int error, void	*arg), void *arg);

     dnsres_gethostbyname2(struct dnsres *res, const char *name, int af,
	 void (*cb)(struct hostent *hp,	int error, void	*arg), void *arg);

     dnsres_gethostbyaddr(struct dnsres	*res, const char *addr,	int len,
	 int af, void (*cb)(struct hostent *hp,	int error, void	*arg),
	 void *arg);

     dnsres_getaddrinfo(struct dnsres *res, const char *hostname,
	 const char *servname, const struct addrinfo *hints,
	 void (*cb)(struct addrinfo *ai, int res, void *arg), void *arg);

     The dnsres_init() is used to initialize the dnsres	library.  If you are
     developing	a multi-threaded application, you need one struct dnsres per

     The dnsres_gethostbyname(), dnsres_gethostbyname2() and
     dnsres_gethostbyaddr() functions each call	their provided callback	func-
     tion with a pointer to an object with the following structure describing
     an	internet host referenced by name or by address,	respectively.  This
     structure contains	either information obtained from the name server
     (i.e., resolver(3)	and named(8)), broken-out fields from a	line in
     /etc/hosts, or database entries supplied by the yp(8) system.
     resolv.conf(5) describes how the particular database is chosen.

     struct  dnsres_hostent {
	     char    *h_name;	     /*	official name of host */
	     char    **h_aliases;    /*	alias list */
	     int     h_addrtype;     /*	host address type */
	     int     h_length;	     /*	length of address */
	     char    **h_addr_list;  /*	list of	addresses from name server */

     The members of this structure are:

     h_name	  Official name	of the host.

     h_aliases	  A NULL-terminated array of alternate names for the host.

     h_addrtype	  The type of address being returned.

     h_length	  The length, in bytes,	of the address.

     h_addr_list  A zero-terminated array of network addresses for the host.
		  Host addresses are returned in network byte order.

     h_addr	  The first address in h_addr_list; this is for	backward com-

     The function dnsres_gethostbyname() will search for the named host	in the
     current domain and	its parents using the search lookup semantics detailed
     in	resolv.conf(5) and hostname(7).

     dnsres_gethostbyname2() is	an advanced form of gethostbyname() which al-
     lows lookups in address families other than AF_INET.  Currently, the only
     supported address family besides AF_INET is AF_INET6.

     The dnsres_gethostbyaddr()	function will search for the specified address
     of	length len in the address family af.  The only address family cur-
     rently supported is AF_INET.

     The dnsres_getaddrinfo() function is used to get a	list of	IP addresses
     and port numbers for host hostname	and service servname.

     HOSTALIASES  A file containing local host aliases.	 See hostname(7) for
		  more information.

     RES_OPTIONS  A list of options to override	the resolver's internal	de-
		  faults.  See resolver(3) for more information.


     Error return status from dnsres_gethostbyname(), dnsres_gethostbyname2(),
     and dnsres_gethostbyaddr()	is indicated by	a null pointer passed to the
     callback function.	 The integer dr_errno may then be checked in struct
     dnsres to see whether this	is a temporary failure or an invalid or	un-
     known host.

     The variable h_errno can have the following values:

     DNSRES_HOST_NOT_FOUND  No such host is known.

     DNSRES_TRY_AGAIN	    This is usually a temporary	error and means	that
			    the	local server did not receive a response	from
			    an authoritative server.  A	retry at some later
			    time may succeed.

     DNSRES_NO_RECOVERY	    Some unexpected server failure was encountered.
			    This is a non-recoverable error.

     DNSRES_NO_DATA	    The	requested name is valid	but does not have an
			    IP address;	this is	not a temporary	error.	This
			    means that the name	is known to the	name server
			    but	there is no address associated with this name.
			    Another type of request to the name	server using
			    this domain	name will result in an answer; for ex-
			    ample, a mail-forwarder may	be registered for this

     DNSRES_NETDB_INTERNAL  An internal	error occurred.	 This may occurs when
			    an address family other than AF_INET or AF_INET6
			    is specified or when a resource is unable to be

     DNSRES_NETDB_SUCCESS   The	function completed successfully.

     getnameinfo(3), resolver(3), hosts(5), resolv.conf(5), hostname(7),

     The herror() function appeared in 4.3BSD.	The endhostent(),
     gethostbyaddr(), gethostbyname(), gethostent(), and sethostent() func-
     tions appeared in 4.2BSD.

     If	the search routines in resolv.conf(5) decide to	read the /etc/hosts
     file, gethostent()	and other functions will read the next line of the
     file, re-opening the file if necessary.

     The sethostent() function opens and/or rewinds the	file /etc/hosts.  If
     the stayopen argument is non-zero,	the file will not be closed after each
     call to gethostbyname(), gethostbyname2(),	or gethostbyaddr().

     The endhostent() function closes the file.

     The dnsres	library	was hacked together by Niels Provos.  Heavy use	was
     made of the exisiting BSD resolver	library.

FreeBSD	13.0			March 13, 1997			  FreeBSD 13.0


Want to link to this manual page? Use this URL:

home | help