Kea  1.9.9-git
opcode.cc
Go to the documentation of this file.
1 // Copyright (C) 2010-2016 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <string>
10 #include <ostream>
11 
12 #include <exceptions/exceptions.h>
13 
14 #include <dns/opcode.h>
15 
16 using namespace std;
17 
18 namespace isc {
19 namespace dns {
20 namespace {
21 const char *opcodetext[] = {
22  "QUERY",
23  "IQUERY",
24  "STATUS",
25  "RESERVED3",
26  "NOTIFY",
27  "UPDATE",
28  "RESERVED6",
29  "RESERVED7",
30  "RESERVED8",
31  "RESERVED9",
32  "RESERVED10",
33  "RESERVED11",
34  "RESERVED12",
35  "RESERVED13",
36  "RESERVED14",
37  "RESERVED15"
38 };
39 
40 // OPCODEs are 4-bit values. So 15 is the highest code.
41 const uint8_t MAX_OPCODE = 15;
42 }
43 
44 Opcode::Opcode(const uint8_t code) : code_(static_cast<CodeValue>(code)) {
45  if (code > MAX_OPCODE) {
47  "DNS Opcode is too large to construct: "
48  << static_cast<unsigned>(code));
49  }
50 }
51 
52 string
53 Opcode::toText() const {
54  return (opcodetext[code_]);
55 }
56 
57 ostream&
58 operator<<(std::ostream& os, const Opcode& opcode) {
59  return (os << opcode.toText());
60 }
61 }
62 }
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
CodeValue
Constants for standard OPCODE values.
Definition: opcode.h:35
std::string toText() const
Convert the Opcode to a string.
Definition: opcode.cc:53
STL namespace.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-dhcp-ddns.
uint16_t code_
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The Opcode class objects represent standard OPCODEs of the header section of DNS messages as defined ...
Definition: opcode.h:32