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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
* Dibbler - a portable DHCPv6
*
* authors: Tomasz Mrugalski <thomson@klub.com.pl>
* Marek Senderski <msend@o2.pl>
*
* released under GNU GPL v2 licence
*
* $Id: OptIA_NA.cpp,v 1.8 2008-08-17 22:41:43 thomson Exp $
*
* $Log: OptIA_NA.cpp,v $
* Revision 1.8 2008-08-17 22:41:43 thomson
* CONFIRM improvements (patch sent by Liu Ming)
*
* Revision 1.7 2007-01-21 19:17:58 thomson
* Option name constants updated (by Jyrki Soini)
*
* Revision 1.6 2004-09-07 22:02:33 thomson
* pref/valid/IAID is not unsigned, RAPID-COMMIT now works ok.
*
* Revision 1.5 2004/06/17 23:53:54 thomson
* Server Address Assignment rewritten.
*
* Revision 1.4 2004/06/04 19:03:46 thomson
* Resolved warnings with signed/unisigned
*
* Revision 1.2 2004/03/29 18:53:08 thomson
* Author/Licence/cvs log/cvs version headers added.
*
*/
#ifdef WIN32
#include <winsock2.h>
#endif
#ifdef LINUX
#include <netinet/in.h>
#endif
#include "OptIA_NA.h"
#include "OptIAAddress.h"
#include "OptStatusCode.h"
//#include "OptRapidCommit.h"
TOptIA_NA::TOptIA_NA( long IAID, long t1, long t2, TMsg* parent)
:TOpt(OPTION_IA_NA, parent) {
this->IAID = IAID;
this->T1 = t1;
this->T2 = t2;
}
unsigned long TOptIA_NA::getIAID() {
return IAID;
}
unsigned long TOptIA_NA::getT1() {
return T1;
}
void TOptIA_NA::setT1(unsigned long t1) {
this->T1 = t1;
}
unsigned long TOptIA_NA::getT2() {
return T2;
}
void TOptIA_NA::setT2(unsigned long t2) {
this->T2 = t2;
}
TOptIA_NA::TOptIA_NA( char * &buf, int &bufsize, TMsg* parent)
:TOpt(OPTION_IA_NA, parent) {
if (bufsize<12) {
Valid=false;
bufsize=0;
} else {
Valid=true;
IAID = ntohl(*( long*)buf);
T1 = ntohl(*( long*)(buf+4));
T2 = ntohl(*( long*)(buf+8));
buf+=12; bufsize-=12;
}
}
int TOptIA_NA::getStatusCode() {
SmartPtr<TOpt> ptrOpt;
SubOptions.first();
while ( ptrOpt = SubOptions.get() ) {
if ( ptrOpt->getOptType() == OPTION_STATUS_CODE) {
SmartPtr <TOptStatusCode> ptrStatus;
ptrStatus = (Ptr*) ptrOpt;
return ptrStatus->getCode();
}
}
return -1;
}
int TOptIA_NA::getSize() {
int mySize = 16;
return mySize+getSubOptSize();
}
char * TOptIA_NA::storeSelf( char* buf) {
*(uint16_t*)buf = htons(OptType);
buf+=2;
*(uint16_t*)buf = htons( getSize()-4 );
buf+=2;
*(uint32_t*)buf = htonl(IAID);
buf+=4;
*(uint32_t*)buf = htonl(T1);
buf+=4;
*(uint32_t*)buf = htonl(T2);
buf+=4;
buf=this->storeSubOpt(buf);
return buf;
}
unsigned long TOptIA_NA::getMaxValid() {
unsigned long maxValid=0;
SmartPtr<TOpt> ptrOpt;
SubOptions.first();
while (ptrOpt=SubOptions.get())
{
if (ptrOpt->getOptType()==OPTION_IAADDR) {
SmartPtr<TOptIAAddress> ptrIAAddr=(Ptr*)ptrOpt;
if (maxValid<ptrIAAddr->getValid())
maxValid=ptrIAAddr->getValid();
}
}
return maxValid;
}
bool TOptIA_NA::isValid() {
return this->Valid;
}
/*
* How many addresses is stored in this IA
*/
int TOptIA_NA::countAddrs() {
int cnt = 0;
SmartPtr<TOpt> opt;
this->firstOption();
while (opt = this->getOption() ) {
if (opt->getOptType() == OPTION_IAADDR)
cnt++;
}
return cnt;
}
|