opt_41.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // BEGIN_HEADER_GUARD
  15. #include <string>
  16. #include <dns/rdata.h>
  17. #include <boost/shared_ptr.hpp>
  18. #include <vector>
  19. // BEGIN_ISC_NAMESPACE
  20. // BEGIN_COMMON_DECLARATIONS
  21. // END_COMMON_DECLARATIONS
  22. // BEGIN_RDATA_NAMESPACE
  23. struct OPTImpl;
  24. class OPT : public Rdata {
  25. public:
  26. // BEGIN_COMMON_MEMBERS
  27. // END_COMMON_MEMBERS
  28. // The default constructor makes sense for OPT as it can be empty.
  29. OPT();
  30. OPT& operator=(const OPT& source);
  31. ~OPT();
  32. /// \brief A class representing a pseudo RR (or option) within an
  33. /// OPT RR (see RFC 6891).
  34. class PseudoRR {
  35. public:
  36. /// \brief Constructor.
  37. /// \param code The OPTION-CODE field of the pseudo RR.
  38. /// \param data The OPTION-DATA field of the pseudo
  39. /// RR. OPTION-LENGTH is set to the length of this vector.
  40. PseudoRR(uint16_t code,
  41. boost::shared_ptr<std::vector<uint8_t> >& data);
  42. /// \brief Return the option code of this pseudo RR.
  43. uint16_t getCode() const;
  44. /// \brief Return the option data of this pseudo RR.
  45. const uint8_t* getData() const;
  46. /// \brief Return the length of the option data of this
  47. /// pseudo RR.
  48. uint16_t getLength() const;
  49. private:
  50. uint16_t code_;
  51. boost::shared_ptr<std::vector<uint8_t> > data_;
  52. };
  53. /// \brief Append a pseudo RR (option) in this OPT RR.
  54. ///
  55. /// \param code The OPTION-CODE field of the pseudo RR.
  56. /// \param data The OPTION-DATA field of the pseudo RR.
  57. /// \param length The size of the \c data argument. OPTION-LENGTH is
  58. /// set to this size.
  59. /// \throw isc::InvalidParameter if this pseudo RR would cause
  60. /// the OPT RDATA to overflow its RDLENGTH.
  61. void appendPseudoRR(uint16_t code, const uint8_t* data, uint16_t length);
  62. /// \brief Return a vector of the pseudo RRs (options) in this
  63. /// OPT RR.
  64. ///
  65. /// Note: The returned reference is only valid during the lifetime
  66. /// of this \c generic::OPT object. It should not be used
  67. /// afterwards.
  68. const std::vector<PseudoRR>& getPseudoRRs() const;
  69. private:
  70. OPTImpl* impl_;
  71. };
  72. // END_RDATA_NAMESPACE
  73. // END_ISC_NAMESPACE
  74. // END_HEADER_GUARD
  75. // Local Variables:
  76. // mode: c++
  77. // End: