Commit 7f3e5fc0 authored by /jdi/'s avatar /jdi/
Browse files

type lookup tabel

parent f11f281a
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>
\ No newline at end of file
......@@ -20,7 +20,7 @@ Packet::Packet(OpCode c) {
}
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 << "\tVersion:\t" << version << "\n";
std::cout << "\tError:\t\t" << errorCode << "\n";
......@@ -145,8 +145,10 @@ std::string Packet::opCodeToString() {
return "GET";
case SET:
return "SET";
case READ:
return "READ";
case RECEIVE:
return "RECEIVE";
case READ5:
return "READ5";
default:
return "NONE";
}
......
......@@ -18,7 +18,7 @@
class Packet {
public:
enum OpCode {
DISCOVERY, GET, SET, READ
DISCOVERY, GET, SET, READ4,RECEIVE, READ5
};
Packet(OpCode);
void encode(bytes&);
......
......@@ -66,29 +66,40 @@ int Program::sniff() {
Socket s(io_service);
s.setHostIp(h.getIp());
s.init(DST_PORT, SRC_PORT);
s.callback = [](Packet p) {
if (options.flags & FLAG_HEADER) {
if (options.flags & FLAG_HEX) {
std::cout <<"Received Header:\n\t"<< p.getHead() <<"\n";
} else {
p.printHeader();
printf("\n");
}
}
if (options.flags & FLAG_HEX) {
std::cout <<"Received Payload:\n\t"<<p.getBody()<<"\n";
} else {
for(auto a : p.getPayload()) {
dataset d = a.second;
std::cout<<"#"<<d.type<<"\tLength: "<<d.len<<"\n";
std::cout<<std::hex<< "\tHex: " <<d.value<<"\n";
//std::cout<<std::dec<<"\tDec: " << d.value<<"\n";
d.value.push_back(0U);
std::cout<<"\tString: " <<&d.value[0]<<"\n";
}
}
return 0;
};
s.callback =
[](Packet p) {
std::cout <<"Packet:\n\t"<<p.opCodeToString()<<"\n";
if (options.flags & FLAG_HEADER) {
if (options.flags & FLAG_HEX) {
std::cout <<"Received Header:\n\t"<< p.getHead() <<"\n";
} else {
p.printHeader();
printf("\n");
}
}
if (options.flags & FLAG_HEX) {
std::cout <<"Received Payload:\n\t"<<p.getBody()<<"\n";
} else {
for(auto a : p.getPayload()) {
dataset d = a.second;
auto lookup=(options.flags & FLAG_REVERSE)?snd_lookup:rcv_lookup;
if(lookup.find(d.type) ==lookup.end()) {
if(d.len>0) {
std::cout<<std::dec<<"#"<<d.type<<"\tLength: "<<d.len<<"\n";
std::cout<<std::hex<< "\tHex: " <<d.value<<"\n";
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();
io_service.run();
} catch (std::exception& e) {
......@@ -110,15 +121,56 @@ int Program::setProperty() {
return 0;
}
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() {
//File = fopen(otions.file)
//File = fopen(otions.file)
return 0;
}
int Program::restore() {
//File = fopen(otions.file)
//File = fopen(otions.file)
return 0;
}
int Program::flash() {
......
......@@ -74,7 +74,7 @@ void Socket::listen() {
listen();
} else {
data.resize(bytes_recvd);
Packet p = Packet(Packet::READ);
Packet p = Packet(Packet::RECEIVE);
p.encode(data);
p.parse(data);
datasets l = p.getPayload();
......
......@@ -9,6 +9,7 @@
#define SWITCH_H_
#include <string>
#include <map>
#include "Types.h"
#include "Types/bytes.h"
#include "Types/datasets.h"
......@@ -16,19 +17,37 @@
#define DEFAULT_USER "admin"
#define DEFAULT_PASS "admin"
/*
*
static bitable lookup = {
{1, "type"},
{2, "hostname"},
{3, "mac"},
{4, "ip_addr"},
{5, "ip_mask"},
{6, "gateway"},
{7, "firmware_version"},
{8, "hardware_version"},
{9, "dhcp"}};
*/
static std::map<int,std::string> 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
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 {
int vlan_id;
......
......@@ -117,7 +117,6 @@ int main(int argc, char *argv[]) {
std::string cmd = std::string(argv[optind++]);
switch (caseArg(cmd.c_str())) {
case caseArg("get"):
case caseArg("set"):
case caseArg("reboot"):
case caseArg("reset"):
......@@ -128,6 +127,11 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
break;
case caseArg("get"):
if (p.getProperty())
exit(EXIT_SUCCESS);
break;
case caseArg("list"):
if (p.list())
exit(EXIT_SUCCESS);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment