1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
- //
- // Permission to use, copy, modify, and/or distribute this software for any
- // purpose with or without fee is hereby granted, provided that the above
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- // $Id$
- #include <sstream>
- #include <stdint.h>
- #include "buffer.h"
- #include "messagerenderer.h"
- #include "rrttl.h"
- #include <iostream>
- using namespace std;
- using namespace isc::dns;
- namespace isc {
- namespace dns {
- RRTTL::RRTTL(const string& ttlstr)
- {
- // Some systems (at least gcc-4.4) flow negative values over into
- // unsigned integer, where older systems failed to parse. We want
- // that failure here, so we extract into int64 and check the value
- uint64_t val;
- istringstream iss(ttlstr);
- iss >> dec >> val;
- if (iss.rdstate() == ios::eofbit && val >= 0 && val <= 0xffffffff) {
- ttlval_ = static_cast<uint32_t>(val);
- } else {
- dns_throw(InvalidRRTTL, "invalid TTL");
- }
- }
- RRTTL::RRTTL(InputBuffer& buffer)
- {
- if (buffer.getLength() - buffer.getPosition() < sizeof(uint32_t)) {
- dns_throw(IncompleteRRTTL, "incomplete wire-format TTL value");
- }
- ttlval_ = buffer.readUint32();
- }
- const string
- RRTTL::toText() const
- {
- ostringstream oss;
- oss << ttlval_;
- return (oss.str());
- }
- void
- RRTTL::toWire(OutputBuffer& buffer) const
- {
- buffer.writeUint32(ttlval_);
- }
- void
- RRTTL::toWire(MessageRenderer& renderer) const
- {
- renderer.writeUint32(ttlval_);
- }
- ostream&
- operator<<(ostream& os, const RRTTL& rrttl)
- {
- os << rrttl.toText();
- return (os);
- }
- }
- }
|