You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

portmap.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. #include <errno.h>
  25. #include <byteswap.h>
  26. #include <ipxe/socket.h>
  27. #include <ipxe/tcpip.h>
  28. #include <ipxe/in.h>
  29. #include <ipxe/iobuf.h>
  30. #include <ipxe/xfer.h>
  31. #include <ipxe/open.h>
  32. #include <ipxe/uri.h>
  33. #include <ipxe/features.h>
  34. #include <ipxe/timer.h>
  35. #include <ipxe/oncrpc.h>
  36. #include <ipxe/oncrpc_iob.h>
  37. #include <ipxe/portmap.h>
  38. /** @file
  39. *
  40. * PORTMAPPER protocol.
  41. *
  42. */
  43. /** PORTMAP GETPORT procedure. */
  44. #define PORTMAP_GETPORT 3
  45. /**
  46. * Send a GETPORT request
  47. *
  48. * @v intf Interface to send the request on
  49. * @v session ONC RPC session
  50. * @v prog ONC RPC program number
  51. * @v vers ONC RPC rogram version number
  52. * @v proto Protocol (TCP or UDP)
  53. * @ret rc Return status code
  54. */
  55. int portmap_getport ( struct interface *intf, struct oncrpc_session *session,
  56. uint32_t prog, uint32_t vers, uint32_t proto ) {
  57. struct oncrpc_field fields[] = {
  58. ONCRPC_FIELD ( int32, prog ),
  59. ONCRPC_FIELD ( int32, vers ),
  60. ONCRPC_FIELD ( int32, proto ),
  61. ONCRPC_FIELD ( int32, 0 ), /* The port field is only meaningful
  62. in GETPORT reply */
  63. ONCRPC_FIELD_END,
  64. };
  65. return oncrpc_call ( intf, session, PORTMAP_GETPORT, fields );
  66. }
  67. /**
  68. * Parse a GETPORT reply
  69. *
  70. * @v getport_reply A structure where the data will be saved
  71. * @v reply The ONC RPC reply to get data from
  72. * @ret rc Return status code
  73. */
  74. int portmap_get_getport_reply ( struct portmap_getport_reply *getport_reply,
  75. struct oncrpc_reply *reply ) {
  76. if ( ! getport_reply || ! reply )
  77. return -EINVAL;
  78. getport_reply->port = oncrpc_iob_get_int ( reply->data );
  79. if ( getport_reply == 0 || getport_reply->port >= 65536 )
  80. return -EINVAL;
  81. return 0;
  82. }