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 licence
*
*/
#include <string.h>
#include <string>
#include "Portable.h"
#include "OptStatusCode.h"
#include "Logger.h"
#if defined(LINUX) || defined(BSD)
#include <arpa/inet.h>
#endif
using namespace std;
TOptStatusCode::TOptStatusCode(const char * buf, size_t len, TMsg* parent)
:TOpt(OPTION_STATUS_CODE, parent), Valid_(false)
{
if (len < 2) {
buf += len;
len = 0;
return;
}
StatusCode_ = readUint16(buf);
buf += sizeof(uint16_t);
len -= sizeof(uint16_t);
char *msg = new char[len+1];
memcpy(msg, buf, len);
msg[len]=0;
Message_ = (string)msg;
delete [] msg;
Valid_ = true;
}
size_t TOptStatusCode::getSize() {
return Message_.length() + 6;
}
int TOptStatusCode::getCode() {
return StatusCode_;
}
string TOptStatusCode::getText() {
return Message_;
}
char * TOptStatusCode::storeSelf( char* buf)
{
buf = writeUint16(buf, OptType);
buf = writeUint16(buf, getSize()-4);
buf = writeUint16(buf, StatusCode_);
strncpy((char *)buf, Message_.c_str(), Message_.length());
buf += Message_.length();
return buf;
}
TOptStatusCode::TOptStatusCode(int status,const std::string& message, TMsg* parent)
:TOpt(OPTION_STATUS_CODE, parent), Message_(message), StatusCode_(status),
Valid_(true) {
}
bool TOptStatusCode::doDuties()
{
switch (StatusCode_) {
case STATUSCODE_SUCCESS:
Log(Notice) << "Status SUCCESS :" << Message_ << LogEnd;
break;
case STATUSCODE_UNSPECFAIL:
Log(Notice) << "Status UNSPECIFIED FAILURE :" << Message_ << LogEnd;
break;
case STATUSCODE_NOADDRSAVAIL:
Log(Notice) << "Status NO ADDRS AVAILABLE :" << Message_ << LogEnd;
break;
case STATUSCODE_NOBINDING:
Log(Notice) << "Status NO BINDING:" << Message_ << LogEnd;
break;
case STATUSCODE_NOTONLINK:
Log(Notice) << "Status NOT ON LINK:" << Message_ << LogEnd;
break;
case STATUSCODE_USEMULTICAST:
Log(Notice) << "Status USE MULTICAST:" << Message_ << LogEnd;
break;
case STATUSCODE_NOPREFIXAVAIL:
Log(Notice) << "Status NO PREFIX AVAILABLE :" << Message_ << LogEnd;
break;
}
return true;
}
|