File: RelCfgIface.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 (120 lines) | stat: -rw-r--r-- 3,046 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Dibbler - a portable DHCPv6
 *
 * authors: Tomasz Mrugalski <thomson@klub.com.pl>
 *
 * released under GNU GPL v2 only licence
 *
 */

#include <sstream>
#include "DHCPDefaults.h"
#include "RelCfgIface.h"
#include "Logger.h"

using namespace std;

TRelCfgIface::TRelCfgIface(int ifindex)
    :Name_("[unknown]"), ID_(ifindex), InterfaceID_(-1),
     ClientUnicast_(), ServerUnicast_(),
     ClientMulticast_(false), ServerMulticast_(false) {
}

TRelCfgIface::TRelCfgIface(const std::string& ifaceName)
    :Name_(ifaceName), ID_(-1), InterfaceID_(-1),
     ClientUnicast_(), ServerUnicast_(),
     ClientMulticast_(false), ServerMulticast_(false) {
}

int TRelCfgIface::getID() {
    return ID_;
}

string TRelCfgIface::getName() {
    return Name_;
}

string TRelCfgIface::getFullName() {
    ostringstream oss;
    oss << ID_;
    return Name_ + "/" + oss.str();
}

TRelCfgIface::~TRelCfgIface() {
}

SPtr<TIPv6Addr> TRelCfgIface::getServerUnicast() {
    return ServerUnicast_;
}

SPtr<TIPv6Addr> TRelCfgIface::getClientUnicast() {
    return ClientUnicast_;
}

bool TRelCfgIface::getClientMulticast() {
    return ClientMulticast_;
}

bool TRelCfgIface::getServerMulticast() {
    return ServerMulticast_;
}

void TRelCfgIface::setOptions(SPtr<TRelParsGlobalOpt> opt) {
    ClientUnicast_ = opt->getClientUnicast();
    ServerUnicast_ = opt->getServerUnicast();
    ClientMulticast_ = opt->getClientMulticast();
    ServerMulticast_ = opt->getServerMulticast();
    InterfaceID_ = opt->getInterfaceID();
}

void TRelCfgIface::setName(std::string ifaceName) {
    Name_ = ifaceName;
}

void TRelCfgIface::setID(int ifaceID) {
    ID_ = ifaceID;
}

int TRelCfgIface::getInterfaceID() {
    return InterfaceID_;
}

// --------------------------------------------------------------------
// --- operators ------------------------------------------------------
// --------------------------------------------------------------------

ostream& operator<<(ostream& out, TRelCfgIface& iface) {
    SPtr<TIPv6Addr> addr;
    SPtr<string> str;

    out << dec;
    out << "  <RelCfgIface name=\"" << iface.Name_ << "\" ifindex=\"" << iface.ID_
        << "\" interfaceID=\"" << iface.InterfaceID_ << "\">" << std::endl;

    if (iface.ClientUnicast_) {
        out << "    <ClientUnicast>" << iface.ClientUnicast_->getPlain()
            << "</ClientUnicast>" << endl;
    } else {
        out << "    <!-- <ClientUnicast/> -->" << endl;
    }
    if (iface.ClientMulticast_) {
        out << "    <ClientMulticast/>" << endl;
    } else {
        out << "    <!-- <ClientMulticast/> -->" << endl;
    }

    if (iface.ServerUnicast_) {
        out << "    <ServerUnicast>" << iface.ServerUnicast_->getPlain()
            << "</ServerUnicast>" << endl;
    } else {
        out << "    <!-- <ServerUnicast/> -->" << endl;
    }
    if (iface.ServerMulticast_) {
        out << "    <ServerMulticast/>" << endl;
    } else {
        out << "    <!-- <ServerMulticast/> -->" << endl;
    }

    out << "  </RelCfgIface>" << endl;
    return out;
}