experimental stuff
This commit is contained in:
		
							parent
							
								
									96a10549d7
								
							
						
					
					
						commit
						5b61676236
					
				
					 6 changed files with 161 additions and 60 deletions
				
			
		|  | @ -57,15 +57,6 @@ ipAddr Host::getIp() { | |||
| 				return data; | ||||
| 			} | ||||
| 	} | ||||
| 	for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { | ||||
| 		if (ifa->ifa_addr == NULL) | ||||
| 			continue; | ||||
| 		if (ifa->ifa_addr->sa_family == AF_INET) | ||||
| 			if (getIface().compare(ifa->ifa_name) == 0) { | ||||
| 				memcpy(&data[0], &ifa->ifa_addr->sa_data[2], 4); | ||||
| 				return data; | ||||
| 			} | ||||
| 	} | ||||
| 	freeifaddrs(ifaddr); | ||||
| 	return data; | ||||
| } | ||||
|  |  | |||
							
								
								
									
										61
									
								
								src/Lookup.h
									
										
									
									
									
								
							
							
						
						
									
										61
									
								
								src/Lookup.h
									
										
									
									
									
								
							|  | @ -7,43 +7,46 @@ | |||
| 
 | ||||
| #include "table.h" | ||||
| 
 | ||||
| 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" }, | ||||
| 		{ 8, table::STRING, "hardware_version" }, | ||||
| 		{ 9, table::DEC, "dhcp" }, //bool byte
 | ||||
| 		{ 10, table::DEC, "ports" }, //byte, maybe number of ports
 | ||||
| 		{ 4352, table::HEX, "igmp_snooping" }, //switching
 | ||||
| 		{ 4096, table::HEX, "port_settings" }, //per port
 | ||||
| const 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" },//+
 | ||||
| 		{ 8, table::STRING, "hardware_version" },//+
 | ||||
| 		{ 9, table::DEC, "dhcp" }, //+bool byte
 | ||||
| 		{ 10, table::DEC, "ports" }, //+byte, maybe number of ports
 | ||||
| 
 | ||||
| 		{ 4352, table::HEX, "igmp_snooping" }, //???
 | ||||
| 		{ 4096, table::HEX, "port_settings" }, //+per port
 | ||||
