From ba786e388c785383804b244b42c8aa7a68af9831 Mon Sep 17 00:00:00 2001 From: /jdi/ Date: Tue, 27 Oct 2015 23:51:59 +0100 Subject: [PATCH] e --- src/Lookup.h | 57 ++++++++++++++--------------- src/Options.h | 7 ++-- src/Program.cpp | 23 +++++++++++- src/Switch.cpp | 89 ++++++++++++++++++--------------------------- src/lookupTable.cpp | 32 ---------------- src/lookupTable.h | 31 ---------------- 6 files changed, 90 insertions(+), 149 deletions(-) delete mode 100644 src/lookupTable.cpp delete mode 100644 src/lookupTable.h diff --git a/src/Lookup.h b/src/Lookup.h index add7ecc..5c0fbec 100644 --- a/src/Lookup.h +++ b/src/Lookup.h @@ -5,42 +5,41 @@ * Author: jdi */ -#include "lookupTable.h" +#include "table.h" -static lookupTable rcv_lookup = { { 1, "type" }, //string - { 2, "hostname" }, //string - { 3, "mac" }, //byte[6] - { 4, "ip_addr" }, //byte[4] - { 5, "ip_mask" }, //byte[4] - { 6, "gateway" }, //byte[4] - { 7, "firmware_version" }, //string - { 8, "hardware_version" }, //string - { 9, "dhcp" }, //bool byte - { 8704, "802.1q vlan" }, //??? +static table rcv_lookup = { { 1, table::STRING, "type" }, //string + { 2, table::STRING, "hostname" }, //string + { 3, table::HEX, "mac" }, //byte[6] + { 4, table::DEC, "ip_addr" }, //byte[4] + { 5, table::DEC, "ip_mask" }, //byte[4] + { 6, table::DEC, "gateway" }, //byte[4] + { 7, table::STRING, "firmware_version" }, //string + { 8, table::STRING, "hardware_version" }, //string + { 9, table::DEC, "dhcp" }, //bool byte + { 8704, table::HEX, "802.1q vlan" }, //??? //{0000," "}, }; -static lookupTable snd_lookup = { +static table snd_lookup = { // TODO find out if id is unique in response - { 10, "???" }, //after login - { 2, "???" }, //after login - { 512, "login_user" }, //string - { 513, "new_user" }, //string - { 514, "login_password" }, //string - { 515, "new_passwoord" }, //string - { 2200, "vlan" }, - { 2305, "???" }, //sent before login and before change hostname - { 4608, "port_trunk" }, //byte[5] last byte bitmask?? - { 8192, "mtu_vlan" }, //byte[2] first byte bool, second byte port id - { 8449, "port_vlan" }, //??? + { 10, table::HEX, "???" }, //after login + { 2, table::HEX, "???" }, //after login + { 512, table::STRING, "login_user" }, //string + { 513, table::STRING, "new_user" }, //string + { 514, table::STRING, "login_password" }, //string + { 515, table::STRING, "new_passwoord" }, //string + { 2200, table::HEX, "vlan" }, { 2305, table::HEX, "???" }, //sent before login and before change hostname + { 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask?? + { 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool, second byte port id + { 8449, table::HEX, "port_vlan" }, //??? - { 8704, "802.1q vlan" }, //??? get vlan / set status - { 8705, "802.1q vlan" }, //??? - { 8706, "802.1q vlan pvid" }, //???? + { 8704, table::HEX, "802.1q vlan" }, //??? get vlan / set status + { 8705, table::HEX, "802.1q vlan" }, //??? + { 8706, table::HEX, "802.1q vlan pvid" }, //???? - { 12288, "QoS Basic" }, //bool = QoS Mod - { 16640, "port_mirror" }, //byte[10] second byte port id?? - { 17152, "loop_prevention" }, //bool byte + { 12288, table::HEX, "QoS Basic" }, //bool = QoS Mod + { 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id?? + { 17152, table::HEX, "loop_prevention" }, //bool byte //{0000," "}, }; diff --git a/src/Options.h b/src/Options.h index 6f4ddc8..8921eb4 100644 --- a/src/Options.h +++ b/src/Options.h @@ -11,7 +11,7 @@ #include "Types.h" #define VERSION "smrtlink (v1 Linux)\n" -#define USAGE "usage: %s [-bdhrvswx] [-i interface] [-u [password:]username]\n\ +#define USAGE "usage: %s [-bdhjrvswx] [-i interface] [-u [password:]username]\n\ [-p password] \n\n" #define HELP "\ Option Summary:\n\ @@ -21,6 +21,7 @@ -r switch ports to emulate switch while sniffing\n\ -b --header Show header\n\ -x --hex Display Packets as Hex String\n\ + -j --json Display Packets as JSON\n\ -i --interface only use one Interface\n\ -u --user <[password:]username>\n\ -p --password \n\ @@ -38,8 +39,8 @@ encode use encoding algorithm on hex data separated by colon\n\ get Not yet implemented\n\ set Not yet implemented\n\ - save Not yet implemented: save config to file\n\ - restore Not yet implemented: restore onfig from file\n\ + get|save Not yet implemented: save config to file\n\ + set|restore Not yet implemented: restore onfig from file\n\ flash Not yet implemented: replace firmware\n\ reboot Not yet implemented\n\ reset Not yet implemented\n\n\ diff --git a/src/Program.cpp b/src/Program.cpp index 40d2955..5776243 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -86,7 +86,21 @@ int Program::sniff() { auto lookup=(options.flags & FLAG_REVERSE)?snd_lookup:rcv_lookup; if(lookup.exists(d.type)) { if(d.len>0) { - std::cout<format) { + case table::STRING: + std::cout<name<<": "<<&d.value[0]<name<<": "<name<<": "<name<<": "<value.IsString()); - assert(strcmp("world", hello->value.GetString()) == 0); - (void) hello; - - assert(json["t"].IsBool()); // JSON true/false are bool. Can also uses more specific function IsTrue(). - printf("t = %s\n", json["t"].GetBool() ? "true" : "false"); - - assert(json["f"].IsBool()); - printf("f = %s\n", json["f"].GetBool() ? "true" : "false"); - - printf("n = %s\n", json["n"].IsNull() ? "null" : "?"); - - assert(json["i"].IsNumber()); // Number is a JSON type, but C++ needs more specific type. - assert(json["i"].IsInt()); // In this case, IsUint()/IsInt64()/IsUInt64() also return true. - printf("i = %d\n", json["i"].GetInt()); // Alternative (int)document["i"] - - assert(json["pi"].IsNumber()); - assert(json["pi"].IsDouble()); - printf("pi = %g\n", json["pi"].GetDouble()); - - { - const rapidjson::Value& a = json["a"]; // Using a reference for consecutive access is handy and faster. - assert(a.IsArray()); - for (rapidjson::SizeType i = 0; i < a.Size(); i++) // rapidjson uses SizeType instead of size_t. - printf("a[%d] = %d\n", i, a[i].GetInt()); - - int y = a[0].GetInt(); - (void) y; - - // Iterating array with iterators - printf("a = "); - for (rapidjson::Value::ConstValueIterator itr = a.Begin(); - itr != a.End(); ++itr) - printf("%d ", itr->GetInt()); - printf("\n"); - } - - // Iterating object members - static const char* kTypeNames[] = { "Null", "False", "True", "Object", - "Array", "String", "Number" }; - for (rapidjson::Value::ConstMemberIterator itr = json.MemberBegin(); - itr != json.MemberEnd(); ++itr) - printf("Type of member %s is %s\n", itr->name.GetString(), - kTypeNames[itr->value.GetType()]); -*/ return 0; } diff --git a/src/lookupTable.cpp b/src/lookupTable.cpp deleted file mode 100644 index c4def39..0000000 --- a/src/lookupTable.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * lookupTable.h - * - * Created on: 11.10.2015 - * Author: jdi - */ - -#include -#include "lookupTable.h" - -lookupTable::lookupTable(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++; - } -} -const short& lookupTable::operator[](std::string s) { - return this->right[s]->type; -} -const std::string& lookupTable::operator[](short n) { - return this->left[n]->name; -} -bool lookupTable::exists(std::string s) { - return !(right.find(s) == right.end()); -} -bool lookupTable::exists(short n) { - return !(left.find(n) == left.end()); -} diff --git a/src/lookupTable.h b/src/lookupTable.h deleted file mode 100644 index f293ca7..0000000 --- a/src/lookupTable.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * lookupTable.h - * - * Created on: 11.10.2015 - * Author: jdi - */ - -#ifndef LOOKUPTABLE_H_ -#define LOOKUPTABLE_H_ - -#include -#include - -class lookupTable { -public: - struct set { - short type; - std::string name; - }; - lookupTable(std::initializer_list l); - const short& operator[](std::string s); - const std::string& operator[](short n); - bool exists(std::string s); - bool exists(short n); -private: - std::vector data; - std::map left; - std::map right; -}; - -#endif /* LOOKUPTABLE_H_ */