xref: /illumos-gate/usr/src/lib/nsswitch/nis/common/getprotoent.c (revision d48be21240dfd051b689384ce2b23479d757f2d8)
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/getprotoent.c -- "nis" backend for nsswitch "protocols" database
24  *
25  *	Copyright (c) 1988-1992 Sun Microsystems Inc
26  *	All Rights Reserved.
27  */
28 
29 #include <stdio.h>
30 #include "nis_common.h"
31 #include <synch.h>
32 #include <netdb.h>
33 #include <string.h>
34 
35 static nss_status_t
36 getbyname(be, a)
37 	nis_backend_ptr_t	be;
38 	void			*a;
39 {
40 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
41 
42 	return (_nss_nis_lookup(be, argp, 1, "protocols.byname",
43 		argp->key.name, 0));
44 }
45 
46 static nss_status_t
47 getbynumber(be, a)
48 	nis_backend_ptr_t	be;
49 	void			*a;
50 {
51 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
52 	char			numstr[12];
53 
54 	(void) sprintf(numstr, "%d", argp->key.number);
55 	return (_nss_nis_lookup(be, argp, 1, "protocols.bynumber",
56 				numstr, 0));
57 }
58 
59 static nis_backend_op_t proto_ops[] = {
60 	_nss_nis_destr,
61 	_nss_nis_endent,
62 	_nss_nis_setent,
63 	_nss_nis_getent_netdb,
64 	getbyname,
65 	getbynumber
66 };
67 
68 /*ARGSUSED*/
69 nss_backend_t *
70 _nss_nis_protocols_constr(dummy1, dummy2, dummy3)
71 	const char	*dummy1, *dummy2, *dummy3;
72 {
73 	return (_nss_nis_constr(proto_ops,
74 				sizeof (proto_ops) / sizeof (proto_ops[0]),
75 				"protocols.bynumber"));
76 }
77