gethostent.3n (2010 09)
g
gethostent(3N) gethostent(3N)
hp=gethostbyaddr((char *) &addr, sizeof (addr), AF_INET);
if (hp == NULL) {
(void) printf("host information for %s no found \n", argv[1]);
exit (3);
}
for (p = hp->h_addr_list; *p!=0;p++){
struct in_addr in;
char **q;
(void)memcpy(&in.s_addr, *p, sizeof(in.s_addr));
(void)printf("%s\t%s",inet_ntoa(in), hp->h_name);
for (q=hp->h_aliases;*q != 0; q++)
(void) printf("%s", *q);
(void)putchar(’\n’);
}
exit (0);
}
WARNINGS
Programs that use the interfaces described in this manpage cannot be linked statically because the imple-
mentations of these functions employ dynamic loading and linking of shared objects at run time.
h_errno is referenced as an extern int for single thread applications and is defined as function call
macro for multithreaded applications in file
/usr/include/netdb.h. Applications that reference
h_errno need to include /usr/include/netdb.h
.
OBSOLESCENT INTERFACES
int gethostent_r(struct hostent *result,
struct hostent_data *buffer);
int gethostbyname_r(const char *name,
struct hostent *result,
struct hostent_data *buffer);
int gethostbyaddr_r(const char *addr,
int len,
int type,
struct hostent *result,
struct hostent_data *buffer);
int sethostent_r(int stayopen, struct hostent_data *buffer);
int endhostent_r(struct hostent_data *buffer);
The above reentrant interfaces have been moved from libc to libd4r. They are included to support
existing applications and may be removed in the future release. New multithreaded applications should
use the regular APIs (those without the -r suffix).
The reentrant interfaces function the same as the regular interfaces without the
-r suffix. However,
gethostent_r(), gethostbyname_r(), and
gethostbyaddr_r() expect to be passed the
address of a
struct hostent and will store the address of the result at the supplied parameter. The
passed in address of struct hostent_data in the reentrant interfaces cannot be a NULL pointer.
The reentrant routines return
-1 if the operation is unsuccessful, or, in the case of gethostent_r()
,if
the end of the hosts list has been reached.
0 is returned otherwise.
AUTHOR
gethostent() was developed by Sun Microsystems Inc.
FILES
/etc/hosts
SEE ALSO
named(1M), ypserv(1M), resolver(3N), ypclnt(3C), hosts(4), nsswitch.conf(4), ypfiles(4), thread_safety(5).
4 Hewlett-Packard Company − 4 − HP-UX 11i Version 3: September 2010