Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / lib / nsswitch / mdns / common / gethostent6.c
blobe4288de82b746eafee8a6e28e776d1828d1b69f7
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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.
40 static nss_status_t
41 getbyname(be, a)
42 mdns_backend_ptr_t be;
43 void *a;
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));
51 qdata.argp = argp;
53 _nss_mdns_updatecfg(be);
54 return (_nss_mdns_querybyname(be, hname, af, &qdata));
57 static nss_status_t
58 getbyaddr(be, a)
59 mdns_backend_ptr_t be;
60 void *a;
62 int i;
63 char ch;
64 char *chptr;
65 uint8_t *p;
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));
73 qdata.argp = argp;
74 argp->h_errno = 0;
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);
90 qdata.af = AF_INET;
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]);
94 } else {
95 if (inet_ntop(AF_INET6, (void *)addr,
96 (void *)qdata.paddrbuf,
97 sizeof (qdata.paddrbuf)) == NULL)
98 return (NSS_NOTFOUND);
99 qdata.af = AF_INET6;
100 chptr = addrqryname;
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));
114 /*ARGSUSED*/
115 static nss_status_t
116 _nss_mdns_getent(be, args)
117 mdns_backend_ptr_t be;
118 void *args;
120 return (NSS_UNAVAIL);
123 /*ARGSUSED*/
124 static nss_status_t
125 _nss_mdns_setent(be, dummy)
126 mdns_backend_ptr_t be;
127 void *dummy;
129 return (NSS_UNAVAIL);
132 /*ARGSUSED*/
133 static nss_status_t
134 _nss_mdns_endent(be, dummy)
135 mdns_backend_ptr_t be;
136 void *dummy;
138 return (NSS_UNAVAIL);
141 /*ARGSUSED*/
142 static nss_status_t
143 _nss_mdns_ipnodes_destr(be, dummy)
144 mdns_backend_ptr_t be;
145 void *dummy;
147 _nss_mdns_destr(be);
148 return (NSS_SUCCESS);
151 static mdns_backend_op_t ipnodes_ops[] = {
152 _nss_mdns_ipnodes_destr,
153 _nss_mdns_endent,
154 _nss_mdns_setent,
155 _nss_mdns_getent,
156 getbyname,
157 getbyaddr,
160 /*ARGSUSED*/
161 nss_backend_t *
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])));
169 /*ARGSUSED*/
170 nss_status_t
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));