experimental stuff

This commit is contained in:
j3d1 2016-01-16 23:33:04 +01:00
parent 96a10549d7
commit 5b61676236
6 changed files with 161 additions and 60 deletions

View file

@ -57,15 +57,6 @@ ipAddr Host::getIp() {
return data; return data;
} }
} }
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
if (ifa->ifa_addr == NULL)
continue;
if (ifa->ifa_addr->sa_family == AF_INET)
if (getIface().compare(ifa->ifa_name) == 0) {
memcpy(&data[0], &ifa->ifa_addr->sa_data[2], 4);
return data;
}
}
freeifaddrs(ifaddr); freeifaddrs(ifaddr);
return data; return data;
} }

View file

@ -7,43 +7,46 @@
#include "table.h" #include "table.h"
static table rcv_lookup = { { 1, table::STRING, "type" }, //string const static table rcv_lookup = { //
{ 2, table::STRING, "hostname" }, //string { 1, table::STRING, "type" }, //+string
{ 3, table::HEX, "mac" }, //byte[6] { 2, table::STRING, "hostname" }, //+string
{ 4, table::DEC, "ip_addr" }, //byte[4] { 3, table::HEX, "mac" }, //+byte[6]
{ 5, table::DEC, "ip_mask" }, //byte[4] { 4, table::DEC, "ip_addr" }, //+byte[4]
{ 6, table::DEC, "gateway" }, //byte[4] { 5, table::DEC, "ip_mask" }, //+byte[4]
{ 7, table::STRING, "firmware_version" }, { 6, table::DEC, "gateway" }, //+byte[4]
{ 8, table::STRING, "hardware_version" }, { 7, table::STRING, "firmware_version" },//+
{ 9, table::DEC, "dhcp" }, //bool byte { 8, table::STRING, "hardware_version" },//+
{ 10, table::DEC, "ports" }, //byte, maybe number of ports { 9, table::DEC, "dhcp" }, //+bool byte
{ 4352, table::HEX, "igmp_snooping" }, //switching { 10, table::DEC, "ports" }, //+byte, maybe number of ports
{ 4096, table::HEX, "port_settings" }, //per port
{ 4352, table::HEX, "igmp_snooping" }, //???
{ 4096, table::HEX, "port_settings" }, //+per port
{ 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask?? { 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask??
{ 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool,second byte port id { 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool,second byte port id
{ 8448, table::HEX, "port_vlan_1" }, //??? { 8448, table::HEX, "port_vlan_1" }, //???
{ 8450, table::HEX, "port_vlan_2" }, //??? { 8450, table::HEX, "port_vlan_2" }, //???
{ 8704, table::HEX, "vlan enabled" }, //bool byte { 8704, table::HEX, "vlan_enabled" }, //+bool byte
{ 8705, table::HEX, "vlan" }, //one set per vlan { 8705, table::HEX, "vlan" }, //+one set per vlan
{ 8706, table::HEX, "vlan_pvid" }, //per port { 8706, table::HEX, "vlan_pvid" }, //+per port
{ 8707, table::HEX, "vlan ?????" }, //???? { 8707, table::HEX, "vlan ?????" }, //????
{ 12288, table::HEX, "qos_basic_1" }, //bool = QoS Mod
{ 12289, table::HEX, "qos_basic_2" }, //per port
{ 12544, table::HEX, "bandwidth_control_1" }, //per port
{ 12545, table::HEX, "bandwidth_control_2" }, //per port
{ 12800, table::HEX, "storm_control" }, //per port
{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id??
{ 16384, table::HEX, "port_statistics" }, //per port
{ 16896, table::HEX, "cable_test" }, //per port
{ 17152, table::HEX, "loop_prevention" }, //bool byte
{ 12288, table::HEX, "qos_basic_enabled" }, //+bool = QoS Mod
{ 12289, table::HEX, "qos_basic" }, //+per port ???
{ 12544, table::HEX, "bandwidth_control_1" }, //+per port ???
{ 12545, table::HEX, "bandwidth_control_2" }, //+per port ???
{ 12800, table::HEX, "storm_control" }, //+per port ???
{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id???
{ 16384, table::HEX, "port_statistics" }, //+per port ???
{ 16896, table::HEX, "cable_test" }, //+per port ???
{ 17152, table::HEX, "loop_prevention" }, //+bool byte
//{0000," "}, //{0000," "},
}; };
static table snd_lookup = { const static table snd_lookup = {
// TODO find out if id is unique in response // TODO find out if id is unique in response
{ 2, table::HEX, "system_info" }, //page sysinfo { 2, table::HEX, "system_info" }, //page sysinfo
{ 9, table::HEX, "ip_config" }, //page sysinfo { 9, table::HEX, "ip_config" }, //page sysinfo
{ 10, table::HEX, "ports" }, //after login { 10, table::HEX, "ports" }, //after login
@ -52,6 +55,7 @@ static table snd_lookup = {
{ 514, table::STRING, "login_password" }, //string { 514, table::STRING, "login_password" }, //string
{ 515, table::STRING, "new_passwoord" }, //string { 515, table::STRING, "new_passwoord" }, //string
{ 773, table::HEX, "reboot" }, //bool byte = save config { 773, table::HEX, "reboot" }, //bool byte = save config
{ 1280, table::ACTION, "reset" }, // { 1280, table::ACTION, "reset" }, //
{ 1536, table::ACTION, "flash" }, //update firmware { 1536, table::ACTION, "flash" }, //update firmware
@ -59,10 +63,10 @@ static table snd_lookup = {
{ 2304, table::ACTION, "save" }, //save { 2304, table::ACTION, "save" }, //save
{ 2305, table::ACTION, "ping" }, //sent before SET ??? { 2305, table::ACTION, "ping" }, //sent before SET ???
{ 4352, table::HEX, "igmp_snooping" }, //switching { 4352, table::HEX, "igmp_snooping" }, //switching
{ 4096, table::HEX, "port_settings" }, //switching { 4096, table::HEX, "port_settings" }, //switching
{ 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask?? { 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask??
{ 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool, second byte port id { 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool, second byte port id
{ 8449, table::HEX, "port_vlan ???" }, //??? { 8449, table::HEX, "port_vlan ???" }, //???
{ 8448, table::HEX, "port_vlan" }, //open page { 8448, table::HEX, "port_vlan" }, //open page
@ -72,13 +76,12 @@ static table snd_lookup = {
{ 12288, table::HEX, "qos_basic_enabled" }, //bool = QoS Mod { 12288, table::HEX, "qos_basic_enabled" }, //bool = QoS Mod
{ 12289, table::HEX, "qos_basic" }, //per port { 12289, table::HEX, "qos_basic" }, //per port
{ 12544, table::HEX, "bandwidth_control_1" }, //per port { 12544, table::HEX, "bandwidth_control_1" }, //per port
{ 12545, table::HEX, "bandwidth_control_2" }, //per port { 12545, table::HEX, "bandwidth_control_2" }, //per port
{ 12800, table::HEX, "storm_control" }, //??? { 12800, table::HEX, "storm_control" }, //???
{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id?? { 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id??
{ 16384, table::HEX, "port_statistics" }, //??? { 16384, table::HEX, "port_statistics" }, //???
{ 17152, table::HEX, "loop_prevention" }, //bool byte { 17152, table::HEX, "loop_prevention" }, //bool byte
//{0000," "}, //{0000," "},
}; };

View file

@ -21,32 +21,55 @@ int Switch::parse(datasets arr) {
int Switch::parse(dataset d) { int Switch::parse(dataset d) {
auto lookup = (options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup; auto lookup = (options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup;
if (d.type == lookup["type"]) { switch (d.type) {
case lookup["type"]:
device.type = d.value; device.type = d.value;
} return 0;
if (d.type == lookup["mac"]) { case lookup["mac"]:
device.mac = d.value; device.mac = d.value;
} return 0;
if (d.type == lookup["firmware_version"]) { case lookup["ip_addr"]:
device.firmware_version = d.value; device.firmware_version = d.value;
} return 0;
if (d.type == lookup["hardware_version"]) { case lookup["ip_mask"]:
device.firmware_version = d.value;
return 0;
case lookup["gateway"]:
device.firmware_version = d.value;
return 0;
case lookup["firmware_version"]:
device.firmware_version = d.value;
return 0;
case lookup["hardware_version"]:
device.hardware_version = d.value; device.hardware_version = d.value;
} return 0;
if (d.type == lookup["hostname"]) { case lookup["ports"]:
device.ports = d.value[0];
return 0;
case lookup["hostname"]:
settings.hostname = d.value; settings.hostname = d.value;
} return 0;
if (d.type == lookup["ip_addr"]) { case lookup["ip_addr"]:
settings.ip_addr = d.value; settings.ip_addr = d.value;
} return 0;
if (d.type == lookup["ip_mask"]) { case lookup["ip_mask"]:
settings.ip_mask = d.value; settings.ip_mask = d.value;
} return 0;
if (d.type == lookup["gateway"]) { case lookup["gateway"]:
settings.gateway = d.value; settings.gateway = d.value;
} return 0;
if (d.type == lookup["dhcp"]) { case lookup["dhcp"]:
settings.dhcp = d.value[0]; settings.dhcp = d.value[0];
return 0;
case lookup["loop_prevention"]:
settings.loop_prevention = d.value[0];
return 0;
case lookup["qos_basic_enabled"]:
settings.qos_enabled = d.value[0];
return 0;
case lookup["vlan_enabled"]:
settings.vlan_enabled = d.value[0];
return 0;
} }
return 0; return 0;
} }
@ -72,8 +95,8 @@ int Switch::parse(std::string str) {
for (rapidjson::SizeType i = 0; i < a.Size(); i++) for (rapidjson::SizeType i = 0; i < a.Size(); i++)
if (a[i].IsObject()) { if (a[i].IsObject()) {
port p; port p;
if (a[i].HasMember("id")&&a[i]["id"].IsInt()) { if (a[i].HasMember("id") && a[i]["id"].IsInt()) {
p.id=a[i]["id"].GetInt(); p.id = a[i]["id"].GetInt();
std::cout << a[i]["id"].GetInt() << "\n"; std::cout << a[i]["id"].GetInt() << "\n";
} }
ports.push_back(p); ports.push_back(p);
@ -84,8 +107,8 @@ int Switch::parse(std::string str) {
for (rapidjson::SizeType i = 0; i < a.Size(); i++) for (rapidjson::SizeType i = 0; i < a.Size(); i++)
if (a[i].IsObject()) { if (a[i].IsObject()) {
vlan v; vlan v;
if (a[i].HasMember("name")&&a[i]["name"].IsString()) { if (a[i].HasMember("name") && a[i]["name"].IsString()) {
v.name=a[i]["name"].GetString(); v.name = a[i]["name"].GetString();
std::cout << a[i]["name"].GetString() << "\n"; std::cout << a[i]["name"].GetString() << "\n";
} }
vlans.push_back(v); vlans.push_back(v);

View file

@ -27,7 +27,14 @@ struct vlan {
struct port { struct port {
byte id; byte id;
byte status; byte status;
int pvid; int vlan_pvid;
//port_settings
//qos_basic
//bandwidth_control_1
//bandwidth_control_2
//storm_control
//port_statistics
//cable_test
}; };
class Switch { class Switch {
@ -43,6 +50,7 @@ public:
std::string hardware_version; std::string hardware_version;
std::string firmware_version; std::string firmware_version;
macAddr mac { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; macAddr mac { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
int ports;
} device; } device;
struct { struct {
std::string password = DEFAULT_PASS; std::string password = DEFAULT_PASS;
@ -52,6 +60,9 @@ public:
ipAddr ip_mask; ipAddr ip_mask;
ipAddr gateway; ipAddr gateway;
bool dhcp; bool dhcp;
bool loop_prevention;
bool qos_enabled;
bool vlan_enabled;
} settings; } settings;
private: private:
rapidjson::Document json; rapidjson::Document json;

38
src/table.cpp Normal file
View file

@ -0,0 +1,38 @@
/*
* lookupTable.h
*
* Created on: 11.10.2015
* Author: jdi
*/
#include <string>
#include "table.h"
table::table(std::initializer_list<set> l) {
int i = 0;
this->data.resize(l.size());
for (set s : l) {
this->data[i] = s;
this->left[s.type] = &this->data[i];
this->right[s.name] = &this->data[i];
i++;
}
}
constexpr const short& table::operator[](std::string s) {
return this->right[s]->type;
}
constexpr const std::string& table::operator[](short n) {
return this->left[n]->name;
}
bool table::exists(std::string s) {
return !(right.find(s) == right.end());
}
bool table::exists(short n) {
return !(left.find(n) == left.end());
}
const table::set* table::get(std::string s) {
return this->right[s];
}
const table::set* table::get(short n) {
return this->left[n];
}

35
src/table.h Normal file
View file

@ -0,0 +1,35 @@
/*
* lookupTable.h
*
* Created on: 11.10.2015
* Author: jdi
*/
#ifndef LOOKUPTABLE_H_
#define LOOKUPTABLE_H_
#include <map>
#include <vector>
class table {
public:
enum F {STRING,HEX,DEC,ACTION,EMPTY};
struct set {
short type;
F format;
std::string name;
};
table(std::initializer_list<set> l);
const short& operator[](std::string);
const std::string& operator[](short);
const set* get(std::string);
const set* get(short);
bool exists(std::string);
bool exists(short);
private:
std::vector<set> data;
const std::map<short, set*> left;
const std::map<std::string, set*> right;
};
#endif /* LOOKUPTABLE_H_ */