1GETHOSTBYNAME(3)           Linux Programmer's Manual          GETHOSTBYNAME(3)
2
3
4

NAME

6       gethostbyname,  gethostbyaddr, sethostent, gethostent, endhostent, her‐
7       ror, hstrerror - get network host entry
8

SYNOPSIS

10       #include <netdb.h>
11       extern int h_errno;
12
13       struct hostent *gethostbyname(const char *name);
14
15       #include <sys/socket.h>       /* for AF_INET */
16       struct hostent *
17       gethostbyaddr(const void *addr, int len, int type);
18
19       void sethostent(int stayopen);
20
21       void endhostent(void);
22
23       void herror(const char *s);
24
25       const char *hstrerror(int err);
26
27
28       /* System V/POSIX extension */
29       struct hostent *gethostent(void);
30
31
32       /* GNU extensions */
33       struct hostent *gethostbyname2(const char *name, int af);
34
35       int gethostent_r(
36         struct hostent *ret, char *buf, size_t buflen,
37         struct hostent **result, int *h_errnop);
38
39       int gethostbyname_r(const char *name,
40         struct hostent *ret, char *buf, size_t buflen,
41         struct hostent **result, int *h_errnop);
42
43       int gethostbyname2_r(const char *name, int af,
44         struct hostent *ret, char *buf, size_t buflen,
45         struct hostent **result, int *h_errnop);
46

DESCRIPTION

48       The gethostbyname() function returns a structure of  type  hostent  for
49       the  given  host  name.   Here  name  is either a host name, or an IPv4
50       address in standard dot notation, or an IPv6 address in colon (and pos‐
51       sibly  dot)  notation.   (See  RFC 1884  for  the  description  of IPv6
52       addresses.)  If name is an IPv4 or IPv6 address, no lookup is performed
53       and  gethostbyname()  simply  copies name into the h_name field and its
54       struct in_addr equivalent into the h_addr_list[0] field of the returned
55       hostent  structure.   If  name doesn't end in a dot and the environment
56       variable HOSTALIASES is set, the alias file pointed to  by  HOSTALIASES
57       will  first be searched for name (see hostname(7) for the file format).
58       The current domain and its parents are searched unless name ends  in  a
59       dot.
60
61       The  gethostbyaddr()  function  returns a structure of type hostent for
62       the given host address addr of length len and address type type.  Valid
63       address types are AF_INET and AF_INET6.  The host address argument is a
64       pointer to a struct of a type depending on the address type, for  exam‐
65       ple  a  struct  in_addr * (probably obtained via a call to inet_addr())
66       for address type AF_INET.
67
68       The sethostent() function specifies, if stayopen is true  (1),  that  a
69       connected  TCP  socket  should  be used for the name server queries and
70       that the connection should remain open during successive queries.  Oth‐
71       erwise, name server queries will use UDP datagrams.
72
73       The  endhostent()  function  ends  the use of a TCP connection for name
74       server queries.
75
76       The (obsolete) herror() function prints the  error  message  associated
77       with the current value of h_errno on stderr.
78
79       The  (obsolete)  hstrerror()  function takes an