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

NAME

6       gethostbyname,   gethostbyaddr,   sethostent,  gethostent,  endhostent,
7       h_errno, herror, hstrerror, gethostbyaddr_r, gethostbyname2, gethostby‐
8       name2_r, gethostbyname_r, gethostent_r - get network host entry
9

SYNOPSIS

11       #include <netdb.h>
12       extern int h_errno;
13
14       struct hostent *gethostbyname(const char *name);
15
16       #include <sys/socket.h>       /* for AF_INET */
17       struct hostent *gethostbyaddr(const void *addr,
18                                     socklen_t len, int type);
19
20       void sethostent(int stayopen);
21
22       void endhostent(void);
23
24       void herror(const char *s);
25
26       const char *hstrerror(int err);
27
28       /* System V/POSIX extension */
29       struct hostent *gethostent(void);
30
31       /* GNU extensions */
32       struct hostent *gethostbyname2(const char *name, int af);
33
34       int gethostent_r(
35               struct hostent *ret, char *buf, size_t buflen,
36               struct hostent **result, int *h_errnop);
37
38       int gethostbyaddr_r(const void *addr, socklen_t len, int type,
39               struct hostent *ret, char *buf, size_t buflen,
40               struct hostent **result, int *h_errnop);
41
42       int gethostbyname_r(const char *name,
43               struct hostent *ret, char *buf, size_t buflen,
44               struct hostent **result, int *h_errnop);
45
46       int gethostbyname2_r(const char *name, int af,
47               struct hostent *ret, char *buf, size_t buflen,
48               struct hostent **result, int *h_errnop);
49
50   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
51
52       gethostbyname2(), gethostent_r(), gethostbyaddr_r(), gethostbyname_r(),
53       gethostbyname2_r(): _BSD_SOURCE || _SVID_SOURCE
54
55       herror(), hstrerror() (since glibc 2.8): _BSD_SOURCE || _SVID_SOURCE ||
56       _GNU_SOURCE
57

DESCRIPTION

59       The  gethostbyname*()  and  gethostbyaddr*()  functions  are  obsolete.
60       Applications should use getaddrinfo(3) and getnameinfo(3) instead.
61
62       The gethostbyname() function returns a structure of  type  hostent  for
63       the  given  host  name.   Here  name  is  either a hostname, or an IPv4
64       address in standard dot notation (as  for  inet_addr(3)),  or  an  IPv6
65       address  in  colon  (and possibly dot) notation.  (See RFC 1884 for the
66       description of IPv6 addresses.)  If name is an IPv4 or IPv6 address, no
67       lookup  is  performed  and  gethostbyname() simply copies name into the
68       h_name field and its struct in_addr equivalent into the  h_addr_list[0]
69       field  of the returned hostent structure.  If name doesn't end in a dot
70       and the environment variable HOSTALIASES is set, the alias file pointed
71       to  by HOSTALIASES will first be searched for name (see hostname(7) for
72       the file format).  The current domain  and  its  parents  are  searched
73       unless name ends in a dot.
74
75       The  gethostbyaddr()  function  returns a structure of type hostent for
76       the given host address addr of length len and address type type.  Valid
77       address types are AF_INET and AF_INET6.  The host address argument is a
78       pointer to a struct of a type depending on the address type, for  exam‐
79       ple  a  struct in_addr * (probably