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 #ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1994, by Sun Microsystems, Inc.
26 * All rights reserved.
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
40 * Print a network number such as 129.144
43 inet_nettoa(struct in_addr in
)
45 u_long addr
= htonl(in
.s_addr
);
46 u_char
*up
= (u_char
*)&addr
;
47 static char result
[256];
49 /* Omit leading zeros */
51 (void) sprintf(result
, "%d.%d.%d.%d",
52 up
[0], up
[1], up
[2], up
[3]);
54 (void) sprintf(result
, "%d.%d.%d", up
[1], up
[2], up
[3]);
56 (void) sprintf(result
, "%d.%d", up
[2], up
[3]);
58 (void) sprintf(result
, "%d", up
[3]);
64 putnetent(const struct netent
*np
, FILE *fp
)
74 in
.s_addr
= np
->n_net
;
75 if (fprintf(fp
, "%-20s %s",
76 np
->n_name
, inet_nettoa(in
)) == EOF
)
78 for (p
= np
->n_aliases
; *p
!= 0; p
++) {
79 if (fprintf(fp
, " %s", *p
) == EOF
)
82 if (putc('\n', fp
) == EOF
)
88 * getnetbyname/addr - get entries from network database
91 dogetnet(const char **list
)
96 if (list
== NULL
|| *list
== NULL
) {
97 while ((np
= getnetent()) != NULL
)
98 (void) putnetent(np
, stdout
);
100 for (; *list
!= NULL
; list
++) {
101 long addr
= inet_network(*list
);
103 np
= getnetbyaddr(addr
, AF_INET
);
105 np
= getnetbyname(*list
);
107 rc
= EXC_NAME_NOT_FOUND
;
109 (void) putnetent(np
, stdout
);