opcode.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <string>
  16. #include <ostream>
  17. #include <exceptions/exceptions.h>
  18. #include <dns/opcode.h>
  19. using namespace std;
  20. namespace isc {
  21. namespace dns {
  22. namespace {
  23. const char *opcodetext[] = {
  24. "QUERY",
  25. "IQUERY",
  26. "STATUS",
  27. "RESERVED3",
  28. "NOTIFY",
  29. "UPDATE",
  30. "RESERVED6",
  31. "RESERVED7",
  32. "RESERVED8",
  33. "RESERVED9",
  34. "RESERVED10",
  35. "RESERVED11",
  36. "RESERVED12",
  37. "RESERVED13",
  38. "RESERVED14",
  39. "RESERVED15"
  40. };
  41. // OPCODEs are 4-bit values. So 15 is the highest code.
  42. const uint8_t MAX_OPCODE = 15;
  43. }
  44. Opcode::Opcode(const uint8_t code) : code_(static_cast<CodeValue>(code)) {
  45. if (code > MAX_OPCODE) {
  46. isc_throw(OutOfRange,
  47. "DNS Opcode is too large to construct: " << code);
  48. }
  49. }
  50. string
  51. Opcode::toText() const {
  52. return (opcodetext[code_]);
  53. }
  54. ostream&
  55. operator<<(std::ostream& os, const Opcode& opcode) {
  56. return (os << opcode.toText());
  57. }
  58. }
  59. }