4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 #pragma ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1994-2000 by Sun Microsystems, Inc.
26 * All rights reserved.
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
40 puthostent(const struct hostent
*hp
, FILE *fp
)
49 for (p
= hp
->h_addr_list
; *p
!= 0; p
++) {
53 (void) memcpy((char *)&in
.s_addr
, *p
, sizeof (in
));
54 if (fprintf(fp
, "%s\t%s",
55 inet_ntoa(in
), hp
->h_name
) == EOF
)
57 for (q
= hp
->h_aliases
; *q
!= 0; q
++) {
58 if (fprintf(fp
, " %s", *q
) == EOF
)
61 if (putc('\n', fp
) == EOF
)
68 * gethostbyname/addr - get entries from hosts database
71 dogethost(const char **list
)
76 if (list
== NULL
|| *list
== NULL
) {
77 while ((hp
= gethostent()) != NULL
)
78 (void) puthostent(hp
, stdout
);
80 for (; *list
!= NULL
; list
++) {
82 addr
.s_addr
= inet_addr(*list
);
83 if (addr
.s_addr
!= (in_addr_t
)-1)
84 hp
= gethostbyaddr((char *)&addr
,
85 sizeof (addr
), AF_INET
);
87 hp
= gethostbyname(*list
);
89 rc
= EXC_NAME_NOT_FOUND
;
91 (void) puthostent(hp
, stdout
);