some minor fixes
This commit is contained in:
parent
5b61676236
commit
06351d87d1
8 changed files with 47 additions and 53 deletions
6
Makefile
6
Makefile
|
@ -15,12 +15,14 @@ $(BUILDDIR):
|
||||||
|
|
||||||
|
|
||||||
$(TARGET): $(OBJECTS)
|
$(TARGET): $(OBJECTS)
|
||||||
$(CC) $^ -o $@ -lboost_filesystem -lboost_system
|
$(CC) $^ -o $(BUILDDIR)/$@ -lboost_filesystem -lboost_system
|
||||||
|
|
||||||
|
|
||||||
$(OBJECTS): $(BUILDDIR)/%.o : $(SOURCEDIR)/%.cpp
|
$(OBJECTS): $(BUILDDIR)/%.o : $(SOURCEDIR)/%.cpp
|
||||||
$(CC) $(CFLAGS) $< -o $@
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
install: bin/$(TARGET)
|
||||||
|
install -m 0755 bin/$(TARGET) $(prefix)/bin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(BUILDDIR)/*o $(TARGET)
|
rm -f $(BUILDDIR)/*
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
|
||||||
const static table rcv_lookup = { //
|
static table rcv_lookup = { //
|
||||||
{ 1, table::STRING, "type" }, //+string
|
{ 1, table::STRING, "type" }, //+string
|
||||||
{ 2, table::STRING, "hostname" }, //+string
|
{ 2, table::STRING, "hostname" }, //+string
|
||||||
{ 3, table::HEX, "mac" }, //+byte[6]
|
{ 3, table::HEX, "mac" }, //+byte[6]
|
||||||
|
@ -44,7 +44,7 @@ const static table rcv_lookup = { //
|
||||||
//{0000," "},
|
//{0000," "},
|
||||||
};
|
};
|
||||||
|
|
||||||
const static table snd_lookup = {
|
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
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "Switch.h"
|
#include "Switch.h"
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
#include "Lookup.h"
|
#include "Lookup.h"
|
||||||
|
#include "table.h"
|
||||||
|
|
||||||
int printHeader(Packet p) {
|
int printHeader(Packet p) {
|
||||||
if (options.flags & FLAG_HEADER) {
|
if (options.flags & FLAG_HEADER) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "Lookup.h"
|
#include "Lookup.h"
|
||||||
#include "jsonNode.h"
|
#include "jsonNode.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
#include "table.h"
|
||||||
|
|
||||||
int Switch::parse(datasets arr) {
|
int Switch::parse(datasets arr) {
|
||||||
for (dataset a : arr) {
|
for (dataset a : arr) {
|
||||||
|
@ -21,55 +22,44 @@ 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;
|
||||||
switch (d.type) {
|
if (d.type == lookup["type"]) {
|
||||||
case lookup["type"]:
|
|
||||||
device.type = d.value;
|
device.type = d.value;
|
||||||
return 0;
|
}
|
||||||
case lookup["mac"]:
|
if (d.type == lookup["mac"]) {
|
||||||
device.mac = d.value;
|
device.mac = d.value;
|
||||||
return 0;
|
}
|
||||||
case lookup["ip_addr"]:
|
if (d.type == lookup["firmware_version"]) {
|
||||||
device.firmware_version = d.value;
|
device.firmware_version = d.value;
|
||||||
return 0;
|
}
|
||||||
case lookup["ip_mask"]:
|
if (d.type == lookup["hardware_version"]) {
|
||||||
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;
|
}
|
||||||
case lookup["ports"]:
|
if (d.type == lookup["ports"]) {
|
||||||
device.ports = d.value[0];
|
device.ports = d.value[0];
|
||||||
return 0;
|
}
|
||||||
case lookup["hostname"]:
|
if (d.type == lookup["hostname"]) {
|
||||||
settings.hostname = d.value;
|
settings.hostname = d.value;
|
||||||
return 0;
|
}
|
||||||
case lookup["ip_addr"]:
|
if (d.type == lookup["ip_addr"]) {
|
||||||
settings.ip_addr = d.value;
|
settings.ip_addr = d.value;
|
||||||
return 0;
|
}
|
||||||
case lookup["ip_mask"]:
|
if (d.type == lookup["ip_mask"]) {
|
||||||
settings.ip_mask = d.value;
|
settings.ip_mask = d.value;
|
||||||
return 0;
|
}
|
||||||
case lookup["gateway"]:
|
if (d.type == lookup["gateway"]) {
|
||||||
settings.gateway = d.value;
|
settings.gateway = d.value;
|
||||||
return 0;
|
}
|
||||||
case lookup["dhcp"]:
|
if (d.type == lookup["dhcp"]) {
|
||||||
settings.dhcp = d.value[0];
|
settings.dhcp = d.value[0];
|
||||||
return 0;
|
}
|
||||||
case lookup["loop_prevention"]:
|
if (d.type == lookup["loop_prevention"]) {
|
||||||
settings.loop_prevention = d.value[0];
|
settings.loop_prevention = d.value[0];
|
||||||
return 0;
|
}
|
||||||
case lookup["qos_basic_enabled"]:
|
if (d.type == lookup["qos_basic_enabled"]) {
|
||||||
settings.qos_enabled = d.value[0];
|
settings.qos_enabled = d.value[0];
|
||||||
return 0;
|
}
|
||||||
case lookup["vlan_enabled"]:
|
if (d.type == lookup["vlan_enabled"]) {
|
||||||
settings.vlan_enabled = d.value[0];
|
settings.vlan_enabled = d.value[0];
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct vlan {
|
||||||
struct port {
|
struct port {
|
||||||
byte id;
|
byte id;
|
||||||
byte status;
|
byte status;
|
||||||
int vlan_pvid;
|
int pvid;
|
||||||
//port_settings
|
//port_settings
|
||||||
//qos_basic
|
//qos_basic
|
||||||
//bandwidth_control_1
|
//bandwidth_control_1
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "bytes.h"
|
#include "bytes.h"
|
||||||
#include "datasets.h"
|
#include "datasets.h"
|
||||||
|
#include "table.h"
|
||||||
|
|
||||||
class macAddr: public std::array<byte, 6> {
|
class macAddr: public std::array<byte, 6> {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -18,21 +18,21 @@ table::table(std::initializer_list<set> l) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
constexpr const short& table::operator[](std::string s) {
|
short table::operator[](std::string s){
|
||||||
return this->right[s]->type;
|
return this->right[s]->type;
|
||||||
}
|
}
|
||||||
constexpr const std::string& table::operator[](short n) {
|
std::string table::operator[](short n){
|
||||||
return this->left[n]->name;
|
return this->left[n]->name;
|
||||||
}
|
}
|
||||||
bool table::exists(std::string s) {
|
bool table::exists(std::string s){
|
||||||
return !(right.find(s) == right.end());
|
return !(right.find(s) == right.end());
|
||||||
}
|
}
|
||||||
bool table::exists(short n) {
|
bool table::exists(short n){
|
||||||
return !(left.find(n) == left.end());
|
return !(left.find(n) == left.end());
|
||||||
}
|
}
|
||||||
const table::set* table::get(std::string s) {
|
const table::set* table::get(std::string s){
|
||||||
return this->right[s];
|
return this->right[s];
|
||||||
}
|
}
|
||||||
const table::set* table::get(short n) {
|
const table::set* table::get(short n){
|
||||||
return this->left[n];
|
return this->left[n];
|
||||||
}
|
}
|
||||||
|
|
12
src/table.h
12
src/table.h
|
@ -20,16 +20,16 @@ public:
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
table(std::initializer_list<set> l);
|
table(std::initializer_list<set> l);
|
||||||
const short& operator[](std::string);
|
short operator[](std::string);
|
||||||
const std::string& operator[](short);
|
std::string operator[](short);
|
||||||
const set* get(std::string);
|
|
||||||
const set* get(short);
|
|
||||||
bool exists(std::string);
|
bool exists(std::string);
|
||||||
bool exists(short);
|
bool exists(short);
|
||||||
|
const set* get(std::string);
|
||||||
|
const set* get(short);
|
||||||
private:
|
private:
|
||||||
std::vector<set> data;
|
std::vector<set> data;
|
||||||
const std::map<short, set*> left;
|
std::map<short, set*> left;
|
||||||
const std::map<std::string, set*> right;
|
std::map<std::string, set*> right;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LOOKUPTABLE_H_ */
|
#endif /* LOOKUPTABLE_H_ */
|
||||||
|
|
Loading…
Reference in a new issue