rt-thread/components/dfs/filesystems/nfs/rpc/pmap.c

55 lines
1.4 KiB
C
Raw Normal View History

#include "pmap.h"
#include "clnt.h"
#include <rpc/rpc.h>
static struct timeval timeout = { 5, 0 };
static struct timeval tottimeout = { 60, 0 };
2014-03-10 11:48:47 +08:00
bool_t xdr_pmap(XDR *xdrs, struct pmap *regs)
{
if (xdr_u_long(xdrs, &regs->pm_prog) &&
xdr_u_long(xdrs, &regs->pm_vers) &&
xdr_u_long(xdrs, &regs->pm_prot))
return (xdr_u_long(xdrs, &regs->pm_port));
return (FALSE);
}
/*
* Find the mapped port for program,version.
* Calls the pmap service remotely to do the lookup.
* Returns 0 if no map exists.
*/
2014-03-10 11:48:47 +08:00
unsigned short pmap_getport(struct sockaddr_in *address, unsigned long program, unsigned long version, unsigned int protocol)
{
unsigned short port = 0;
int socket = -1;
2014-04-02 14:02:36 +08:00
register CLIENT *client = RT_NULL;
struct pmap parms;
address->sin_port = htons((unsigned short)PMAPPORT);
if (protocol == IPPROTO_UDP)
client = clntudp_bufcreate(address, PMAPPROG, PMAPVERS, timeout,
&socket, RPCSMALLMSGSIZE,
RPCSMALLMSGSIZE);
if (client != (CLIENT *) NULL)
{
parms.pm_prog = program;
parms.pm_vers = version;
parms.pm_prot = protocol;
parms.pm_port = 0; /* not needed or used */
if (CLNT_CALL(client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap, (char*)&parms,
(xdrproc_t)xdr_u_short, (char*)&port, tottimeout) != RPC_SUCCESS)
{
rt_kprintf("pmap failure\n");
}
CLNT_DESTROY(client);
}
(void) lwip_close(socket);
address->sin_port = 0;
return (port);
}