| 		{ 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask??
 | ||||
| 
 | ||||
| 		{ 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool,second byte port id
 | ||||
| 		{ 8448, table::HEX, "port_vlan_1" }, //???
 | ||||
| 		{ 8450, table::HEX, "port_vlan_2" }, //???
 | ||||
| 		{ 8704, table::HEX, "vlan enabled" }, //bool byte
 | ||||
| 		{ 8705, table::HEX, "vlan" }, //one set per vlan
 | ||||
| 		{ 8706, table::HEX, "vlan_pvid" }, //per port
 | ||||
| 		{ 8704, table::HEX, "vlan_enabled" }, //+bool byte
 | ||||
| 		{ 8705, table::HEX, "vlan" }, //+one set per vlan
 | ||||
| 		{ 8706, table::HEX, "vlan_pvid" }, //+per port
 | ||||
| 		{ 8707, table::HEX, "vlan ?????" }, //????
 | ||||
| 		{ 12288, table::HEX, "qos_basic_1" }, //bool = QoS Mod
 | ||||
| 		{ 12289, table::HEX, "qos_basic_2" }, //per port
 | ||||
| 		{ 12544, table::HEX, "bandwidth_control_1" }, //per port
 | ||||
| 		{ 12545, table::HEX, "bandwidth_control_2" }, //per port
 | ||||
| 		{ 12800, table::HEX, "storm_control" }, //per port
 | ||||
| 		{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id??
 | ||||
| 		{ 16384, table::HEX, "port_statistics" }, //per port
 | ||||
| 		{ 16896, table::HEX, "cable_test" }, //per port
 | ||||
| 		{ 17152, table::HEX, "loop_prevention" }, //bool byte
 | ||||
| 
 | ||||
| 		{ 12288, table::HEX, "qos_basic_enabled" }, //+bool = QoS Mod
 | ||||
| 		{ 12289, table::HEX, "qos_basic" }, //+per port ???
 | ||||
| 		{ 12544, table::HEX, "bandwidth_control_1" }, //+per port ???
 | ||||
| 		{ 12545, table::HEX, "bandwidth_control_2" }, //+per port ???
 | ||||
| 		{ 12800, table::HEX, "storm_control" }, //+per port ???
 | ||||
| 		{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id???
 | ||||
| 		{ 16384, table::HEX, "port_statistics" }, //+per port ???
 | ||||
| 		{ 16896, table::HEX, "cable_test" }, //+per port ???
 | ||||
| 		{ 17152, table::HEX, "loop_prevention" }, //+bool byte
 | ||||
| 
 | ||||
| 		//{0000," "},
 | ||||
| 		}; | ||||
| 
 | ||||
| static table snd_lookup = { | ||||
| const static table snd_lookup = { | ||||
| 
 | ||||
| // TODO find out if id is unique in response
 | ||||
| 		// 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, "ports" }, //after login
 | ||||
|  | @ -52,6 +55,7 @@ static table snd_lookup = { | |||
| 		{ 514, table::STRING, "login_password" }, //string
 | ||||
| 		{ 515, table::STRING, "new_passwoord" }, //string
 | ||||
| 		{ 773, table::HEX, "reboot" }, //bool byte = save config
 | ||||
| 
 | ||||
| 		{ 1280, table::ACTION, "reset" }, //
 | ||||
| 		{ 1536, table::ACTION, "flash" }, //update firmware
 | ||||
| 
 | ||||
|  | @ -59,10 +63,10 @@ static table snd_lookup = { | |||
| 		{ 2304, table::ACTION, "save" }, //save
 | ||||
| 		{ 2305, table::ACTION, "ping" }, //sent before SET ???
 | ||||
| 
 | ||||
| 
 | ||||
| 		{ 4352, table::HEX, "igmp_snooping" }, //switching
 | ||||
| 		{ 4096, table::HEX, "port_settings" }, //switching
 | ||||
| 		{ 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 ???" }, //???
 | ||||
| 		{ 8448, table::HEX, "port_vlan" }, //open page
 | ||||
|  | @ -72,13 +76,12 @@ static table snd_lookup = { | |||
| 
 | ||||
| 		{ 12288, table::HEX, "qos_basic_enabled" }, //bool = QoS Mod
 | ||||
| 		{ 12289, table::HEX, "qos_basic" }, //per port
 | ||||
| 
 | ||||
| 		{ 12544, table::HEX, "bandwidth_control_1" }, //per port
 | ||||
| 		{ 12545, table::HEX, "bandwidth_control_2" }, //per port
 | ||||
| 		{ 12800, table::HEX, "storm_control" }, //???
 | ||||
| 
 | ||||
| 		{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id??
 | ||||
| 		{ 16384, table::HEX, "port_statistics" }, //???
 | ||||
| 		{ 17152, table::HEX, "loop_prevention" }, //bool byte
 | ||||
| 
 | ||||
| 		//{0000," "},
 | ||||
| 		}; | ||||
|  |  | |||
|  | @ -21,32 +21,55 @@ int Switch::parse(datasets arr) { | |||
| 
 | ||||
| int Switch::parse(dataset d) { | ||||
| 	auto lookup = (options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup; | ||||
| 	if (d.type == lookup["type"]) { | ||||
| 	switch (d.type) { | ||||
| 	case lookup["type"]: | ||||
| 		device.type = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["mac"]) { | ||||
| 		return 0; | ||||
| 	case lookup["mac"]: | ||||
| 		device.mac = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["firmware_version"]) { | ||||
| 		return 0; | ||||
| 	case lookup["ip_addr"]: | ||||
| 		device.firmware_version = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["hardware_version"]) { | ||||
| 		return 0; | ||||
| 	case lookup["ip_mask"]: | ||||
| 		device.firmware_version = d.value; | ||||
| 		return 0; | ||||
| 	case lookup["gateway"]: | ||||
| 		device.firmware_version = d.value; | ||||
| 		return 0; | ||||
| 	case lookup["firmware_version"]: | ||||
| 		device.firmware_version = d.value; | ||||
| 		return 0; | ||||
| 	case lookup["hardware_version"]: | ||||
| 		device.hardware_version = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["hostname"]) { | ||||
| 		return 0; | ||||
| 	case lookup["ports"]: | ||||
| 		device.ports = d.value[0]; | ||||
| 		return 0; | ||||
| 	case lookup["hostname"]: | ||||
| 		settings.hostname = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["ip_addr"]) { | ||||
| 		return 0; | ||||
| 	case lookup["ip_addr"]: | ||||
| 		settings.ip_addr = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["ip_mask"]) { | ||||
| 		return 0; | ||||
| 	case lookup["ip_mask"]: | ||||
| 		settings.ip_mask = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["gateway"]) { | ||||
| 		return 0; | ||||
| 	case lookup["gateway"]: | ||||
| 		settings.gateway = d.value; | ||||
| 	} | ||||
| 	if (d.type == lookup["dhcp"]) { | ||||
| 		return 0; | ||||
| 	case lookup["dhcp"]: | ||||
| 		settings.dhcp = d.value[0]; | ||||
| 		return 0; | ||||
| 	case lookup["loop_prevention"]: | ||||
| 		settings.loop_prevention = d.value[0]; | ||||
| 		return 0; | ||||
| 	case lookup["qos_basic_enabled"]: | ||||
| 		settings.qos_enabled = d.value[0]; | ||||
| 		return 0; | ||||
| 	case lookup["vlan_enabled"]: | ||||
| 		settings.vlan_enabled = d.value[0]; | ||||
| 		return 0; | ||||
| 	} | ||||
| 	return 0; | ||||
| } | ||||
|  | @ -72,8 +95,8 @@ int Switch::parse(std::string str) { | |||
| 			for (rapidjson::SizeType i = 0; i < a.Size(); i++) | ||||
| 				if (a[i].IsObject()) { | ||||
| 					port p; | ||||
| 					if (a[i].HasMember("id")&&a[i]["id"].IsInt()) { | ||||
| 						p.id=a[i]["id"].GetInt(); | ||||
| 					if (a[i].HasMember("id") && a[i]["id"].IsInt()) { | ||||
| 						p.id = a[i]["id"].GetInt(); | ||||
| 						std::cout << a[i]["id"].GetInt() << "\n"; | ||||
| 					} | ||||
| 					ports.push_back(p); | ||||
|  | @ -84,8 +107,8 @@ int Switch::parse(std::string str) { | |||
| 			for (rapidjson::SizeType i = 0; i < a.Size(); i++) | ||||
| 				if (a[i].IsObject()) { | ||||
| 					vlan v; | ||||
| 					if (a[i].HasMember("name")&&a[i]["name"].IsString()) { | ||||
| 						v.name=a[i]["name"].GetString(); | ||||
| 					if (a[i].HasMember("name") && a[i]["name"].IsString()) { | ||||
| 						v.name = a[i]["name"].GetString(); | ||||
| 						std::cout << a[i]["name"].GetString() << "\n"; | ||||
| 					} | ||||
| 					vlans.push_back(v); | ||||
|  |  | |||
							
								
								
									
										13
									
								
								src/Switch.h
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								src/Switch.h
									
										
									
									
									
								
							|  | @ -27,7 +27,14 @@ struct vlan { | |||
| struct port { | ||||
| 	byte id; | ||||
| 	byte status; | ||||
| 	int pvid; | ||||
| 	int vlan_pvid; | ||||
| 	//port_settings
 | ||||
| 	//qos_basic
 | ||||
| 	//bandwidth_control_1
 | ||||
| 	//bandwidth_control_2
 | ||||
| 	//storm_control
 | ||||
| 	//port_statistics
 | ||||
| 	//cable_test
 | ||||
| }; | ||||
| 
 | ||||
| class Switch { | ||||
|  | @ -43,6 +50,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 +60,9 @@ public: | |||
| 		ipAddr ip_mask; | ||||
| 		ipAddr gateway; | ||||
| 		bool dhcp; | ||||
| 		bool loop_prevention; | ||||
| 		bool qos_enabled; | ||||
| 		bool vlan_enabled; | ||||
| 	} settings; | ||||
| private: | ||||
| 	rapidjson::Document json; | ||||
|  |  | |||
							
								
								
									
										38
									
								
								src/table.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/table.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| /*
 | ||||
|  * lookupTable.h | ||||
|  * | ||||
|  *  Created on: 11.10.2015 | ||||
|  *      Author: jdi | ||||
|  */ | ||||
| 
 | ||||
| #include <string> | ||||
| #include "table.h" | ||||
| 
 | ||||
| table::table(std::initializer_list<set> 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++; | ||||
| 	} | ||||
| } | ||||
| constexpr const short& table::operator[](std::string s) { | ||||
| 	return this->right[s]->type; | ||||
| } | ||||
| constexpr const 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]; | ||||
| } | ||||
							
								
								
									
										35
									
								
								src/table.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/table.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| /*
 | ||||
|  * lookupTable.h | ||||
|  * | ||||
|  *  Created on: 11.10.2015 | ||||
|  *      Author: jdi | ||||
|  */ | ||||
| 
 | ||||
| #ifndef LOOKUPTABLE_H_ | ||||
| #define LOOKUPTABLE_H_ | ||||
| 
 | ||||
| #include <map> | ||||
| #include <vector> | ||||
| 
 | ||||
| class table { | ||||
| public: | ||||
| 	enum F {STRING,HEX,DEC,ACTION,EMPTY}; | ||||
| 	struct set { | ||||
| 		short type; | ||||
| 		F format; | ||||
| 		std::string name; | ||||
| 	}; | ||||
| 	table(std::initializer_list<set> l); | ||||
| 	const short& operator[](std::string); | ||||
| 	const std::string& operator[](short); | ||||
| 	const set* get(std::string); | ||||
| 	const set* get(short); | ||||
| 	bool exists(std::string); | ||||
| 	bool exists(short); | ||||
| private: | ||||
| 	std::vector<set> data; | ||||
| 	const std::map<short, set*> left; | ||||
| 	const std::map<std::string, set*> right; | ||||
| }; | ||||
| 
 | ||||
| #endif /* LOOKUPTABLE_H_ */ | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue