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