rrclass.cc 1.8 KB

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