Branch data Line data Source code
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 : :
15 : : #include <stdint.h>
16 : :
17 : : #include <string>
18 : :
19 : : #include <exceptions/exceptions.h>
20 : :
21 : : #include <util/buffer.h>
22 : : #include <dns/messagerenderer.h>
23 : : #include <dns/rrparamregistry.h>
24 : : #include <dns/rrclass.h>
25 : :
26 : : using namespace std;
27 : : using namespace isc::dns;
28 : : using namespace isc::util;
29 : :
30 : : namespace isc {
31 : : namespace dns {
32 : :
33 : 11207 : RRClass::RRClass(const string& classstr) {
34 : 11207 : classcode_ = RRParamRegistry::getRegistry().textToClassCode(classstr);
35 : 11188 : }
36 : :
37 : 9 : RRClass::RRClass(InputBuffer& buffer) {
38 [ + + ]: 9 : if (buffer.getLength() - buffer.getPosition() < sizeof(uint16_t)) {
39 [ + - ]: 6 : isc_throw(IncompleteRRClass, "incomplete wire-format RR class");
40 : : }
41 : 6 : classcode_ = buffer.readUint16();
42 : 6 : }
43 : :
44 : : const string
45 : 10131 : RRClass::toText() const {
46 : 10131 : return (RRParamRegistry::getRegistry().codeToClassText(classcode_));
47 : : }
48 : :
49 : : void
50 : 101 : RRClass::toWire(OutputBuffer& buffer) const {
51 : 101 : buffer.writeUint16(classcode_);
52 : 101 : }
53 : :
54 : : void
55 : 1716 : RRClass::toWire(AbstractMessageRenderer& renderer) const {
56 : 1716 : renderer.writeUint16(classcode_);
57 : 1716 : }
58 : :
59 : : ostream&
60 : 4119 : operator<<(ostream& os, const RRClass& rrclass) {
61 [ + - ]: 4119 : os << rrclass.toText();
62 : 4119 : return (os);
63 : : }
64 : : }
65 : 3542 : }
|