merging dev

This commit is contained in:
j3d1 2016-01-21 05:19:26 +01:00
parent f2d85a67a5
commit 4543473821
2 changed files with 0 additions and 178 deletions

View file

@ -30,62 +30,6 @@ int printHeader(Packet p) {
}
int printPacket(Packet p) {
<<<<<<< HEAD
if (options.flags & FLAG_HEX) {
std::cout << "Received Payload:\n\t" << p.getBody() << "\n";
} else {
for (dataset d : p.getPayload()) {
auto lookup =
(options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup;
if (lookup.exists(d.type)) {
const table::set *s = lookup.get(d.type);
if (d.len > 0) {
switch (s->format) {
case table::STRING:
std::cout << "+\t" << s->name << " = " << &d.value[0]
<< "\n";
break;
case table::BOOL:
std::cout << "+\t" << s->name << " = " << (d.value[0]?"YES":"NO")
<< "\n";
break;
case table::HEX:
std::cout << "+\t" << s->name << " = " << d.value
<< "\n";
break;
case table::DEC:
std::cout << "+\t" << s->name << " = ";
if (d.value.size() > 0)
std::cout << std::dec << (unsigned) d.value[0];
for (unsigned i = 1; i < d.value.size(); i++)
std::cout << std::dec << "." << (unsigned) d.value[i];
std::cout << "\n";
break;
case table::ACTION:
std::cout << "Error:" << s->name
<< " is marked as 'action' but carries payload."
<< d.value << "\n";
break;
default:
std::cout << "+\t" << s->name << " = " << d.value
<< "\n";
break;
}
} else { //empty
std::cout << std::dec << ">\t" << s->name << "\n";
}
} else { //unknown id
if (d.len > 0) {
std::cout << "##\t" << d.type << ":\n\t";
std::cout << std::hex << d.value << std::dec << "\n";
} else { //empty
std::cout << "#>\t" << d.type << "\n";
}
}
}
}
return 0;
=======
if (options.flags & FLAG_HEX) {
std::cout << "Received Payload:\n\t" << p.getBody() << "\n";
} else {
@ -141,7 +85,6 @@ int printPacket(Packet p) {
}
}
return 0;
>>>>>>> 3ef2da7b7a10c8b34f20c452acc0f8d0ffc17db5
}
int Program::list() {
@ -214,71 +157,6 @@ int Program::setProperty() {
}
int Program::getProperty() {
<<<<<<< HEAD
std::cout << "List:\n";
Packet p = Packet(Packet::DISCOVERY);
p.setHostMac(host.getMac());
p.setPayload( { });
bytes b = p.getBytes();
p.encode(b);
auto s = sock;
try {
sock->setHostIp(host.getIp());
sock->init(DST_PORT, SRC_PORT);
sock->callback =
[this](Packet a) {
auto s = sock;
datasets d =a.getPayload();
Switch sw = Switch();
sw.parse(d);
std::cout <<"Devices:\n\t"<<sw.settings.hostname<<" ("<< sw.device.type<<")\tMAC: "<<sw.device.mac<<"\tIP: "<<sw.settings.ip_addr<<"\n";
Packet p = Packet(Packet::GET);
p.setSwitchMac(a.getSwitchMac());
p.setHostMac(host.getMac());
datasets t = { {snd_lookup["ping"], 0, {}}};
p.setPayload(t);
bytes c = p.getBytes();
p.encode(c);
sock->callback =
[this](Packet a) {
auto s = sock;
datasets d =a.getPayload();
Switch sw = Switch();
sw.parse(d);
Packet p = Packet(Packet::SET);
p.setSwitchMac(a.getSwitchMac());
p.setHostMac(host.getMac());
datasets t = {
{snd_lookup["login_user"], (short)(options.user.length()), options.user},
{snd_lookup["login_password"], (short)(options.password.length()), options.password}
};
std::cout<<options.user<<std::endl<<options.password<<std::endl;
p.setPayload(t);
bytes c = p.getBytes();
p.encode(c);
sock->callback =
[this](Packet a) {
std::cout << a.opCodeToString() << "\n";
printHeader(a);
printPacket(a);
return 0;
};
sock->send(c);
return 0;
};
sock->send(c);
return 0;
};
sock->send(b);
io_service->run();
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}
return 1;
=======
std::cout << "List:\n";
Packet p = Packet(Packet::DISCOVERY);
p.setHostMac(host.getMac());
@ -348,7 +226,6 @@ int Program::getProperty() {
std::cerr << "Exception: " << e.what() << "\n";
}
return 1;
>>>>>>> 3ef2da7b7a10c8b34f20c452acc0f8d0ffc17db5
}
int Program::save() {
@ -389,11 +266,6 @@ int Program::ping(std::function<int(Packet)>) {
return 0;
}
int Program::ping(std::function<int(Packet)>){
return 0;
}
void Program::init() {
if (options.interface.compare("") == 0)
options.interface = host.getIface();

View file

@ -8,11 +8,7 @@
#include <string>
#include "Types.h"
#include "Switch.h"
<<<<<<< HEAD
#include "Lookup.h"
=======
#include "lookup.h"
>>>>>>> 3ef2da7b7a10c8b34f20c452acc0f8d0ffc17db5
#include "Constant.h"
#include "table.h"
@ -24,51 +20,6 @@ int Switch::parse(datasets arr) {
}
int Switch::parse(dataset d) {
<<<<<<< HEAD
auto lookup = (options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup;
std::string id = lookup.exists(d.type)?lookup[d.type]:"unknown";
if (d.type == lookup["type"]) {
device.type = d.value;
}
else if (id == "mac") {
device.mac = d.value;
}
else if (d.type == lookup["firmware_version"]) {
device.firmware_version = d.value;
}
else if (id == "hardware_version") {
device.hardware_version = d.value;
}
else if (id == "ports") {
device.ports = d.value[0];
}
else if (id == "hostname") {
settings.hostname = d.value;
}
else if (id == "ip_addr") {
settings.ip_addr = d.value;
}
else if (id == "ip_mask") {
settings.ip_mask = d.value;
}
else if (id == "gateway") {
settings.gateway = d.value;
}
else if (id == "dhcp_enabled") {
settings.dhcp = d.value[0];
}
else if (id == "loop_prevention") {
settings.loop_prevention = d.value[0];
}
else if (id == "qos_basic_enabled") {
settings.qos_enabled = d.value[0];
}
else if (id == "vlan_enabled") {
settings.vlan_enabled = d.value[0];
}
return 0;
}
=======
switch (d.type) {
case RCV_TYPE:
device.type = d.value;
@ -113,4 +64,3 @@ int Switch::parse(dataset d) {
return 0;
}
>>>>>>> 3ef2da7b7a10c8b34f20c452acc0f8d0ffc17db5