4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Routines to handle getnet* calls in nscd
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
40 #define nam_db ctx->nsc_db[0]
41 #define addr_db ctx->nsc_db[1]
43 #define NSC_NAME_NETWORKS_BYNAME "getnetbyname"
44 #define NSC_NAME_NETWORKS_BYADDR "getnetbyaddr"
46 static int netaddr_compar(const void *, const void *);
47 static uint_t
netaddr_gethash(nss_XbyY_key_t
*, int);
48 static void netaddr_getlogstr(char *, char *, size_t, nss_XbyY_args_t
*);
51 net_init_ctx(nsc_ctx_t
*ctx
) {
52 ctx
->dbname
= NSS_DBNAM_NETWORKS
;
54 ctx
->file_name
= "/etc/inet/networks";
56 nam_db
= make_cache(nsc_key_ces
,
57 NSS_DBOP_NETWORKS_BYNAME
,
58 NSC_NAME_NETWORKS_BYNAME
,
59 NULL
, NULL
, NULL
, nsc_ht_default
, -1);
61 addr_db
= make_cache(nsc_key_other
,
62 NSS_DBOP_NETWORKS_BYADDR
,
63 NSC_NAME_NETWORKS_BYADDR
,
66 netaddr_gethash
, nsc_ht_default
, -1);
70 netaddr_getlogstr(char *name
, char *whoami
, size_t len
, nss_XbyY_args_t
*argp
) {
71 if (argp
->key
.netaddr
.type
== AF_INET
) {
75 net
= htonl(argp
->key
.netaddr
.net
);
79 (void) snprintf(whoami
, len
, "%s [key=%d.%d.%d.%d]",
81 up
[0], up
[1], up
[2], up
[3]);
83 (void) snprintf(whoami
, len
, "%s [key=%d.%d.%d]",
87 (void) snprintf(whoami
, len
, "%s [key=%d.%d]",
91 (void) snprintf(whoami
, len
, "%s [key=%d]",
95 (void) snprintf(whoami
, len
, "%s [key=%d, %d]",
97 argp
->key
.netaddr
.net
, argp
->key
.netaddr
.type
);
102 netaddr_compar(const void *n1
, const void *n2
) {
103 nsc_entry_t
*e1
, *e2
;
105 e1
= (nsc_entry_t
*)n1
;
106 e2
= (nsc_entry_t
*)n2
;
108 if (e1
->key
.netaddr
.type
> e2
->key
.netaddr
.type
)
110 else if (e1
->key
.netaddr
.type
< e2
->key
.netaddr
.type
)
113 return (_NSC_INT_KEY_CMP(e1
->key
.netaddr
.net
, e2
->key
.netaddr
.net
));
117 netaddr_gethash(nss_XbyY_key_t
*key
, int htsize
) {
118 return (db_gethash(&key
->netaddr
.net
,
119 sizeof (key
->netaddr
.net
), htsize
));