pmap.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "pmap.h"
  2. #include "clnt.h"
  3. #include <rpc/rpc.h>
  4. static struct timeval timeout = { 5, 0 };
  5. static struct timeval tottimeout = { 60, 0 };
  6. bool_t xdr_pmap(XDR *xdrs, struct pmap *regs)
  7. {
  8. if (xdr_u_long(xdrs, &regs->pm_prog) &&
  9. xdr_u_long(xdrs, &regs->pm_vers) &&
  10. xdr_u_long(xdrs, &regs->pm_prot))
  11. return (xdr_u_long(xdrs, &regs->pm_port));
  12. return (FALSE);
  13. }
  14. /*
  15. * Find the mapped port for program,version.
  16. * Calls the pmap service remotely to do the lookup.
  17. * Returns 0 if no map exists.
  18. */
  19. unsigned short pmap_getport(struct sockaddr_in *address, unsigned long program, unsigned long version, unsigned int protocol)
  20. {
  21. unsigned short port = 0;
  22. int socket = -1;
  23. register CLIENT *client = RT_NULL;
  24. struct pmap parms;
  25. address->sin_port = htons((unsigned short)PMAPPORT);
  26. if (protocol == IPPROTO_UDP)
  27. client = clntudp_bufcreate(address, PMAPPROG, PMAPVERS, timeout,
  28. &socket, RPCSMALLMSGSIZE,
  29. RPCSMALLMSGSIZE);
  30. if (client != (CLIENT *) NULL)
  31. {
  32. parms.pm_prog = program;
  33. parms.pm_vers = version;
  34. parms.pm_prot = protocol;
  35. parms.pm_port = 0; /* not needed or used */
  36. if (CLNT_CALL(client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap, (char*)&parms,
  37. (xdrproc_t)xdr_u_short, (char*)&port, tottimeout) != RPC_SUCCESS)
  38. {
  39. rt_kprintf("pmap failure\n");
  40. }
  41. CLNT_DESTROY(client);
  42. }
  43. (void) lwip_close(socket);
  44. address->sin_port = 0;
  45. return (port);
  46. }