portmap.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdio.h>
  15. #include <rpc/xdr.h>
  16. #include "nfs.h"
  17. #include "libnfs-raw.h"
  18. #include "libnfs-private.h"
  19. #include "rpc/portmap.h"
  20. int rpc_pmap_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
  21. {
  22. struct rpc_pdu *pdu;
  23. pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V2, PMAP_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
  24. if (pdu == NULL) {
  25. rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for portmap/null call");
  26. return -1;
  27. }
  28. if (rpc_queue_pdu(rpc, pdu) != 0) {
  29. rpc_set_error(rpc, "Out of memory. Failed to queue pdu for portmap/null call");
  30. rpc_free_pdu(rpc, pdu);
  31. return -2;
  32. }
  33. return 0;
  34. }
  35. int rpc_pmap_getport_async(struct rpc_context *rpc, int program, int version, rpc_cb cb, void *private_data)
  36. {
  37. struct rpc_pdu *pdu;
  38. struct mapping m;
  39. pdu = rpc_allocate_pdu(rpc, PMAP_PROGRAM, PMAP_V2, PMAP_GETPORT, cb, private_data, (xdrproc_t)xdr_int, sizeof(uint32_t));
  40. if (pdu == NULL) {
  41. rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for portmap/getport call");
  42. return -1;
  43. }
  44. m.prog = program;
  45. m.vers = version;
  46. m.prot = IPPROTO_TCP;
  47. m.port = 0;
  48. if (xdr_mapping(&pdu->xdr, &m) == 0) {
  49. rpc_set_error(rpc, "XDR error: Failed to encode data for portmap/getport call");
  50. rpc_free_pdu(rpc, pdu);
  51. return -2;
  52. }
  53. if (rpc_queue_pdu(rpc, pdu) != 0) {
  54. printf("Failed to queue portmap/getport pdu\n");
  55. rpc_free_pdu(rpc, pdu);
  56. return -2;
  57. }
  58. return 0;
  59. }