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
|
/*
* Dibbler - a portable DHCPv6
*
* authors: Tomasz Mrugalski <thomson@klub.com.pl>
* Marek Senderski <msend@o2.pl>
*
* released under GNU GPL v2 licence
*
* $Id: OptStatusCode.cpp,v 1.7 2007-08-26 10:26:19 thomson Exp $
*
*/
#include <stdlib.h>
#include <string>
#include "Portable.h"
#include "OptStatusCode.h"
#include "Logger.h"
TOptStatusCode::TOptStatusCode( char * &buf, int &len, TMsg* parent)
:TOpt(OPTION_STATUS_CODE, parent)
{
Valid=true;
if (len<2)
{
Valid=false;
buf+=len;
len=0;
return;
}
this->StatusCode = ntohs(*(short*)buf);
buf +=2; len -=2;
char *Message = new char[len+1];
memcpy(Message,buf,len);
Message[len]=0;
this->Message=(string)Message;
delete [] Message;
}
int TOptStatusCode::getSize()
{
return (int)(this->Message.length()+6);
}
int TOptStatusCode::getCode()
{
return StatusCode;
}
string TOptStatusCode::getText()
{
return Message;
}
char * TOptStatusCode::storeSelf( char* buf)
{
*(short*)buf = htons(OptType);
buf+=2;
*(short*)buf = htons(getSize()-4);
buf+=2;
*(short*)buf = htons(this->StatusCode);
buf+=2;
strncpy((char *)buf,Message.c_str(),Message.length());
buf+=Message.length();
return buf;
}
TOptStatusCode::TOptStatusCode(int status,string message, TMsg* parent)
:TOpt(OPTION_STATUS_CODE, parent)
{
this->StatusCode = status;
this->Message = message;
}
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;
}
|