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
|
/*
* Dibbler - a portable DHCPv6
*
* authors: Tomasz Mrugalski <thomson@klub.com.pl>
* Marek Senderski <msend@o2.pl>
*
* released under GNU GPL v2 licence
*
*/
#include <stdlib.h>
#include <sstream>
#include "Portable.h"
#include "OptAddrLst.h"
#include "DHCPConst.h"
TOptAddrLst::TOptAddrLst(int type, List(TIPv6Addr) lst, TMsg* parent)
:TOpt(type, parent), AddrLst(lst) {
}
TOptAddrLst::TOptAddrLst(int type, const char* buf, unsigned short bufSize, TMsg* parent)
:TOpt(type, parent)
{
while(bufSize>0)
{
if (bufSize<16) {
Valid = false;
return;
}
this->AddrLst.append(new TIPv6Addr(buf));
buf +=16;
bufSize -= 16;
}
Valid = true;
return;
}
char * TOptAddrLst::storeSelf(char* buf) {
SPtr<TIPv6Addr> addr;
buf = writeUint16(buf, OptType);
buf = writeUint16(buf, getSize()-4);
AddrLst.first();
while(addr=AddrLst.get())
buf=addr->storeSelf(buf);
return buf;
}
size_t TOptAddrLst::getSize()
{
return 4+16*AddrLst.count();
}
void TOptAddrLst::firstAddr() {
this->AddrLst.first();
}
SPtr<TIPv6Addr> TOptAddrLst::getAddr()
{
return this->AddrLst.get();
}
bool TOptAddrLst::isValid() const
{
return this->Valid;
}
std::string TOptAddrLst::getPlain() {
std::stringstream tmp;
AddrLst.first();
SPtr<TIPv6Addr> addr;
while (addr = AddrLst.get()) {
tmp << addr->getPlain() << " ";
}
return tmp.str();
}
|