pmap_rmt.c revision 74462
150276Speter/* $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $ */ 2166124Srafan 350276Speter/* 450276Speter * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 550276Speter * unrestricted use provided that this legend is included on all tape 650276Speter * media and as a part of the software program in whole or part. Users 750276Speter * may copy or modify Sun RPC without charge, but are not authorized 850276Speter * to license or distribute it to anyone else except as part of a product or 950276Speter * program developed by the user. 1050276Speter * 1150276Speter * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1250276Speter * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 1350276Speter * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 1450276Speter * 1550276Speter * Sun RPC is provided with no support and without any obligation on the 1650276Speter * part of Sun Microsystems, Inc. to assist in its use, correction, 1750276Speter * modification or enhancement. 1850276Speter * 1950276Speter * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 2050276Speter * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 2150276Speter * OR ANY PART THEREOF. 2250276Speter * 2350276Speter * In no event will Sun Microsystems, Inc. be liable for any lost revenue 2450276Speter * or profits or other special, indirect and consequential damages, even if 2550276Speter * Sun has been advised of the possibility of such damages. 2650276Speter * 2750276Speter * Sun Microsystems, Inc. 2850276Speter * 2550 Garcia Avenue 2950276Speter * Mountain View, California 94043 3050276Speter */ 3150276Speter 32166124Srafan#include <sys/cdefs.h> 33166124Srafan#if defined(LIBC_SCCS) && !defined(lint) 3450276Speter/*static char *sccsid = "from: @(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";*/ 3550276Speter/*static char *sccsid = "from: @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";*/ 3650276Speterstatic char *rcsid = "$FreeBSD: head/lib/libc/rpc/pmap_rmt.c 74462 2001-03-19 12:50:13Z alfred $"; 3750276Speter#endif 3850276Speter 3950276Speter/* 4050276Speter * pmap_rmt.c 4150276Speter * Client interface to pmap rpc service. 4250276Speter * remote call and broadcast service 4350276Speter * 4450276Speter * Copyright (C) 1984, Sun Microsystems, Inc. 45166124Srafan */ 4650276Speter 47166124Srafan#include "namespace.h" 48166124Srafan#include <sys/types.h> 49166124Srafan#include <sys/ioctl.h> 50166124Srafan#include <sys/poll.h> 51166124Srafan#include <sys/socket.h> 52166124Srafan 53166124Srafan#include <net/if.h> 54166124Srafan#include <netinet/in.h> 55166124Srafan#include <arpa/inet.h> 56166124Srafan 57166124Srafan#include <assert.h> 58166124Srafan#include <err.h> 59166124Srafan#include <errno.h> 60166124Srafan#include <stdio.h> 6176726Speter#include <string.h> 6297049Speter#include <unistd.h> 6397049Speter 6497049Speter#include <rpc/rpc.h> 6597049Speter#include <rpc/pmap_prot.h> 6697049Speter#include <rpc/pmap_clnt.h> 6750276Speter#include <rpc/pmap_rmt.h> 6862449Speter#include "un-namespace.h" 6962449Speter 7097049Speterstatic const struct timeval timeout = { 3, 0 }; 7150276Speter 7250276Speter/* 7376726Speter * pmapper remote-call-service interface. 7476726Speter * This routine is used to call the pmapper remote call service 7576726Speter * which will look up a service program in the port maps, and then 7676726Speter * remotely call that routine with the given parameters. This allows 7776726Speter * programs to do a lookup and call in one step. 7876726Speter*/ 7976726Speterenum clnt_stat 8076726Speterpmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, 8176726Speter port_ptr) 8250276Speter struct sockaddr_in *addr; 8362449Speter u_long prog, vers, proc; 8462449Speter xdrproc_t xdrargs, xdrres; 8550276Speter caddr_t argsp, resp; 8697049Speter struct timeval tout; 8797049Speter u_long *port_ptr; 8897049Speter{ 8997049Speter int sock = -1; 9097049Speter CLIENT *client; 9197049Speter struct rmtcallargs a; 9297049Speter struct rmtcallres r; 9397049Speter enum clnt_stat stat; 9450276Speter 9597049Speter assert(addr != NULL); 9697049Speter assert(port_ptr != NULL); 9797049Speter 9897049Speter addr->sin_port = htons(PMAPPORT); 9997049Speter client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock); 10097049Speter if (client != NULL) { 10197049Speter a.prog = prog; 10297049Speter a.vers = vers; 10397049Speter a.proc = proc; 10450276Speter a.args_ptr = argsp; 10562449Speter a.xdr_args = xdrargs; 10662449Speter r.port_ptr = port_ptr; 10750276Speter r.results_ptr = resp; 10862449Speter r.xdr_results = xdrres; 109166124Srafan stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT, 110166124Srafan (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres, 11162449Speter &r, tout); 11262449Speter CLNT_DESTROY(client); 11362449Speter } else { 11450276Speter stat = RPC_FAILED; 11562449Speter } 116166124Srafan addr->sin_port = 0; 117166124Srafan return (stat); 11862449Speter} 11962449Speter 12062449Speter 121166124Srafan/* 122166124Srafan * XDR remote call arguments 123166124Srafan * written for XDR_ENCODE direction only 124166124Srafan */ 12550276Speterbool_t 12662449Speterxdr_rmtcall_args(xdrs, cap) 12762449Speter XDR *xdrs; 12850276Speter 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