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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Routines used by ypserv
28  */
29 
30 #include <rpc/rpc.h>
31 #include <netdb.h>
32 #include <rpcsvc/yp_prot.h>
33 #include <errno.h>
34 #include <sys/types.h>
35 #include "ypserv_resolv_common.h"
36 
37 #ifdef TDRPC
38 extern int sys_nerr;
39 extern char *sys_errlist[];
40 extern int errno;
41 
42 char *
strerror(err)43 strerror(err)	/* no 4.1.3 strerror() */
44 int err;
45 {
46 	if (err > 0 && err < sys_nerr)
47 		return (sys_errlist[err]);
48 	else
49 		return ((char *) NULL);
50 }
51 #endif
52 
53 bool_t
xdr_ypfwdreq_key4(XDR * xdrs,struct ypfwdreq_key4 * ps)54 xdr_ypfwdreq_key4(XDR *xdrs, struct ypfwdreq_key4 *ps)
55 {
56 	return (xdr_ypmap_wrap_string(xdrs, &ps->map) &&
57 		xdr_datum(xdrs, &ps->keydat) &&
58 		xdr_u_long(xdrs, &ps->xid) &&
59 		xdr_u_long(xdrs, &ps->ip) &&
60 		xdr_u_short(xdrs, &ps->port));
61 }
62 
63 
64 bool_t
xdr_ypfwdreq_key6(XDR * xdrs,struct ypfwdreq_key6 * ps)65 xdr_ypfwdreq_key6(XDR *xdrs, struct ypfwdreq_key6 *ps)
66 {
67 	u_int	addrsize = sizeof (struct in6_addr)/sizeof (uint32_t);
68 	char	**addrp = (caddr_t *)&(ps->addr);
69 
70 	return (xdr_ypmap_wrap_string(xdrs, &ps->map) &&
71 		xdr_datum(xdrs, &ps->keydat) &&
72 		xdr_u_long(xdrs, &ps->xid) &&
73 		xdr_array(xdrs, addrp, &addrsize, addrsize,
74 			sizeof (uint32_t), xdr_uint32_t) &&
75 		xdr_u_short(xdrs, &ps->port));
76 }
77 
78 
79 u_long
svc_getxid(SVCXPRT * xprt)80 svc_getxid(SVCXPRT *xprt)
81 {
82 	struct svc_dg_data *su = get_svc_dg_data(xprt);
83 	if (su == NULL)
84 		return (0);
85 
86 	return (su->su_xid);
87 }
88