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():
54           _BSD_SOURCE || _SVID_SOURCE
55
56       herror(), hstrerror():
57           Since glibc 2.8:
58               _BSD_SOURCE || _SVID_SOURCE || _GNU_SOURCE
59           Before glibc 2.8:
60               none
61

DESCRIPTION

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