type lookup tabel

This commit is contained in:
/jdi/ 2015-10-08 17:26:39 +02:00
parent f11f281a2c
commit 7f3e5fc0d9
7 changed files with 122 additions and 75 deletions

View file

@ -1,30 +0,0 @@
change Password:
#512 Length: 6 Value: admin
#513 Length: 6 Value: admin
#514 Length: 10 Value: <oldPassword>
#515 Length: 10 Value: <newPassword>
login:
#2305 Length: 0 Value: (null)
#512 Length: 6 Value: admin
#514 Length: 10 Value: <Password>
#10 Length: 0 Value: (null)
#2 Length: 0 Value: (null)
change Hostname:
#2305 Length: 0 Value: (null)
#2 Length: 11 Value: <Hostname>
#4 Length: 4 Dec: 192.168.0.5
#5 Length: 4 Dec: 255.255.255.0
#6 Length: 4 Dec: 0.0.0.0
#9 Length: 1 Hex: 00
#512 Length: 6 Value: admin
#514 Length: 17 Value: <Password>

View file

@ -20,7 +20,7 @@ Packet::Packet(OpCode c) {
} }
void Packet::printHeader() { void Packet::printHeader() {
std::cout << "Header:\n\tOpCode:\t\t" << opCodeToString() << "\n"; std::cout << "Header:\n";
std::cout << "\tID:\t\t" << sequenceId << "\n"; std::cout << "\tID:\t\t" << sequenceId << "\n";
std::cout << "\tVersion:\t" << version << "\n"; std::cout << "\tVersion:\t" << version << "\n";
std::cout << "\tError:\t\t" << errorCode << "\n"; std::cout << "\tError:\t\t" << errorCode << "\n";
@ -145,8 +145,10 @@ std::string Packet::opCodeToString() {
return "GET"; return "GET";
case SET: case SET:
return "SET"; return "SET";
case READ: case RECEIVE:
return "READ"; return "RECEIVE";
case READ5:
return "READ5";
default: default:
return "NONE"; return "NONE";
} }

View file

@ -18,7 +18,7 @@
class Packet { class Packet {
public: public:
enum OpCode { enum OpCode {
DISCOVERY, GET, SET, READ DISCOVERY, GET, SET, READ4,RECEIVE, READ5
}; };
Packet(OpCode); Packet(OpCode);
void encode(bytes&); void encode(bytes&);

View file

@ -66,29 +66,40 @@ int Program::sniff() {
Socket s(io_service); Socket s(io_service);
s.setHostIp(h.getIp()); s.setHostIp(h.getIp());
s.init(DST_PORT, SRC_PORT); s.init(DST_PORT, SRC_PORT);
s.callback = [](Packet p) { s.callback =
if (options.flags & FLAG_HEADER) { [](Packet p) {
if (options.flags & FLAG_HEX) { std::cout <<"Packet:\n\t"<<p.opCodeToString()<<"\n";
std::cout <<"Received Header:\n\t"<< p.getHead() <<"\n"; if (options.flags & FLAG_HEADER) {
} else { if (options.flags & FLAG_HEX) {
p.printHeader(); std::cout <<"Received Header:\n\t"<< p.getHead() <<"\n";
printf("\n"); } else {
} p.printHeader();
} printf("\n");
if (options.flags & FLAG_HEX) { }
std::cout <<"Received Payload:\n\t"<<p.getBody()<<"\n"; }
} else { if (options.flags & FLAG_HEX) {
for(auto a : p.getPayload()) { std::cout <<"Received Payload:\n\t"<<p.getBody()<<"\n";
dataset d = a.second; } else {
std::cout<<"#"<<d.type<<"\tLength: "<<d.len<<"\n"; for(auto a : p.getPayload()) {
std::cout<<std::hex<< "\tHex: " <<d.value<<"\n"; dataset d = a.second;
//std::cout<<std::dec<<"\tDec: " << d.value<<"\n"; auto lookup=(options.flags & FLAG_REVERSE)?snd_lookup:rcv_lookup;
d.value.push_back(0U); if(lookup.find(d.type) ==lookup.end()) {
std::cout<<"\tString: " <<&d.value[0]<<"\n"; if(d.len>0) {
} std::cout<<std::dec<<"#"<<d.type<<"\tLength: "<<d.len<<"\n";
} std::cout<<std::hex<< "\tHex: " <<d.value<<"\n";
return 0; d.value.push_back(0U);
}; std::cout<<"\tString: " <<&d.value[0]<<"\n";
} else {
std::cout<<std::dec<<"\t++"<<std::hex<<d.type<<std::dec<<"++\n";
}
} else {
std::cout<<"###"<<lookup[d.type]<<"\n";
}
}
}
return 0;
};
s.listen(); s.listen();
io_service.run(); io_service.run();
} catch (std::exception& e) { } catch (std::exception& e) {
@ -110,15 +121,56 @@ int Program::setProperty() {
return 0; return 0;
} }
int Program::getProperty() { int Program::getProperty() {
Host h = Host();
printf("Get:\n");
Packet p = Packet(Packet::DISCOVERY);
macAddr d = {0x14,0xcc,0x20,0x49,0x5e,0x07};
p.setSwitchMac(d);
p.setHostMac(h.getMac());
datasets t = { { 2200, 0, { } } };
p.setPayload(t);
bytes a = p.getBytes();
p.encode(a);
return 0; try {
asio::io_service io_service;
Socket s(io_service);
s.setHostIp(h.getIp());
s.init(DST_PORT, SRC_PORT);
s.callback =
[](Packet a) {
if (options.flags & FLAG_HEADER) {
if (options.flags & FLAG_HEX) {
std::cout <<"Received Header:\n"<< a.getHead() <<"\n";
} else {
a.printHeader();
std::cout<<"\n";
}
}
if (options.flags & FLAG_HEX) {
std::cout <<"Received Payload:\n"<<a.getBody()<<"\n";
} else {
datasets d =a.getPayload();
Switch s = Switch();
s.parse(d);
std::cout <<"Devices:\n\t"<<s.settings.hostname<<" ("<< s.device.type<<")\tMAC: "<<s.device.mac<<"\tIP: "<<s.settings.ip_addr<<"\n";
}
return 1;
};
s.send(a);
io_service.run();
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}
return 1;
} }
int Program::save() { int Program::save() {
//File = fopen(otions.file) //File = fopen(otions.file)
return 0; return 0;
} }
int Program::restore() { int Program::restore() {
//File = fopen(otions.file) //File = fopen(otions.file)
return 0; return 0;
} }
int Program::flash() { int Program::flash() {

View file

@ -74,7 +74,7 @@ void Socket::listen() {
listen(); listen();
} else { } else {
data.resize(bytes_recvd); data.resize(bytes_recvd);
Packet p = Packet(Packet::READ); Packet p = Packet(Packet::RECEIVE);
p.encode(data); p.encode(data);
p.parse(data); p.parse(data);
datasets l = p.getPayload(); datasets l = p.getPayload();

View file

@ -9,6 +9,7 @@
#define SWITCH_H_ #define SWITCH_H_
#include <string> #include <string>
#include <map>
#include "Types.h" #include "Types.h"
#include "Types/bytes.h" #include "Types/bytes.h"
#include "Types/datasets.h" #include "Types/datasets.h"
@ -16,19 +17,37 @@
#define DEFAULT_USER "admin" #define DEFAULT_USER "admin"
#define DEFAULT_PASS "admin" #define DEFAULT_PASS "admin"
/* static std::map<int,std::string> rcv_lookup= {
* { 1, "type"},//string
static bitable lookup = { { 2, "hostname"},//string
{1, "type"}, { 3, "mac"},//byte[6]
{2, "hostname"}, { 4, "ip_addr"},//byte[4]
{3, "mac"}, { 5, "ip_mask"},//byte[4]
{4, "ip_addr"}, { 6, "gateway"},//byte[4]
{5, "ip_mask"}, { 7, "firmware_version"},//string
{6, "gateway"}, { 8, "hardware_version"},//string
{7, "firmware_version"}, { 9, "dhcp"}};//bool byte
{8, "hardware_version"},
{9, "dhcp"}}; static std::map<int,std::string> snd_lookup= {
*/ {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"},//???
{8705,"802.1q vlan"},//???
{8706,"802.1q vlan pvid"},//????
{12288,"QoS Basic"},//bool = QoS Mod
{16640,"port_mirror"},//byte[10] second byte port id??
{17152,"loop_prevention"},//bool byte
//{0000," "},
};
struct vlan { struct vlan {
int vlan_id; int vlan_id;

View file

@ -117,7 +117,6 @@ int main(int argc, char *argv[]) {
std::string cmd = std::string(argv[optind++]); std::string cmd = std::string(argv[optind++]);
switch (caseArg(cmd.c_str())) { switch (caseArg(cmd.c_str())) {
case caseArg("get"):
case caseArg("set"): case caseArg("set"):
case caseArg("reboot"): case caseArg("reboot"):
case caseArg("reset"): case caseArg("reset"):
@ -128,6 +127,11 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
break; break;
case caseArg("get"):
if (p.getProperty())
exit(EXIT_SUCCESS);
break;
case caseArg("list"): case caseArg("list"):
if (p.list()) if (p.list())
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);