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

NAME

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

SYNOPSIS

11       #include <netdb.h>
12
13       extern int h_errno;
14
15       struct hostent *gethostbyname(const char *name);
16       struct hostent *gethostbyaddr(const void *addr,
17                                     socklen_t len, int type);
18
19       void sethostent(int stayopen);
20       void endhostent(void);
21
22       void herror(const char *s);
23       const char *hstrerror(int err);
24
25       /* System V/POSIX extension */
26       struct hostent *gethostent(void);
27
28       /* GNU extensions */
29       struct hostent *gethostbyname2(const char *name, int af);
30
31       int gethostent_r(struct hostent *restrict ret,
32                        char *restrict buf, size_t buflen,
33                        struct hostent **restrict result,
34                        int *restrict h_errnop);
35
36       int gethostbyaddr_r(const void *restrict addr, socklen_t len, int type,
37                        struct hostent *restrict ret,
38                        char *restrict buf, size_t buflen,
39                        struct hostent **restrict result,
40                        int *restrict h_errnop);
41       int gethostbyname_r(const char *restrict name,
42                        struct hostent *restrict ret,
43                        char *restrict buf, size_t buflen,
44                        struct hostent **restrict result,
45                        int *restrict h_errnop);
46       int gethostbyname2_r(const char *restrict name, int af,
47                        struct hostent *restrict ret,
48                        char *restrict buf, size_t buflen,
49                        struct hostent **restrict result,
50                        int *restrict h_errnop);
51
52   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
53
54       gethostbyname2(), gethostent_r(), gethostbyaddr_r(), gethostbyname_r(),
55       gethostbyname2_r():
56           Since glibc 2.19:
57               _DEFAULT_SOURCE
58           Glibc up to and including 2.19:
59               _BSD_SOURCE || _SVID_SOURCE
60
61       herror(), hstrerror():
62           Since glibc 2.19:
63               _DEFAULT_SOURCE
64           Glibc 2.8 to 2.19:
65               _BSD_SOURCE || _SVID_SOURCE
66           Before glibc 2.8:
67               none
68
69       h_errno:
70           Since glibc 2.19
71               _DEFAULT_SOURCE || _POSIX_C_SOURCE < 200809L
72           Glibc 2.12 to 2.19:
73               _BSD_SOURCE || _SVID_SOURCE || _POSIX_C_SOURCE < 200809L
74           Before glibc 2.12:
75               none
76

DESCRIPTION

78       The gethostbyname*(), gethostbyaddr*(), herror(), and hstrerror() func‐
79       tions  are  obsolete.  Applications should use getaddrinfo(3), getname‐
80       info(3), and gai_strerror(3) instead.
81
82       The gethostbyname() function returns a structure of  type  hostent  for
83       the given host name.  Here name is either a hostname or an IPv4 address
84       in standard dot notation (as for inet_addr(3)).  If name is an IPv4 ad‐
85       dress,  no  lookup  is performed and gethostbyname() simply copies name
86       into the h_name field  and  its  struct  in_addr  equivalent  into  the
87       h_addr_list[0]  field  of  the  returned  hostent  structure.   If name
88       doesn't end in a dot and the environment variable HOSTALIASES  is  set,
89       the  alias  file  pointed  to by HOSTALIASES will first be searched for
90       name (see hostname(7) for the file format).  The current domain and its