File: OptTA.cpp

package info (click to toggle)
dibbler 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,352 kB
  • sloc: cpp: 60,323; ansic: 12,235; sh: 11,951; yacc: 3,418; lex: 969; makefile: 940; perl: 319; xml: 116; python: 74
file content (98 lines) | stat: -rw-r--r-- 2,215 bytes parent folder | download | duplicates (3)
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
/*
 * 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 $
 */

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

TOptTA::TOptTA(uint32_t iaid, TMsg* parent)
    :TOpt(OPTION_IA_TA, parent), IAID_(iaid), Valid_(true) {
}

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

TOptTA::TOptTA(char * &buf, int &bufsize, TMsg* parent)
    :TOpt(OPTION_IA_TA, parent), Valid_(false) {
    if (bufsize < OPTION_IA_TA_LEN) {
        buf += bufsize;
        bufsize = 0;
        return;
    }

    IAID_ = readUint32(buf);
    buf += sizeof(uint32_t);
    bufsize -= sizeof(uint32_t);
    Valid_ = true;

    /// @todo: Parse suboptions
}

int TOptTA::getStatusCode() {
    SPtr<TOpt> ptrOpt;
    SubOptions.first();
    while ( ptrOpt = SubOptions.get() ) {
        if ( ptrOpt->getOptType() == OPTION_STATUS_CODE) {
            SPtr <TOptStatusCode> ptrStatus;
            ptrStatus = (Ptr*) ptrOpt;
            return ptrStatus->getCode();
        }
    }
    return -1;
}

size_t TOptTA::getSize() {
    return 4 + OPTION_IA_TA_LEN + getSubOptSize();
}

char * TOptTA::storeSelf( char* buf) {
    buf = writeUint16(buf, OptType);
    buf = writeUint16(buf, getSize()-4);
    buf = writeUint32(buf, IAID_);
    buf = storeSubOpt(buf);
    return buf;
}

unsigned long TOptTA::getMaxValid() {
    unsigned long maxValid=0;
    SPtr<TOpt> ptrOpt;
    SubOptions.first();
    while (ptrOpt=SubOptions.get())
    {
        if (ptrOpt->getOptType()==OPTION_IAADDR) {
            SPtr<TOptIAAddress> ptrIAAddr=(Ptr*)ptrOpt;
            if (maxValid<ptrIAAddr->getValid())
                maxValid=ptrIAAddr->getValid();
        }
    }
    return maxValid;
}

bool TOptTA::isValid() const {
    return this->Valid;
}

/*
 * How many addresses is stored in this IA
 */
int TOptTA::countAddrs() {
    int cnt = 0;
    SPtr<TOpt> opt;
    this->firstOption();
    while (opt = this->getOption() ) {
        if (opt->getOptType() == OPTION_IAADDR)
            cnt++;
    }
    return cnt;
}