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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "mdns_common.h"
32 * gethostby* functions for the ipnodes database. The ipnodes
33 * database stores both IPv4 and IPv6 address information.
34 * mDNS query functions to perform the host lookup are
35 * in mdns/common/mdns_common.c file.
36 * _nss_mdns_ipnodes_constr is called to initialize
37 * the nsswitch backend data structures.
42 mdns_backend_ptr_t be
;
45 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
46 int af
= argp
->key
.ipnode
.af_family
;
47 char *hname
= (char *)argp
->key
.ipnode
.name
;
48 struct mdns_querydata qdata
;
50 (void) memset(&qdata
, 0, sizeof (struct mdns_querydata
));
53 _nss_mdns_updatecfg(be
);
54 return (_nss_mdns_querybyname(be
, hname
, af
, &qdata
));
59 mdns_backend_ptr_t be
;
66 struct in6_addr
*addr
;
67 struct mdns_querydata qdata
;
68 char addrqryname
[ sizeof ("f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f") + \
69 sizeof (".f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.ip6.arpa.")];
70 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
72 (void) memset(&qdata
, 0, sizeof (struct mdns_querydata
));
76 if ((argp
->key
.hostaddr
.type
!= AF_INET6
) ||
77 (argp
->key
.hostaddr
.len
!= sizeof (*addr
)))
78 return (NSS_NOTFOUND
);
80 /* LINTED E_BAD_PTR_CAST_ALIGN */
81 addr
= (struct in6_addr
*)(argp
->key
.hostaddr
.addr
);
83 if (IN6_IS_ADDR_V4MAPPED(addr
)) {
84 struct in_addr ipv4addr
;
86 IN6_V4MAPPED_TO_INADDR(addr
, &ipv4addr
);
87 if (inet_ntop(AF_INET
, (void *) &ipv4addr
.s_addr
,
88 (void *)qdata
.paddrbuf
, sizeof (qdata
.paddrbuf
)) == NULL
)
89 return (NSS_NOTFOUND
);
91 p
= (uint8_t *)&ipv4addr
.s_addr
;
92 (void) snprintf(addrqryname
, sizeof (addrqryname
),
93 "%u.%u.%u.%u.in-addr.arpa.", p
[3], p
[2], p
[1], p
[0]);
95 if (inet_ntop(AF_INET6
, (void *)addr
,
96 (void *)qdata
.paddrbuf
,
97 sizeof (qdata
.paddrbuf
)) == NULL
)
98 return (NSS_NOTFOUND
);
101 for (i
= 0; i
< 16; i
++)
103 ch
= ((char *)addr
)[15-i
];
104 chptr
+= snprintf(chptr
, sizeof (addrqryname
)-i
*4,
105 "%X.%X.", ch
&0x0f, (ch
>>4)&0x0f);
107 (void) strlcpy(chptr
, "ip6.arpa.", sizeof (addrqryname
)-64);
110 _nss_mdns_updatecfg(be
);
111 return (_nss_mdns_querybyaddr(be
, addrqryname
, qdata
.af
, &qdata
));
116 _nss_mdns_getent(be
, args
)
117 mdns_backend_ptr_t be
;
120 return (NSS_UNAVAIL
);
125 _nss_mdns_setent(be
, dummy
)
126 mdns_backend_ptr_t be
;
129 return (NSS_UNAVAIL
);
134 _nss_mdns_endent(be
, dummy
)
135 mdns_backend_ptr_t be
;
138 return (NSS_UNAVAIL
);
143 _nss_mdns_ipnodes_destr(be
, dummy
)
144 mdns_backend_ptr_t be
;
148 return (NSS_SUCCESS
);
151 static mdns_backend_op_t ipnodes_ops
[] = {
152 _nss_mdns_ipnodes_destr
,
162 _nss_mdns_ipnodes_constr(dummy1
, dummy2
, dummy3
)
163 const char *dummy1
, *dummy2
, *dummy3
;
165 return (_nss_mdns_constr(ipnodes_ops
,
166 sizeof (ipnodes_ops
) / sizeof (ipnodes_ops
[0])));
171 _nss_get_mdns_ipnodes_name(mdns_backend_ptr_t
*be
, void **bufp
, size_t *sizep
)
173 return (_nss_mdns_gethost_withttl(*bufp
, *sizep
, 1));