File: OptTA.cpp

package info (click to toggle)
dibbler 0.7.3-1.3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,148 kB
  • ctags: 8,720
  • sloc: cpp: 54,863; sh: 9,389; ansic: 8,659; yacc: 2,570; makefile: 1,061; lex: 842; perl: 49; xml: 6
file content (114 lines) | stat: -rw-r--r-- 2,377 bytes parent folder | download | duplicates (2)
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
/*
 * Dibbler - a portable DHCPv6
 *
 * authors: Tomasz Mrugalski <thomson@klub.com.pl>
 *          Marek Senderski <msend@o2.pl>
 *
 * released under GNU GPL v2 licence
 *
 * $Id: OptTA.cpp,v 1.2 2006-03-05 21:37:46 thomson Exp $
 */

#ifdef WIN32
#include <winsock2.h>
#endif
#ifdef LINUX
#include <netinet/in.h>
#endif 

#include "OptTA.h"
#include "OptIAAddress.h"
#include "OptStatusCode.h"
#include "Logger.h"

TOptTA::TOptTA( long IAID, TMsg* parent)
	:TOpt(OPTION_IA_TA, parent) {
    this->IAID = IAID;
}

unsigned long TOptTA::getIAID() {
    return IAID;
}

TOptTA::TOptTA( char * &buf, int &bufsize, TMsg* parent)
    :TOpt(OPTION_IA_TA, parent) {
    if (bufsize<OPTION_IA_TA_LEN) {
        Valid=false;
        bufsize=0;
    } else {
        Valid=true;
        this->IAID = ntohl(*( long*)buf);
        buf+=4; bufsize-=4;
    }
}

int TOptTA::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 TOptTA::getSize() {
    return 4+OPTION_IA_TA_LEN+getSubOptSize();
}

char * TOptTA::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;
    buf=this->storeSubOpt(buf);
    return buf;
}

unsigned long TOptTA::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 TOptTA::isValid() {
    return this->Valid;
}

/*
 * How many addresses is stored in this IA
 */
int TOptTA::countAddrs() {
    int cnt = 0;
    SmartPtr<TOpt> opt;
    this->firstOption();
    while (opt = this->getOption() ) {
	if (opt->getOptType() == OPTION_IAADDR)
	    cnt++;
    }
    return cnt;
}
/*
 * $Log: OptTA.cpp,v $
 * Revision 1.2  2006-03-05 21:37:46  thomson
 * TA support merged.
 *
 * Revision 1.1.2.1  2006/02/05 23:39:52  thomson
 * Initial revision.
 *
 */