From aa8af55608f7c22976a1b15b7f8bfeb193515824 Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Sun, 17 Jan 2016 00:46:51 +0100 Subject: [PATCH] table.h added --- Makefile | 6 ++++-- src/Host.cpp | 2 ++ src/Switch.h | 4 ++++ src/table.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/table.h | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/table.cpp create mode 100644 src/table.h diff --git a/Makefile b/Makefile index 5a4c853..571843d 100644 --- a/Makefile +++ b/Makefile @@ -15,12 +15,14 @@ $(BUILDDIR): $(TARGET): $(OBJECTS) - $(CC) $^ -o $@ -lboost_filesystem -lboost_system + $(CC) $^ -o $(BUILDDIR)/$@ -lboost_filesystem -lboost_system $(OBJECTS): $(BUILDDIR)/%.o : $(SOURCEDIR)/%.cpp $(CC) $(CFLAGS) $< -o $@ +install: bin/$(TARGET) + install -m 0755 bin/$(TARGET) $(prefix)/bin clean: - rm -f $(BUILDDIR)/*o $(TARGET) + rm -f $(BUILDDIR)/* diff --git a/src/Host.cpp b/src/Host.cpp index a625cf9..83a06b4 100644 --- a/src/Host.cpp +++ b/src/Host.cpp @@ -57,6 +57,7 @@ ipAddr Host::getIp() { return data; } } + /* for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { if (ifa->ifa_addr == NULL) continue; @@ -66,6 +67,7 @@ ipAddr Host::getIp() { return data; } } + */ freeifaddrs(ifaddr); return data; } diff --git a/src/Switch.h b/src/Switch.h index 44b715c..1baa9a4 100644 --- a/src/Switch.h +++ b/src/Switch.h @@ -43,6 +43,7 @@ public: std::string hardware_version; std::string firmware_version; macAddr mac { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; + int ports; } device; struct { std::string password = DEFAULT_PASS; @@ -52,6 +53,9 @@ public: ipAddr ip_mask; ipAddr gateway; bool dhcp; + bool loop_prevention; + bool qos_enabled; + bool vlan_enabled; } settings; private: rapidjson::Document json; diff --git a/src/table.cpp b/src/table.cpp new file mode 100644 index 0000000..75ce25a --- /dev/null +++ b/src/table.cpp @@ -0,0 +1,38 @@ +/* + * lookupTable.h + * + * Created on: 11.10.2015 + * Author: jdi + */ + +#include +#include "table.h" + +table::table(std::initializer_list 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++; + } +} +short table::operator[](std::string s){ + return this->right[s]->type; +} +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]; +} diff --git a/src/table.h b/src/table.h new file mode 100644 index 0000000..f9171a6 --- /dev/null +++ b/src/table.h @@ -0,0 +1,35 @@ +/* + * lookupTable.h + * + * Created on: 11.10.2015 + * Author: jdi + */ + +#ifndef LOOKUPTABLE_H_ +#define LOOKUPTABLE_H_ + +#include +#include + +class table { +public: + enum F {STRING,HEX,DEC,ACTION,EMPTY}; + struct set { + short type; + F format; + std::string name; + }; + table(std::initializer_list l); + short operator[](std::string); + std::string operator[](short); + bool exists(std::string); + bool exists(short); + const set* get(std::string); + const set* get(short); +private: + std::vector data; + std::map left; + std::map right; +}; + +#endif /* LOOKUPTABLE_H_ */