1996-02-27 02:05:14 +03:00
|
|
|
/* $NetBSD: rpc.c,v 1.12 1996/02/26 23:05:26 gwr Exp $ */
|
1994-10-26 08:44:32 +03:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-10-26 08:44:32 +03:00
|
|
|
* @(#) Header: rpc.c,v 1.12 93/09/28 08:31:56 leres Exp (LBL)
|
1994-05-08 20:11:14 +04:00
|
|
|
*/
|
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
/*
|
1995-07-03 06:59:16 +04:00
|
|
|
* RPC functions used by NFS and bootparams.
|
|
|
|
* Note that bootparams requires the ability to find out the
|
|
|
|
* address of the server from which its response has come.
|
|
|
|
* This is supported by keeping the IP/UDP headers in the
|
|
|
|
* buffer space provided by the caller. (See rpc_fromaddr)
|
1995-06-27 19:28:58 +04:00
|
|
|
*/
|
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
1996-02-27 02:05:14 +03:00
|
|
|
#include "rpcv2.h"
|
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#include "stand.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "netif.h"
|
|
|
|
#include "rpc.h"
|
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
struct auth_info {
|
|
|
|
int32_t authtype; /* auth type */
|
|
|
|
u_int32_t authlen; /* auth length */
|
1994-05-08 20:11:14 +04:00
|
|
|
};
|
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
struct auth_unix {
|
|
|
|
int32_t ua_time;
|
|
|
|
int32_t ua_hostname; /* null */
|
|
|
|
int32_t ua_uid;
|
|
|
|
int32_t ua_gid;
|
|
|
|
int32_t ua_gidlist; /* null */
|
|
|
|
};
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
struct rpc_call {
|
|
|
|
u_int32_t rp_xid; /* request transaction id */
|
|
|
|
int32_t rp_direction; /* call direction (0) */
|
|
|
|
u_int32_t rp_rpcvers; /* rpc version (2) */
|
|
|
|
u_int32_t rp_prog; /* program */
|
|
|
|
u_int32_t rp_vers; /* version */
|
|
|
|
u_int32_t rp_proc; /* procedure */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rpc_reply {
|
|
|
|
u_int32_t rp_xid; /* request transaction id */
|
|
|
|
int32_t rp_direction; /* call direction (1) */
|
|
|
|
int32_t rp_astatus; /* accept status (0: accepted) */
|
|
|
|
union {
|
|
|
|
u_int32_t rpu_errno;
|
|
|
|
struct {
|
|
|
|
struct auth_info rok_auth;
|
|
|
|
u_int32_t rok_status;
|
|
|
|
} rpu_rok;
|
|
|
|
} rp_u;
|
1994-05-08 20:11:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Local forwards */
|
1995-09-15 03:45:21 +04:00
|
|
|
static ssize_t recvrpc __P((struct iodesc *, void *, size_t, time_t));
|
1995-09-19 01:19:18 +04:00
|
|
|
static int rpc_getport __P((struct iodesc *, n_long, n_long));
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
int rpc_xid;
|
|
|
|
int rpc_port = 0x400; /* predecrement */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a rpc call; return length of answer
|
1995-07-03 06:59:16 +04:00
|
|
|
* Note: Caller must leave room for headers.
|
1995-06-27 19:28:58 +04:00
|
|
|
*/
|
1995-09-15 03:45:21 +04:00
|
|
|
ssize_t
|
1995-06-27 19:28:58 +04:00
|
|
|
rpc_call(d, prog, vers, proc, sdata, slen, rdata, rlen)
|
1994-05-08 20:11:14 +04:00
|
|
|
register struct iodesc *d;
|
1995-06-27 19:28:58 +04:00
|
|
|
register n_long prog, vers, proc;
|
1994-05-08 20:11:14 +04:00
|
|
|
register void *sdata;
|
1995-02-20 14:04:00 +03:00
|
|
|
register size_t slen;
|
1994-05-08 20:11:14 +04:00
|
|
|
register void *rdata;
|
1995-02-20 14:04:00 +03:00
|
|
|
register size_t rlen;
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
1995-09-15 03:45:21 +04:00
|
|
|
register ssize_t cc;
|
1995-06-27 19:28:58 +04:00
|
|
|
struct auth_info *auth;
|
|
|
|
struct rpc_call *call;
|
|
|
|
struct rpc_reply *reply;
|
1995-09-17 04:49:37 +04:00
|
|
|
char *send_head, *send_tail;
|
|
|
|
char *recv_head, *recv_tail;
|
1995-06-27 19:28:58 +04:00
|
|
|
n_long x;
|
1995-09-23 07:36:06 +04:00
|
|
|
int port; /* host order */
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
if (debug)
|
1995-06-27 19:28:58 +04:00
|
|
|
printf("rpc_call: prog=0x%x vers=%d proc=%d\n",
|
1995-09-19 01:19:18 +04:00
|
|
|
prog, vers, proc);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
|
|
|
|
1995-09-23 07:36:06 +04:00
|
|
|
port = rpc_getport(d, prog, vers);
|
|
|
|
if (port == -1)
|
1995-09-19 01:19:18 +04:00
|
|
|
return (-1);
|
|
|
|
|
1995-09-23 07:36:06 +04:00
|
|
|
d->destport = htons(port);
|
1995-06-27 19:28:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepend authorization stuff and headers.
|
|
|
|
* Note, must prepend things in reverse order.
|
|
|
|
*/
|
|
|
|
send_head = sdata;
|
1995-09-15 03:45:21 +04:00
|
|
|
send_tail = (char *)sdata + slen;
|
1995-06-27 19:28:58 +04:00
|
|
|
|
|
|
|
/* Auth verifier is always auth_null */
|
1995-09-17 04:49:37 +04:00
|
|
|
send_head -= sizeof(*auth);
|
|
|
|
auth = (struct auth_info *)send_head;
|
1995-06-27 19:28:58 +04:00
|
|
|
auth->authtype = htonl(RPCAUTH_NULL);
|
|
|
|
auth->authlen = 0;
|
|
|
|
|
1995-07-03 06:59:16 +04:00
|
|
|
#if 1
|
1995-06-27 19:28:58 +04:00
|
|
|
/* Auth credentials: always auth unix (as root) */
|
1995-09-17 04:49:37 +04:00
|
|
|
send_head -= sizeof(struct auth_unix);
|
1995-06-27 19:28:58 +04:00
|
|
|
bzero(send_head, sizeof(struct auth_unix));
|
1995-09-17 04:49:37 +04:00
|
|
|
send_head -= sizeof(*auth);
|
|
|
|
auth = (struct auth_info *)send_head;
|
1995-06-27 19:28:58 +04:00
|
|
|
auth->authtype = htonl(RPCAUTH_UNIX);
|
|
|
|
auth->authlen = htonl(sizeof(struct auth_unix));
|
|
|
|
#else
|
|
|
|
/* Auth credentials: always auth_null (XXX OK?) */
|
1995-09-17 04:49:37 +04:00
|
|
|
send_head -= sizeof(*auth);
|
1995-06-27 19:28:58 +04:00
|
|
|
auth = send_head;
|
|
|
|
auth->authtype = htonl(RPCAUTH_NULL);
|
|
|
|
auth->authlen = 0;
|
|
|
|
#endif
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
/* RPC call structure. */
|
1995-09-17 04:49:37 +04:00
|
|
|
send_head -= sizeof(*call);
|
|
|
|
call = (struct rpc_call *)send_head;
|
1995-06-27 19:28:58 +04:00
|
|
|
rpc_xid++;
|
|
|
|
call->rp_xid = htonl(rpc_xid);
|
|
|
|
call->rp_direction = htonl(RPC_CALL);
|
|
|
|
call->rp_rpcvers = htonl(RPC_VER2);
|
|
|
|
call->rp_prog = htonl(prog);
|
|
|
|
call->rp_vers = htonl(vers);
|
|
|
|
call->rp_proc = htonl(proc);
|
|
|
|
|
|
|
|
/* Make room for the rpc_reply header. */
|
|
|
|
recv_head = rdata;
|
1995-09-15 03:45:21 +04:00
|
|
|
recv_tail = (char *)rdata + rlen;
|
1995-09-17 04:49:37 +04:00
|
|
|
recv_head -= sizeof(*reply);
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
cc = sendrecv(d,
|
1995-09-15 03:45:21 +04:00
|
|
|
sendudp, send_head, ((int)send_tail - (int)send_head),
|
|
|
|
recvrpc, recv_head, ((int)recv_tail - (int)recv_head));
|
1995-09-19 01:19:18 +04:00
|
|
|
|
1995-02-20 02:52:18 +03:00
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
if (debug)
|
1995-06-27 19:28:58 +04:00
|
|
|
printf("callrpc: cc=%d rlen=%d\n", cc, rlen);
|
1995-02-20 02:52:18 +03:00
|
|
|
#endif
|
1995-09-15 03:45:21 +04:00
|
|
|
if (cc == -1)
|
1995-02-20 14:04:00 +03:00
|
|
|
return (-1);
|
1995-09-15 03:45:21 +04:00
|
|
|
|
|
|
|
if (cc <= sizeof(*reply)) {
|
|
|
|
errno = EBADRPC;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
1995-09-17 04:49:37 +04:00
|
|
|
recv_tail = recv_head + cc;
|
1995-06-27 19:28:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the RPC reply status.
|
|
|
|
* The xid, dir, astatus were already checked.
|
|
|
|
*/
|
1995-09-17 04:49:37 +04:00
|
|
|
reply = (struct rpc_reply *)recv_head;
|
1995-06-27 19:28:58 +04:00
|
|
|
auth = &reply->rp_u.rpu_rok.rok_auth;
|
|
|
|
x = ntohl(auth->authlen);
|
|
|
|
if (x != 0) {
|
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("callrpc: reply auth != NULL\n");
|
|
|
|
#endif
|
1995-09-17 04:49:37 +04:00
|
|
|
errno = EBADRPC;
|
1995-06-27 19:28:58 +04:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
x = ntohl(reply->rp_u.rpu_rok.rok_status);
|
|
|
|
if (x != 0) {
|
|
|
|
printf("callrpc: error = %d\n", x);
|
1995-09-17 04:49:37 +04:00
|
|
|
errno = EBADRPC;
|
1995-06-27 19:28:58 +04:00
|
|
|
return(-1);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
1995-09-17 04:49:37 +04:00
|
|
|
recv_head += sizeof(*reply);
|
1995-06-27 19:28:58 +04:00
|
|
|
|
1995-09-15 03:45:21 +04:00
|
|
|
return (ssize_t)((int)recv_tail - (int)recv_head);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
/*
|
|
|
|
* Returns true if packet is the one we're waiting for.
|
|
|
|
* This just checks the XID, direction, acceptance.
|
|
|
|
* Remaining checks are done by callrpc
|
|
|
|
*/
|
1995-09-15 03:45:21 +04:00
|
|
|
static ssize_t
|
1995-02-20 14:04:00 +03:00
|
|
|
recvrpc(d, pkt, len, tleft)
|
1994-05-08 20:11:14 +04:00
|
|
|
register struct iodesc *d;
|
|
|
|
register void *pkt;
|
1995-02-20 14:04:00 +03:00
|
|
|
register size_t len;
|
|
|
|
time_t tleft;
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
1995-06-27 19:28:58 +04:00
|
|
|
register struct rpc_reply *reply;
|
1995-09-17 04:49:37 +04:00
|
|
|
ssize_t n;
|
|
|
|
long x;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
if (debug)
|
1995-02-20 02:52:18 +03:00
|
|
|
printf("recvrpc: called len=%d\n", len);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
|
|
|
|
1995-09-15 03:45:21 +04:00
|
|
|
n = readudp(d, pkt, len, tleft);
|
|
|
|
if (n <= (4 * 4))
|
1995-09-17 04:49:37 +04:00
|
|
|
return -1;
|
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
reply = (struct rpc_reply *)pkt;
|
1995-02-20 14:04:00 +03:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
x = ntohl(reply->rp_xid);
|
|
|
|
if (x != rpc_xid) {
|
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("recvrpc: rp_xid %d != xid %d\n", x, rpc_xid);
|
|
|
|
#endif
|
1995-09-17 04:49:37 +04:00
|
|
|
return -1;
|
1995-06-27 19:28:58 +04:00
|
|
|
}
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
x = ntohl(reply->rp_direction);
|
|
|
|
if (x != RPC_REPLY) {
|
1994-05-08 20:11:14 +04:00
|
|
|
#ifdef RPC_DEBUG
|
1995-06-27 19:28:58 +04:00
|
|
|
if (debug)
|
|
|
|
printf("recvrpc: rp_direction %d != REPLY\n", x);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1995-09-17 04:49:37 +04:00
|
|
|
return -1;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
x = ntohl(reply->rp_astatus);
|
|
|
|
if (x != RPC_MSGACCEPTED) {
|
|
|
|
errno = ntohl(reply->rp_u.rpu_errno);
|
|
|
|
printf("recvrpc: reject, astat=%d, errno=%d\n", x, errno);
|
1995-09-17 04:49:37 +04:00
|
|
|
return -1;
|
1995-06-27 19:28:58 +04:00
|
|
|
}
|
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
/* Return data count (thus indicating success) */
|
1995-09-15 03:45:21 +04:00
|
|
|
return (n);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
/*
|
|
|
|
* Given a pointer to a reply just received,
|
|
|
|
* dig out the IP address/port from the headers.
|
|
|
|
*/
|
|
|
|
void
|
1995-09-19 01:19:18 +04:00
|
|
|
rpc_fromaddr(pkt, addr, port)
|
|
|
|
void *pkt;
|
|
|
|
struct in_addr *addr;
|
|
|
|
u_short *port;
|
1995-06-27 19:28:58 +04:00
|
|
|
{
|
|
|
|
struct hackhdr {
|
|
|
|
/* Tail of IP header: just IP addresses */
|
|
|
|
n_long ip_src;
|
|
|
|
n_long ip_dst;
|
|
|
|
/* UDP header: */
|
|
|
|
u_int16_t uh_sport; /* source port */
|
|
|
|
u_int16_t uh_dport; /* destination port */
|
|
|
|
int16_t uh_ulen; /* udp length */
|
|
|
|
u_int16_t uh_sum; /* udp checksum */
|
|
|
|
/* RPC reply header: */
|
|
|
|
struct rpc_reply rpc;
|
|
|
|
} *hhdr;
|
|
|
|
|
|
|
|
hhdr = ((struct hackhdr *)pkt) - 1;
|
1995-09-19 01:19:18 +04:00
|
|
|
addr->s_addr = hhdr->ip_src;
|
1995-06-27 19:28:58 +04:00
|
|
|
*port = hhdr->uh_sport;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RPC Portmapper cache
|
|
|
|
*/
|
|
|
|
#define PMAP_NUM 8 /* need at most 5 pmap entries */
|
|
|
|
|
|
|
|
int rpc_pmap_num;
|
|
|
|
struct pmap_list {
|
1995-09-19 01:19:18 +04:00
|
|
|
struct in_addr addr; /* server, net order */
|
1995-06-27 19:28:58 +04:00
|
|
|
u_long prog; /* host order */
|
|
|
|
u_long vers; /* host order */
|
1995-09-23 07:36:06 +04:00
|
|
|
int port; /* host order */
|
1995-06-27 19:28:58 +04:00
|
|
|
} rpc_pmap_list[PMAP_NUM];
|
|
|
|
|
1995-09-23 07:36:06 +04:00
|
|
|
/* return port number in host order, or -1 */
|
1995-06-27 19:28:58 +04:00
|
|
|
int
|
|
|
|
rpc_pmap_getcache(addr, prog, vers)
|
1995-09-19 01:19:18 +04:00
|
|
|
struct in_addr addr; /* server, net order */
|
|
|
|
u_long prog; /* host order */
|
|
|
|
u_long vers; /* host order */
|
1995-06-27 19:28:58 +04:00
|
|
|
{
|
|
|
|
struct pmap_list *pl;
|
|
|
|
|
1995-09-23 07:36:06 +04:00
|
|
|
for (pl = rpc_pmap_list; pl < &rpc_pmap_list[rpc_pmap_num]; pl++) {
|
|
|
|
if (pl->addr.s_addr == addr.s_addr &&
|
|
|
|
pl->prog == prog && pl->vers == vers )
|
|
|
|
{
|
|
|
|
return (pl->port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (-1);
|
1995-06-27 19:28:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rpc_pmap_putcache(addr, prog, vers, port)
|
1995-09-19 01:19:18 +04:00
|
|
|
struct in_addr addr; /* server, net order */
|
|
|
|
u_long prog; /* host order */
|
|
|
|
u_long vers; /* host order */
|
1995-09-23 07:36:06 +04:00
|
|
|
int port; /* host order */
|
1995-06-27 19:28:58 +04:00
|
|
|
{
|
|
|
|
struct pmap_list *pl;
|
|
|
|
|
|
|
|
/* Don't overflow cache... */
|
|
|
|
if (rpc_pmap_num >= PMAP_NUM) {
|
|
|
|
/* ... just re-use the last entry. */
|
|
|
|
rpc_pmap_num = PMAP_NUM - 1;
|
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
printf("rpc_pmap_putcache: cache overflow\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
pl = &rpc_pmap_list[rpc_pmap_num];
|
|
|
|
rpc_pmap_num++;
|
|
|
|
|
|
|
|
/* Cache answer */
|
|
|
|
pl->addr = addr;
|
|
|
|
pl->prog = prog;
|
|
|
|
pl->vers = vers;
|
|
|
|
pl->port = port;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request a port number from the port mapper.
|
1995-09-23 07:36:06 +04:00
|
|
|
* Returns the port in host order.
|
1995-06-27 19:28:58 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
rpc_getport(d, prog, vers)
|
1994-05-08 20:11:14 +04:00
|
|
|
register struct iodesc *d;
|
1995-06-27 19:28:58 +04:00
|
|
|
n_long prog; /* host order */
|
|
|
|
n_long vers; /* host order */
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
1995-06-27 19:28:58 +04:00
|
|
|
struct args {
|
1995-09-19 01:19:18 +04:00
|
|
|
n_long prog; /* call program */
|
|
|
|
n_long vers; /* call version */
|
|
|
|
n_long proto; /* call protocol */
|
|
|
|
n_long port; /* call port (unused) */
|
1995-06-27 19:28:58 +04:00
|
|
|
} *args;
|
|
|
|
struct res {
|
1995-09-19 01:19:18 +04:00
|
|
|
n_long port;
|
1995-06-27 19:28:58 +04:00
|
|
|
} *res;
|
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
struct args d;
|
1994-05-08 20:11:14 +04:00
|
|
|
} sdata;
|
1995-06-27 19:28:58 +04:00
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
struct res d;
|
|
|
|
n_long pad;
|
|
|
|
} rdata;
|
1995-09-19 01:19:18 +04:00
|
|
|
ssize_t cc;
|
1995-09-23 07:36:06 +04:00
|
|
|
int port;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
if (debug)
|
1995-09-19 01:19:18 +04:00
|
|
|
printf("getport: prog=0x%x vers=%d\n", prog, vers);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1995-06-27 19:28:58 +04:00
|
|
|
|
|
|
|
/* This one is fixed forever. */
|
|
|
|
if (prog == PMAPPROG)
|
1995-09-23 07:36:06 +04:00
|
|
|
return (PMAPPORT);
|
1995-06-27 19:28:58 +04:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
/* Try for cached answer first */
|
1995-06-27 19:28:58 +04:00
|
|
|
port = rpc_pmap_getcache(d->destip, prog, vers);
|
1995-09-23 07:36:06 +04:00
|
|
|
if (port != -1)
|
1995-06-27 19:28:58 +04:00
|
|
|
return (port);
|
|
|
|
|
|
|
|
args = &sdata.d;
|
|
|
|
args->prog = htonl(prog);
|
|
|
|
args->vers = htonl(vers);
|
|
|
|
args->proto = htonl(IPPROTO_UDP);
|
|
|
|
args->port = 0;
|
|
|
|
res = &rdata.d;
|
|
|
|
|
|
|
|
cc = rpc_call(d, PMAPPROG, PMAPVERS, PMAPPROC_GETPORT,
|
|
|
|
args, sizeof(*args), res, sizeof(*res));
|
|
|
|
if (cc < sizeof(*res)) {
|
1994-05-08 20:11:14 +04:00
|
|
|
printf("getport: %s", strerror(errno));
|
1995-09-19 01:19:18 +04:00
|
|
|
errno = EBADRPC;
|
1995-09-23 07:36:06 +04:00
|
|
|
return (-1);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
1995-09-23 07:36:06 +04:00
|
|
|
port = (int)ntohl(res->port);
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
rpc_pmap_putcache(d->destip, prog, vers, port);
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:28:58 +04:00
|
|
|
return (port);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|