xref: /titanic_44/usr/src/lib/nsswitch/nis/common/ether_addr.c (revision cb5caa98562cf06753163f558cbcfe30b8f4673a)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  *	nis/ether_addr.c -- "nis" backend for nsswitch "ethers" database
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 /*
31  * All routines necessary to deal with the ethers NIS maps.  The maps
32  * contain mapping between 48 bit ethernet addresses and their corresponding
33  * hosts name.  The addresses have an ascii representation of the form
34  * "x:x:x:x:x:x" where x is a hex number between 0x00 and 0xff;  the
35  * bytes are always in network order.
36  */
37 
38 #include <stdio.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42 #include <netinet/in.h>
43 #include <net/if_arp.h>
44 #include <netinet/if_ether.h>
45 #include <nss_dbdefs.h>
46 #include "nis_common.h"
47 
48 static nss_status_t
getbyhost(be,a)49 getbyhost(be, a)
50 	nis_backend_ptr_t	be;
51 	void			*a;
52 {
53 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
54 
55 	return (_nss_nis_lookup(be, argp, 0, "ethers.byname",
56 		argp->key.name, 0));
57 }
58 
59 static nss_status_t
getbyether(be,a)60 getbyether(be, a)
61 	nis_backend_ptr_t	be;
62 	void			*a;
63 {
64 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
65 	char	etherstr[18];
66 	uchar_t	*e = argp->key.ether;
67 
68 	(void) snprintf(etherstr, 18, "%x:%x:%x:%x:%x:%x",
69 		*e, *(e + 1), *(e + 2), *(e + 3), *(e + 4), *(e + 5));
70 	return (_nss_nis_lookup(be, argp, 0, "ethers.byaddr", etherstr, 0));
71 }
72 
73 static nis_backend_op_t ethers_ops[] = {
74 	_nss_nis_destr,
75 	getbyhost,
76 	getbyether
77 };
78 
79 /*ARGSUSED*/
80 nss_backend_t *
_nss_nis_ethers_constr(dummy1,dummy2,dummy3)81 _nss_nis_ethers_constr(dummy1, dummy2, dummy3)
82 	const char	*dummy1, *dummy2, *dummy3;
83 {
84 	return (_nss_nis_constr(ethers_ops,
85 			sizeof (ethers_ops) / sizeof (ethers_ops[0]),
86 			"ethers.byaddr"));
87 }
88