HP-UX Reference (11i v1 00/12) - 3 Library Functions A-M (vol 6)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
g
gethostent(3N) gethostent(3N)
#include <netdb.h>
#include <netinet/in.h>
main(int argc, const char **argv)
{
u_int addr;
struct hostent *hp;
char **p;
if (argc != 2) {
(void) printf("usage: %s IP-address\n",argv[0]);
exit (1);
}
if ((int) (addr = inet_addr (argv[1])) == -1) {
(void) printf("IP-address must be of the form a.b.c.d\n");
exit (2);
}
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).
HP-UX Release 11i: December 2000 − 4 − Section 3−−305
___
___