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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
* Dibbler - a portable DHCPv6
*
* authors: Tomasz Mrugalski <thomson@klub.com.pl>
* Marek Senderski <msend@o2.pl>
*
* released under GNU GPL v2 licence
*
* $Id: OptVendorSpecInfo.cpp,v 1.10 2008-03-02 19:19:43 thomson Exp $
*
*/
#include <iostream>
#include <sstream>
#include "Portable.h"
#include "OptVendorSpecInfo.h"
#include "DHCPConst.h"
#include "Logger.h"
TOptVendorSpecInfo::TOptVendorSpecInfo(int type, char * &buf, int &n, TMsg* parent)
:TOpt(type, parent)
{
if (n<4) {
Log(Error) << "Unable to parse vendor-spec info option." << LogEnd;
this->Vendor = 0;
this->VendorData = 0;
this->VendorDataLen = 0;
return;
}
this->Vendor = ntohl(*(int*)buf); // enterprise number
buf += 4;
n -= 4;
if (!n) {
this->VendorData = 0;
this->VendorDataLen = 0;
return;
}
if (n) {
this->VendorData = new char[n];
memmove(this->VendorData, buf, n);
} else {
this->VendorData = 0;
}
this->VendorDataLen = n;
buf += n;
n = 0;
}
TOptVendorSpecInfo::TOptVendorSpecInfo(int type, int enterprise, char *data, int dataLen, TMsg* parent)
:TOpt(type, parent)
{
this->Vendor = enterprise;
this->VendorData = new char[dataLen];
memmove(this->VendorData, data, dataLen);
this->VendorDataLen = dataLen;
}
TOptVendorSpecInfo::~TOptVendorSpecInfo()
{
if (this->VendorDataLen)
delete [] VendorData;
}
int TOptVendorSpecInfo::getSize()
{
return 8+this->VendorDataLen; /* normal header(4) + enterprise(4) */
}
char * TOptVendorSpecInfo::storeSelf( char* buf)
{
*(uint16_t*)buf = htons(OptType);
buf+=2;
*(uint16_t*)buf = htons( getSize()-4 );
buf+=2;
*(uint32_t*)buf = htonl(this->Vendor);
buf+=4;
memmove(buf, this->VendorData, this->VendorDataLen);
buf+=this->VendorDataLen;
return buf;
}
bool TOptVendorSpecInfo::isValid()
{
return true;
}
int TOptVendorSpecInfo::getVendor()
{
return this->Vendor;
}
char * TOptVendorSpecInfo::getVendorData()
{
return this->VendorData;
}
string TOptVendorSpecInfo::getVendorDataPlain()
{
ostringstream tmp;
tmp << "0x";
for (int i=0; i<this->VendorDataLen; i++) {
tmp << setfill('0') << setw(2) << hex << (unsigned int) this->VendorData[i];
}
return tmp.str();
}
int TOptVendorSpecInfo::getVendorDataLen()
{
return this->VendorDataLen;
}
|