pmap_rmt.c revision 136581
1/* $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $ */ 2 3/* 4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5 * unrestricted use provided that this legend is included on all tape 6 * media and as a part of the software program in whole or part. Users 7 * may copy or modify Sun RPC without charge, but are not authorized 8 * to license or distribute it to anyone else except as part of a product or 9 * program developed by the user. 10 * 11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 * 15 * Sun RPC is provided with no support and without any obligation on the 16 * part of Sun Microsystems, Inc. to assist in its use, correction, 17 * modification or enhancement. 18 * 19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 * OR ANY PART THEREOF. 22 * 23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 * or profits or other special, indirect and consequential damages, even if 25 * Sun has been advised of the possibility of such damages. 26 * 27 * Sun Microsystems, Inc. 28 * 2550 Garcia Avenue 29 * Mountain View, California 94043 30 */ 31 32#if defined(LIBC_SCCS) && !defined(lint) 33static char *sccsid2 = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro"; 34static char *sccsid = "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC"; 35#endif 36#include <sys/cdefs.h> 37__FBSDID("$FreeBSD: head/lib/libc/rpc/pmap_rmt.c 136581 2004-10-16 06:11:35Z obrien $"); 38 39/* 40 * pmap_rmt.c 41 * Client interface to pmap rpc service. 42 * remote call and broadcast service 43 * 44 * Copyright (C) 1984, Sun Microsystems, Inc. 45 */ 46 47#include "namespace.h" 48#include <sys/types.h> 49#include <sys/ioctl.h> 50#include <sys/poll.h> 51#include <sys/socket.h> 52 53#include <net/if.h> 54#include <netinet/in.h> 55#include <arpa/inet.h> 56 57#include <assert.h> 58#include <err.h> 59#include <errno.h> 60#include <stdio.h> 61#include <string.h> 62#include <unistd.h> 63 64#include <rpc/rpc.h> 65#include <rpc/pmap_prot.h> 66#include <rpc/pmap_clnt.h> 67#include <rpc/pmap_rmt.h> 68#include "un-namespace.h" 69 70static const struct timeval timeout = { 3, 0 }; 71 72/* 73 * pmapper remote-call-service interface. 74 * This routine is used to call the pmapper remote call service 75 * which will look up a service program in the port maps, and then 76 * remotely call that routine with the given parameters. This allows 77 * programs to do a lookup and call in one step. 78*/ 79enum clnt_stat 80pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, 81 port_ptr) 82 struct sockaddr_in *addr; 83 u_long prog, vers, proc; 84 xdrproc_t xdrargs, xdrres; 85 caddr_t argsp, resp; 86 struct timeval tout; 87 u_long *port_ptr; 88{ 89 int sock = -1; 90 CLIENT *client; 91 struct rmtcallargs a; 92 struct rmtcallres r; 93 enum clnt_stat stat; 94 95 assert(addr != NULL); 96 assert(port_ptr != NULL); 97 98 addr->sin_port = htons(PMAPPORT); 99 client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock); 100 if (client != NULL) { 101 a.prog = prog; 102 a.vers = vers; 103 a.proc = proc; 104 a.args_ptr = argsp; 105 a.xdr_args = xdrargs; 106 r.port_ptr = port_ptr; 107 r.results_ptr = resp; 108 r.xdr_results = xdrres; 109 stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT, 110 (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres, 111 &r, tout); 112 CLNT_DESTROY(client); 113 } else { 114 stat = RPC_FAILED; 115 } 116 addr->sin_port = 0; 117 return (stat); 118} 119 120 121/* 122 * XDR remote call arguments 123 * written for XDR_ENCODE direction only 124 */ 125bool_t 126xdr_rmtcall_args(xdrs, cap) 127 XDR *xdrs; 128 struct rmtcallargs *cap; 129{ 130 u_int lenposition, argposition, position; 131 132 assert(xdrs != NULL); 133 assert(cap != NULL); 134 135 if (xdr_u_long(xdrs, &(cap->prog)) && 136 xdr_u_long(xdrs, &(cap->vers)) && 137 xdr_u_long(xdrs, &(cap->proc))) { 138 lenposition = XDR_GETPOS(xdrs); 139 if (! xdr_u_long(xdrs, &(cap->arglen))) 140 return (FALSE); 141 argposition = XDR_GETPOS(xdrs); 142 if (! (*(cap->xdr_args))(xdrs, cap->args_ptr)) 143 return (FALSE); 144 position = XDR_GETPOS(xdrs); 145 cap->arglen = (u_long)position - (u_long)argposition; 146 XDR_SETPOS(xdrs, lenposition); 147 if (! xdr_u_long(xdrs, &(cap->arglen))) 148 return (FALSE); 149 XDR_SETPOS(xdrs, position); 150 return (TRUE); 151 } 152 return (FALSE); 153} 154 155/* 156 * XDR remote call results 157 * written for XDR_DECODE direction only 158 */ 159bool_t 160xdr_rmtcallres(xdrs, crp) 161 XDR *xdrs; 162 struct rmtcallres *crp; 163{ 164 caddr_t port_ptr; 165 166 assert(xdrs != NULL); 167 assert(crp != NULL); 168 169 port_ptr = (caddr_t)(void *)crp->port_ptr; 170 if (xdr_reference(xdrs, &port_ptr, sizeof (u_long), 171 (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) { 172 crp->port_ptr = (u_long *)(void *)port_ptr; 173 return ((*(crp->xdr_results))(xdrs, crp->results_ptr)); 174 } 175 return (FALSE); 176} 177