1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/*
* Dibbler - a portable DHCPv6
*
* authors: Mateusz Ozga <matozga@gmail.com>
* changes: Tomek Mrugalski <thomson@klub.com.pl>
*
* Released under GNU GPL v2 licence
*
*/
#include <sstream>
#include "DHCPConst.h"
#include "OptRtPrefix.h"
#include "Logger.h"
#include "Portable.h"
using namespace std;
TOptRtPrefix::TOptRtPrefix(uint32_t lifetime, uint8_t prefixlen, uint8_t metric, SPtr<TIPv6Addr> prefix, TMsg* parent)
:TOpt(OPTION_RTPREFIX, parent), Lifetime(lifetime), PrefixLen(prefixlen), Metric(metric), Prefix(prefix) {
}
TOptRtPrefix::TOptRtPrefix(const char * buf, int bufsize, TMsg* parent)
:TOpt(OPTION_RTPREFIX, parent) {
if (bufsize<20) {
Log(Warning) << "Received truncated RTPREFIX option" << LogEnd;
Valid = false;
return;
}
Lifetime = readUint32(buf);
buf += sizeof(uint32_t);
bufsize -= sizeof(uint32_t);
PrefixLen = buf[0];
buf += 1;
bufsize -= 1;
Metric = buf[0];
buf += 1;
bufsize -= 1;
Prefix = new TIPv6Addr(buf, false);
buf += 16;
bufsize -= 16;
Valid = parseOptions(SubOptions, buf, bufsize, parent, OPTION_RTPREFIX);
}
char* TOptRtPrefix::storeSelf(char* buf) {
buf = storeHeader(buf);
buf = writeUint32(buf, Lifetime);
buf[0] = PrefixLen;
buf[1] = Metric;
buf += 2;
buf = Prefix->storeSelf(buf);
return storeSubOpt(buf);
}
uint32_t TOptRtPrefix::getLifetime()
{
return Lifetime;
}
uint8_t TOptRtPrefix::getPrefixLen()
{
return PrefixLen;
}
uint8_t TOptRtPrefix::getMetric()
{
return Metric;
}
SPtr<TIPv6Addr> TOptRtPrefix::getPrefix() {
return Prefix;
}
size_t TOptRtPrefix::getSize() {
return 4 + 22 + getSubOptSize();
}
std::string TOptRtPrefix::getPlain() {
stringstream tmp;
tmp << Prefix->getPlain() << "/" << (unsigned int)PrefixLen << " " << Lifetime
<< " " << (unsigned int)Metric;
return tmp.str();
}
|