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 #include <sys/cdefs.h> 33 #if defined(LIBC_SCCS) && !defined(lint) 34 static char *sccsid = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro"; 35 static char *sccsid = "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC"; 36 #endif 37 #include <sys/cdefs.h> 38 __FBSDID("$FreeBSD$"); 39 40 /* 41 * pmap_rmt.c 42 * Client interface to pmap rpc service. 43 * remote call and broadcast service 44 * 45 * Copyright (C) 1984, Sun Microsystems, Inc. 46 */ 47 48 #include "namespace.h" 49 #include <sys/types.h> 50 #include <sys/ioctl.h> 51 #include <sys/poll.h> 52 #include <sys/socket.h> 53 54 #include <net/if.h> 55 #include <netinet/in.h> 56 #include <arpa/inet.h> 57 58 #include <assert.h> 59 #include <err.h> 60 #include <errno.h> 61 #include <stdio.h> 62 #include <string.h> 63 #include <unistd.h> 64 65 #include <rpc/rpc.h> 66 #include <rpc/pmap_prot.h> 67 #include <rpc/pmap_clnt.h> 68 #include <rpc/pmap_rmt.h> 69 #include "un-namespace.h" 70 71 static const struct timeval timeout = { 3, 0 }; 72 73 /* 74 * pmapper remote-call-service interface. 75 * This routine is used to call the pmapper remote call service 76 * which will look up a service program in the port maps, and then 77 * remotely call that routine with the given parameters. This allows 78 * programs to do a lookup and call in one step. 79 */ 80 enum clnt_stat 81 pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, 82 port_ptr) 83 struct sockaddr_in *addr; 84 u_long prog, vers, proc; 85 xdrproc_t xdrargs, xdrres; 86 caddr_t argsp, resp; 87 struct timeval tout; 88 u_long *port_ptr; 89 { 90 int sock = -1; 91 CLIENT *client; 92 struct rmtcallargs a; 93 struct rmtcallres r; 94 enum clnt_stat stat; 95 96 assert(addr != NULL); 97 assert(port_ptr != NULL); 98 99 addr->sin_port = htons(PMAPPORT); 100 client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock); 101 if (client != NULL) { 102 a.prog = prog; 103 a.vers = vers; 104 a.proc = proc; 105 a.args_ptr = argsp; 106 a.xdr_args = xdrargs; 107 r.port_ptr = port_ptr; 108 r.results_ptr = resp; 109 r.xdr_results = xdrres; 110 stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT, 111 (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres, 112 &r, tout); 113 CLNT_DESTROY(client); 114 } else { 115 stat = RPC_FAILED; 116 } 117 addr->sin_port = 0; 118 return (stat); 119 } 120 121 122 /* 123 * XDR remote call arguments 124 * written for XDR_ENCODE direction only 125 */ 126 bool_t 127 xdr_rmtcall_args(xdrs, cap) 128 XDR *xdrs; 129 struct rmtcallargs *cap; 130 { 131 u_int lenposition, argposition, position; 132 133 assert(xdrs != NULL); 134 assert(cap != NULL); 135 136 if (xdr_u_long(xdrs, &(cap->prog)) && 137 xdr_u_long(xdrs, &(cap->vers)) && 138 xdr_u_long(xdrs, &(cap->proc))) { 139 lenposition = XDR_GETPOS(xdrs); 140 if (! xdr_u_long(xdrs, &(cap->arglen))) 141 return (FALSE); 142 argposition = XDR_GETPOS(xdrs); 143 if (! (*(cap->xdr_args))(xdrs, cap->args_ptr)) 144 return (FALSE); 145 position = XDR_GETPOS(xdrs); 146 cap->arglen = (u_long)position - (u_long)argposition; 147 XDR_SETPOS(xdrs, lenposition); 148 if (! xdr_u_long(xdrs, &(cap->arglen))) 149 return (FALSE); 150 XDR_SETPOS(xdrs, position); 151 return (TRUE); 152 } 153 return (FALSE); 154 } 155 156 /* 157 * XDR remote call results 158 * written for XDR_DECODE direction only 159 */ 160 bool_t 161 xdr_rmtcallres(xdrs, crp) 162 XDR *xdrs; 163 struct rmtcallres *crp; 164 { 165 caddr_t port_ptr; 166 167 assert(xdrs != NULL); 168 assert(crp != NULL); 169 170 port_ptr = (caddr_t)(void *)crp->port_ptr; 171 if (xdr_reference(xdrs, &port_ptr, sizeof (u_long), 172 (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) { 173 crp->port_ptr = (u_long *)(void *)port_ptr; 174 return ((*(crp->xdr_results))(xdrs, crp->results_ptr)); 175 } 176 return (FALSE); 177 } 178