1GETHOSTBYNAME(3) Linux Programmer's Manual GETHOSTBYNAME(3)
2
3
4
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
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 Since glibc 2.19:
55 _DEFAULT_SOURCE
56 Glibc versions up to and including 2.19:
57 _BSD_SOURCE || _SVID_SOURCE
58
59 herror(), hstrerror():
60 Since glibc 2.19:
61 _DEFAULT_SOURCE
62 Glibc 2.8 to 2.19:
63 _BSD_SOURCE || _SVID_SOURCE
64 Before glibc 2.8:
65 none
66
67 h_errno:
68 Since glibc 2.19
69 _DEFAULT_SOURCE || _POSIX_C_SOURCE < 200809L
70 Glibc 2.12 to 2.19:
71 _BSD_SOURCE || _SVID_SOURCE || _POSIX_C_SOURCE < 200809L
72 Before glibc 2.12:
73 none
74
76 The gethostbyname*(), gethostbyaddr*(), herror(), and hstrerror() func‐
77 tions are obsolete. Applications should use getaddrinfo(3), getname‐
78 info(3), and gai_strerror(3) instead.
79
80 The gethostbyname() function returns a structure of type hostent for
81 the given host name. Here name is either a hostname or an IPv4 address
82 in standard dot notation (as for inet_addr(3)). If name is an IPv4
83 address, no lookup is performed and gethostbyname() simply copies name
84 into the h_name field and its struct in_addr equivalent into the
85 h_addr_list[0] field of the returned hostent structure. If name
86 doesn't end in a dot and the environment variable HOSTALIASES is set,
87 the alias file pointed to by HOSTALIASES will first be searched for
88 name (see hostname(7) for the file format). The current domain and its
89 parents are searched u