1
0

pmap.c 1.5 KB

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