1997-05-11 18:05:39 +00:00
|
|
|
/* $NetBSD: krpc_subr.c,v 1.12.4.1 1996/06/07 00:52:26 cgd Exp $ */
|
|
|
|
|
2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1997-05-11 18:05:39 +00:00
|
|
|
* Copyright (c) 1995 Gordon Ross, Adam Glass
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* partially based on:
|
|
|
|
* libnetboot/rpc.c
|
|
|
|
* @(#) Header: rpc.c,v 1.12 93/09/28 08:31:56 leres Exp (LBL)
|
|
|
|
*/
|
|
|
|
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1997-09-02 01:19:47 +00:00
|
|
|
#include <sys/malloc.h>
|
1997-05-11 18:05:39 +00:00
|
|
|
#include <sys/mbuf.h>
|
2001-12-31 20:05:26 +00:00
|
|
|
#include <sys/proc.h>
|
1997-05-11 18:05:39 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1998-03-28 10:33:27 +00:00
|
|
|
#include <sys/uio.h>
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2003-11-14 20:54:10 +00:00
|
|
|
#include <rpc/rpcclnt.h>
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
#include <nfs/rpcv2.h>
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <nfsclient/krpc.h>
|
1997-05-11 18:05:39 +00:00
|
|
|
#include <nfs/xdr_subs.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel support for Sun RPC
|
|
|
|
*
|
|
|
|
* Used currently for bootstrapping in nfs diskless configurations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic RPC headers
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct auth_info {
|
|
|
|
u_int32_t authtype; /* auth type */
|
|
|
|
u_int32_t authlen; /* auth length */
|
|
|
|
};
|
|
|
|
|
|
|
|
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 */
|
|
|
|
};
|
|
|
|
|
2003-11-15 00:26:42 +00:00
|
|
|
struct krpc_call {
|
1997-05-11 18:05:39 +00:00
|
|
|
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 auth_info rpc_auth;
|
|
|
|
struct auth_unix rpc_unix;
|
|
|
|
struct auth_info rpc_verf;
|
|
|
|
};
|
|
|
|
|
2003-11-15 00:26:42 +00:00
|
|
|
struct krpc_reply {
|
1997-05-11 18:05:39 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
#define rp_errno rp_u.rpu_errno
|
|
|
|
#define rp_auth rp_u.rpu_rok.rok_auth
|
|
|
|
#define rp_status rp_u.rpu_rok.rok_status
|
|
|
|
|
|
|
|
#define MIN_REPLY_HDR 16 /* xid, dir, astat, errno */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* What is the longest we will wait before re-sending a request?
|
|
|
|
* Note this is also the frequency of "RPC timeout" messages.
|
|
|
|
* The re-send loop count sup linearly to this maximum, so the
|
|
|
|
* first complaint will happen after (1+2+3+4+5)=15 seconds.
|
|
|
|
*/
|
|
|
|
#define MAX_RESEND_DELAY 5 /* seconds */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call portmap to lookup a port number for a particular rpc program
|
|
|
|
* Returns non-zero error on failure.
|
|
|
|
*/
|
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
krpc_portmap(struct sockaddr_in *sin, u_int prog, u_int vers, u_int16_t *portp,
|
|
|
|
struct thread *td)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
|
|
|
struct sdata {
|
|
|
|
u_int32_t prog; /* call program */
|
|
|
|
u_int32_t vers; /* call version */
|
|
|
|
u_int32_t proto; /* call protocol */
|
|
|
|
u_int32_t port; /* call port (unused) */
|
|
|
|
} *sdata;
|
|
|
|
struct rdata {
|
|
|
|
u_int16_t pad;
|
|
|
|
u_int16_t port;
|
|
|
|
} *rdata;
|
|
|
|
struct mbuf *m;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* The portmapper port is fixed. */
|
|
|
|
if (prog == PMAPPROG) {
|
|
|
|
*portp = htons(PMAPPORT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-25 09:39:02 +00:00
|
|
|
m = m_get(M_WAIT, MT_DATA);
|
1997-05-11 18:05:39 +00:00
|
|
|
sdata = mtod(m, struct sdata *);
|
|
|
|
m->m_len = sizeof(*sdata);
|
|
|
|
|
|
|
|
/* Do the RPC to get it. */
|
|
|
|
sdata->prog = txdr_unsigned(prog);
|
|
|
|
sdata->vers = txdr_unsigned(vers);
|
|
|
|
sdata->proto = txdr_unsigned(IPPROTO_UDP);
|
|
|
|
sdata->port = 0;
|
|
|
|
|
|
|
|
sin->sin_port = htons(PMAPPORT);
|
|
|
|
error = krpc_call(sin, PMAPPROG, PMAPVERS,
|
2001-09-12 08:38:13 +00:00
|
|
|
PMAPPROC_GETPORT, &m, NULL, td);
|
2001-09-18 23:32:09 +00:00
|
|
|
if (error)
|
1997-05-11 18:05:39 +00:00
|
|
|
return error;
|
|
|
|
|
|
|
|
if (m->m_len < sizeof(*rdata)) {
|
|
|
|
m = m_pullup(m, sizeof(*rdata));
|
|
|
|
if (m == NULL)
|
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
rdata = mtod(m, struct rdata *);
|
|
|
|
*portp = rdata->port;
|
|
|
|
|
|
|
|
m_freem(m);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a remote procedure call (RPC) and wait for its reply.
|
|
|
|
* If from_p is non-null, then we are doing broadcast, and
|
|
|
|
* the address from whence the response came is saved there.
|
|
|
|
*/
|
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
krpc_call(struct sockaddr_in *sa, u_int prog, u_int vers, u_int func,
|
|
|
|
struct mbuf **data, struct sockaddr **from_p, struct thread *td)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
|
|
|
struct socket *so;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr_in *sin, ssin;
|
|
|
|
struct sockaddr *from;
|
|
|
|
struct mbuf *m, *nam, *mhead;
|
2003-11-15 00:26:42 +00:00
|
|
|
struct krpc_call *call;
|
|
|
|
struct krpc_reply *reply;
|
1998-08-23 03:07:17 +00:00
|
|
|
struct sockopt sopt;
|
|
|
|
struct timeval tv;
|
1997-05-11 18:05:39 +00:00
|
|
|
struct uio auio;
|
|
|
|
int error, rcvflg, timo, secs, len;
|
|
|
|
static u_int32_t xid = ~0xFF;
|
|
|
|
u_int16_t tport;
|
2000-10-24 22:37:55 +00:00
|
|
|
u_int32_t saddr;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate address family.
|
|
|
|
* Sorry, this is INET specific...
|
|
|
|
*/
|
|
|
|
if (sa->sin_family != AF_INET)
|
|
|
|
return (EAFNOSUPPORT);
|
|
|
|
|
|
|
|
/* Free at end if not null. */
|
|
|
|
nam = mhead = NULL;
|
|
|
|
from = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create socket and set its recieve timeout.
|
|
|
|
*/
|
2002-02-27 18:32:23 +00:00
|
|
|
if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0, td->td_ucred, td)))
|
1997-05-11 18:05:39 +00:00
|
|
|
goto out;
|
|
|
|
|
1998-08-23 03:07:17 +00:00
|
|
|
tv.tv_sec = 1;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
bzero(&sopt, sizeof sopt);
|
2003-10-04 17:41:59 +00:00
|
|
|
sopt.sopt_dir = SOPT_SET;
|
1998-08-23 03:07:17 +00:00
|
|
|
sopt.sopt_level = SOL_SOCKET;
|
|
|
|
sopt.sopt_name = SO_RCVTIMEO;
|
|
|
|
sopt.sopt_val = &tv;
|
|
|
|
sopt.sopt_valsize = sizeof tv;
|
|
|
|
|
1999-01-27 23:45:44 +00:00
|
|
|
if ((error = sosetopt(so, &sopt)) != 0)
|
1997-05-11 18:05:39 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable broadcast if necessary.
|
|
|
|
*/
|
|
|
|
if (from_p) {
|
1998-08-23 03:07:17 +00:00
|
|
|
int on = 1;
|
|
|
|
sopt.sopt_name = SO_BROADCAST;
|
|
|
|
sopt.sopt_val = &on;
|
|
|
|
sopt.sopt_valsize = sizeof on;
|
1999-01-27 23:45:44 +00:00
|
|
|
if ((error = sosetopt(so, &sopt)) != 0)
|
1997-05-11 18:05:39 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bind the local endpoint to a reserved port,
|
|
|
|
* because some NFS servers refuse requests from
|
|
|
|
* non-reserved (non-privileged) ports.
|
|
|
|
*/
|
1997-08-16 19:16:27 +00:00
|
|
|
sin = &ssin;
|
|
|
|
bzero(sin, sizeof *sin);
|
|
|
|
sin->sin_len = sizeof(*sin);
|
1997-05-11 18:05:39 +00:00
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_addr.s_addr = INADDR_ANY;
|
|
|
|
tport = IPPORT_RESERVED;
|
|
|
|
do {
|
|
|
|
tport--;
|
|
|
|
sin->sin_port = htons(tport);
|
2001-09-12 08:38:13 +00:00
|
|
|
error = sobind(so, (struct sockaddr *)sin, td);
|
1997-05-11 18:05:39 +00:00
|
|
|
} while (error == EADDRINUSE &&
|
|
|
|
tport > IPPORT_RESERVED / 2);
|
|
|
|
if (error) {
|
|
|
|
printf("bind failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup socket address for the server.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepend RPC message header.
|
|
|
|
*/
|
2008-03-25 09:39:02 +00:00
|
|
|
mhead = m_gethdr(M_WAIT, MT_DATA);
|
1997-05-11 18:05:39 +00:00
|
|
|
mhead->m_next = *data;
|
2003-11-15 00:26:42 +00:00
|
|
|
call = mtod(mhead, struct krpc_call *);
|
1997-05-11 18:05:39 +00:00
|
|
|
mhead->m_len = sizeof(*call);
|
|
|
|
bzero((caddr_t)call, sizeof(*call));
|
|
|
|
/* rpc_call part */
|
|
|
|
xid++;
|
|
|
|
call->rp_xid = txdr_unsigned(xid);
|
|
|
|
/* call->rp_direction = 0; */
|
|
|
|
call->rp_rpcvers = txdr_unsigned(2);
|
|
|
|
call->rp_prog = txdr_unsigned(prog);
|
|
|
|
call->rp_vers = txdr_unsigned(vers);
|
|
|
|
call->rp_proc = txdr_unsigned(func);
|
|
|
|
/* rpc_auth part (auth_unix as root) */
|
|
|
|
call->rpc_auth.authtype = txdr_unsigned(RPCAUTH_UNIX);
|
|
|
|
call->rpc_auth.authlen = txdr_unsigned(sizeof(struct auth_unix));
|
|
|
|
/* rpc_verf part (auth_null) */
|
|
|
|
call->rpc_verf.authtype = 0;
|
|
|
|
call->rpc_verf.authlen = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup packet header
|
|
|
|
*/
|
2005-03-16 08:13:08 +00:00
|
|
|
m_fixhdr(mhead);
|
1997-05-11 18:05:39 +00:00
|
|
|
mhead->m_pkthdr.rcvif = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send it, repeatedly, until a reply is received,
|
|
|
|
* but delay each re-send by an increasing amount.
|
|
|
|
* If the delay hits the maximum, start complaining.
|
|
|
|
*/
|
|
|
|
timo = 0;
|
|
|
|
for (;;) {
|
|
|
|
/* Send RPC request (or re-send). */
|
2008-03-25 09:39:02 +00:00
|
|
|
m = m_copym(mhead, 0, M_COPYALL, M_WAIT);
|
1997-08-16 19:16:27 +00:00
|
|
|
error = sosend(so, (struct sockaddr *)sa, NULL, m,
|
2001-09-12 08:38:13 +00:00
|
|
|
NULL, 0, td);
|
1997-05-11 18:05:39 +00:00
|
|
|
if (error) {
|
|
|
|
printf("krpc_call: sosend: %d\n", error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
m = NULL;
|
|
|
|
|
|
|
|
/* Determine new timeout. */
|
|
|
|
if (timo < MAX_RESEND_DELAY)
|
|
|
|
timo++;
|
2000-10-24 22:37:55 +00:00
|
|
|
else {
|
|
|
|
saddr = ntohl(sa->sin_addr.s_addr);
|
|
|
|
printf("RPC timeout for server %d.%d.%d.%d\n",
|
|
|
|
(saddr >> 24) & 255,
|
|
|
|
(saddr >> 16) & 255,
|
|
|
|
(saddr >> 8) & 255,
|
|
|
|
saddr & 255);
|
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for up to timo seconds for a reply.
|
|
|
|
* The socket receive timeout was set to 1 second.
|
|
|
|
*/
|
|
|
|
secs = timo;
|
|
|
|
while (secs > 0) {
|
|
|
|
if (from) {
|
2008-10-23 15:53:51 +00:00
|
|
|
free(from, M_SONAME);
|
1997-05-11 18:05:39 +00:00
|
|
|
from = NULL;
|
|
|
|
}
|
|
|
|
if (m) {
|
|
|
|
m_freem(m);
|
|
|
|
m = NULL;
|
|
|
|
}
|
2001-09-18 23:32:09 +00:00
|
|
|
bzero(&auio, sizeof(auio));
|
1997-05-11 18:05:39 +00:00
|
|
|
auio.uio_resid = len = 1<<16;
|
|
|
|
rcvflg = 0;
|
|
|
|
error = soreceive(so, &from, &auio, &m, NULL, &rcvflg);
|
|
|
|
if (error == EWOULDBLOCK) {
|
|
|
|
secs--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
len -= auio.uio_resid;
|
|
|
|
|
|
|
|
/* Does the reply contain at least a header? */
|
|
|
|
if (len < MIN_REPLY_HDR)
|
|
|
|
continue;
|
|
|
|
if (m->m_len < MIN_REPLY_HDR)
|
|
|
|
continue;
|
2003-11-15 00:26:42 +00:00
|
|
|
reply = mtod(m, struct krpc_reply *);
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
/* Is it the right reply? */
|
|
|
|
if (reply->rp_direction != txdr_unsigned(RPC_REPLY))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (reply->rp_xid != txdr_unsigned(xid))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Was RPC accepted? (authorization OK) */
|
|
|
|
if (reply->rp_astatus != 0) {
|
|
|
|
error = fxdr_unsigned(u_int32_t, reply->rp_errno);
|
|
|
|
printf("rpc denied, error=%d\n", error);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did the call succeed? */
|
|
|
|
if (reply->rp_status != 0) {
|
|
|
|
error = fxdr_unsigned(u_int32_t, reply->rp_status);
|
|
|
|
if (error == RPC_PROGMISMATCH) {
|
|
|
|
error = EBADRPC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
printf("rpc denied, status=%d\n", error);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto gotreply; /* break two levels */
|
|
|
|
|
|
|
|
} /* while secs */
|
|
|
|
} /* forever send/receive */
|
|
|
|
|
|
|
|
error = ETIMEDOUT;
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
gotreply:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get RPC reply header into first mbuf,
|
|
|
|
* get its length, then strip it off.
|
|
|
|
*/
|
|
|
|
len = sizeof(*reply);
|
|
|
|
if (m->m_len < len) {
|
|
|
|
m = m_pullup(m, len);
|
|
|
|
if (m == NULL) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2003-11-15 00:26:42 +00:00
|
|
|
reply = mtod(m, struct krpc_reply *);
|
1997-05-11 18:05:39 +00:00
|
|
|
if (reply->rp_auth.authtype != 0) {
|
|
|
|
len += fxdr_unsigned(u_int32_t, reply->rp_auth.authlen);
|
|
|
|
len = (len + 3) & ~3; /* XXX? */
|
|
|
|
}
|
|
|
|
m_adj(m, len);
|
|
|
|
|
|
|
|
/* result */
|
|
|
|
*data = m;
|
|
|
|
if (from_p) {
|
|
|
|
*from_p = from;
|
|
|
|
from = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (mhead) m_freem(mhead);
|
1997-08-16 19:16:27 +00:00
|
|
|
if (from) free(from, M_SONAME);
|
1997-05-11 18:05:39 +00:00
|
|
|
soclose(so);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* eXternal Data Representation routines.
|
|
|
|
* (but with non-standard args...)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* String representation for RPC.
|
|
|
|
*/
|
|
|
|
struct xdr_string {
|
|
|
|
u_int32_t len; /* length without null or padding */
|
|
|
|
char data[4]; /* data (longer, of course) */
|
|
|
|
/* data is padded to a long-word boundary */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mbuf *
|
2001-09-18 23:32:09 +00:00
|
|
|
xdr_string_encode(char *str, int len)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct xdr_string *xs;
|
|
|
|
int dlen; /* padded string length */
|
|
|
|
int mlen; /* message length */
|
|
|
|
|
|
|
|
dlen = (len + 3) & ~3;
|
|
|
|
mlen = dlen + 4;
|
|
|
|
|
|
|
|
if (mlen > MCLBYTES) /* If too big, we just can't do it. */
|
|
|
|
return (NULL);
|
|
|
|
|
2008-03-25 09:39:02 +00:00
|
|
|
m = m_get(M_WAIT, MT_DATA);
|
|
|
|
if (mlen > MLEN)
|
|
|
|
MCLGET(m, M_WAIT);
|
1997-05-11 18:05:39 +00:00
|
|
|
xs = mtod(m, struct xdr_string *);
|
|
|
|
m->m_len = mlen;
|
|
|
|
xs->len = txdr_unsigned(len);
|
|
|
|
bcopy(str, xs->data, len);
|
|
|
|
return (m);
|
|
|
|
}
|