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
|
/*
* Dibbler - a portable DHCPv6
*
* authors: Tomasz Mrugalski <thomson@klub.com.pl>
* Marek Senderski <msend@o2.pl>
*
* released under GNU GPL v2 only licence
*
*/
#include <string.h>
#include "hex.h"
#include "DUID.h"
#include "Logger.h"
using namespace std;
TDUID::TDUID()
{
}
// packed
TDUID::TDUID(const char* duid,int len)
{
if (duid && len) {
DUID_.resize(len);
memcpy(&DUID_[0], duid, len);
Plain_ = hexToText((uint8_t*)&DUID_[0], DUID_.size(), true);
}
}
// plain
TDUID::TDUID(const char* text)
{
if (!text) {
return;
}
Plain_ = string(text);
DUID_ = textToHex(Plain_);
Plain_ = hexToText((uint8_t*)&DUID_[0], DUID_.size(), true);
}
TDUID::~TDUID() {
}
TDUID::TDUID(const TDUID &other) {
DUID_ = other.DUID_;
Plain_ = other.Plain_;
}
TDUID& TDUID::operator=(const TDUID &other) {
if (this == &other)
return *this;
DUID_ = other.DUID_;
Plain_ = other.Plain_;
return *this;
}
bool TDUID::operator==(const TDUID &other) {
return (DUID_ == other.DUID_);
}
bool TDUID::operator<=(const TDUID &other) {
return (DUID_ <= other.DUID_);
}
size_t TDUID::getLen() const {
return DUID_.size();
}
const string TDUID::getPlain() const {
return Plain_;
}
const char* TDUID::get() const {
return (const char*)(&DUID_[0]);
}
char * TDUID::storeSelf(char* buf) {
memcpy(buf, &DUID_[0], DUID_.size());
return buf + DUID_.size();
}
ostream& operator<<(ostream& out,TDUID& duid) {
if (duid.DUID_.size()) {
out << "<duid length=\"" << duid.DUID_.size() << "\">"
<< duid.Plain_ << "</duid>" << std::endl;
} else {
out << "<duid length=\"0\"></duid>" << std::endl;
}
return out;
}
|