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