packet can contain multiple datasets of same type

This commit is contained in:
j3d1 2015-11-02 02:20:50 +01:00
parent ed87648312
commit 73df3e0528
5 changed files with 15 additions and 13 deletions

View file

@ -16,12 +16,14 @@ static table rcv_lookup = { { 1, table::STRING, "type" }, //string
{ 7, table::STRING, "firmware_version" },
{ 8, table::STRING, "hardware_version" },
{ 9, table::DEC, "dhcp" }, //bool byte
{ 19, table::DEC, "ports" }, //byte, maybe number of ports
{ 10, table::DEC, "ports???" }, //byte, maybe number of ports
{ 4352, table::HEX, "igmp_snooping" }, //switching
{ 4096, table::HEX, "port_settings" }, //switching
{ 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask??
{ 8704, table::HEX, "802.1q vlan" }, //???
{ 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool,second byte port id
{ 8704, table::HEX, "802.1q vlan enabled" }, //bool byte
{ 8705, table::HEX, "802.1q vlan" }, //one set per vlan
{ 8706, table::HEX, "802.1q vlan pvid" }, //????
{ 12288, table::HEX, "QoS Basic 1" }, //bool = QoS Mod
{ 12289, table::HEX, "QoS Basic 2" }, //QoS
{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id??
@ -35,7 +37,7 @@ static table snd_lookup = {
// TODO find out if id is unique in response
{ 2, table::HEX, "system_info" }, //page sysinfo
{ 9, table::HEX, "ip_config" }, //page sysinfo
{ 10, table::HEX, "??? - 10" }, //after login
{ 10, table::HEX, "ports???" }, //after login
{ 512, table::STRING, "login_user" }, //string
{ 513, table::STRING, "new_user" }, //string
{ 514, table::STRING, "login_password" }, //string
@ -50,7 +52,7 @@ static table snd_lookup = {
{ 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool, second byte port id
{ 8449, table::HEX, "port_vlan1" }, //???
{ 8448, table::HEX, "port_vlan2" }, //open page
{ 8704, table::HEX, "802.1q vlan" }, //??? get vlan / set status
{ 8704, table::HEX, "802.1q vlan enabled" }, //??? get vlan / set status
{ 8705, table::HEX, "802.1q vlan" }, //???
{ 8706, table::HEX, "802.1q vlan pvid" }, //????

View file

@ -33,7 +33,7 @@ void Packet::printHeader() {
bytes Packet::getBytes() {
int i = 0;
for (auto d : payload)
push(body, i, d.second);
push(body, i, d);
push(body, i, (int) PACKET_END);
i = 0;
push(head, i, version);
@ -79,7 +79,7 @@ void Packet::parse(bytes data) {
pull(body, i, d.type);
pull(body, i, d.len);
pull(body, i, d.value, d.len);
payload = d;
payload.push_back(d);
}
}

View file

@ -32,8 +32,7 @@ int printPacket(Packet p) {
if (options.flags & FLAG_HEX) {
std::cout << "Received Payload:\n\t" << p.getBody() << "\n";
} else {
for (auto a : p.getPayload()) {
dataset d = a.second;
for (dataset d : p.getPayload()) {
auto lookup =
(options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup;
if (lookup.exists(d.type)) {

View file

@ -13,8 +13,8 @@
#include "Options.h"
int Switch::parse(datasets arr) {
for (auto a : arr) {
parse(a.second);
for (dataset a : arr) {
parse(a);
}
return 0;
}

View file

@ -17,13 +17,14 @@ struct dataset {
bytes value;
};
class datasets : public std::map<short, dataset> {
class datasets : public std::vector<dataset> {
public:
datasets(){};
datasets(std::initializer_list<dataset> s)
{
for (dataset b : s) {
(*this)[b.type]=b;
//(*this)[b.type]=b;
push_back(b);
}
}
};