rrclass.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // $Id$
  15. #include <stdint.h>
  16. #include <string>
  17. #include <exceptions/exceptions.h>
  18. #include <dns/buffer.h>
  19. #include <dns/messagerenderer.h>
  20. #include <dns/rrparamregistry.h>
  21. #include <dns/rrclass.h>
  22. using namespace std;
  23. using namespace isc::dns;
  24. namespace isc {
  25. namespace dns {
  26. RRClass::RRClass(const string& classstr)
  27. {
  28. classcode_ = RRParamRegistry::getRegistry().textToClassCode(classstr);
  29. }
  30. RRClass::RRClass(InputBuffer& buffer)
  31. {
  32. if (buffer.getLength() - buffer.getPosition() < sizeof(uint16_t)) {
  33. isc_throw(IncompleteRRClass, "incomplete wire-format RR class");
  34. }
  35. classcode_ = buffer.readUint16();
  36. }
  37. const string
  38. RRClass::toText() const
  39. {
  40. return (RRParamRegistry::getRegistry().codeToClassText(classcode_));
  41. }
  42. void
  43. RRClass::toWire(OutputBuffer& buffer) const
  44. {
  45. buffer.writeUint16(classcode_);
  46. }
  47. void
  48. RRClass::toWire(MessageRenderer& renderer) const
  49. {
  50. renderer.writeUint16(classcode_);
  51. }
  52. ostream&
  53. operator<<(ostream& os, const RRClass& rrclass)
  54. {
  55. os << rrclass.toText();
  56. return (os);
  57. }
  58. }
  59. }