minor improvements

This commit is contained in:
/jdi/ 2015-10-06 21:14:01 +02:00
parent 30ebdde28e
commit e077b4ca8a
14 changed files with 172 additions and 220 deletions

View file

@ -1,12 +1,19 @@
CC = g++ CC = g++
CFLAGS = -g -Wall -std=c++11 CFLAGS = -Wall -std=c++11
TARGET = smrtlink TARGET = smrtlink
all: $(TARGET) all: $(TARGET)
$(TARGET): src/*.cpp $(TARGET): Types.o Program.o
$(CC) $(CFLAGS) -o $(TARGET) src/*.cpp src/*.h $(CC) $(CFLAGS) -o $(TARGET) *.o
clean: Types.o: src/Types/*.cpp src/Types*.h
rm src/$(TARGET).g $(CC) $(CFLAGS) -c src/Types/*.cpp
Program.o: src/*.cpp src/*.h
$(CC) $(CFLAGS) -c src/*.cpp
clean:
rm *.o

View file

@ -5,8 +5,10 @@
* Author: jdi * Author: jdi
*/ */
//TODO clean up
#include <cstdio> #include <cstdio>
#include <cerrno> //#include <cerrno>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
@ -16,25 +18,21 @@
#include <netdb.h> #include <netdb.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <unistd.h> #include <unistd.h>
#include <linux/if_link.h> //#include <linux/if_link.h>
#include "Utils.h" #include "Options.h"
#include "Host.h" #include "Host.h"
#include "Types.h"
Host::Host() { #include "Types/bytes.h"
// TODO Auto-generated constructor stub
}
macAddr Host::getMac() { macAddr Host::getMac() {
macAddr ret { { 0x08, 0x3e, 0x8e, 0x16, 0x17, 0x2c } }; macAddr ret { 0x08, 0x3e, 0x8e, 0x16, 0x17, 0x2c }; //TODO find actual MAC Address
//TODO find actual MAC Address
return ret; return ret;
} }
inetAddr Host::getIp(std::string iface) { ipAddr Host::getIp() {
struct ifaddrs *ifaddr, *ifa; struct ifaddrs *ifaddr, *ifa;
int n; int n;
inetAddr data { { 0, 0, 0, 0 } }; ipAddr data { 0, 0, 0, 0 };
if (getifaddrs(&ifaddr) == -1) { if (getifaddrs(&ifaddr) == -1) {
perror("getifaddrs"); perror("getifaddrs");
@ -46,7 +44,7 @@ inetAddr Host::getIp(std::string iface) {
continue; continue;
if (ifa->ifa_addr->sa_family == AF_INET) { if (ifa->ifa_addr->sa_family == AF_INET) {
if (iface.compare(ifa->ifa_name) == 0) { if (options.interface.compare(ifa->ifa_name) == 0) {
memcpy(&data[0], &ifa->ifa_addr->sa_data[2], 4); memcpy(&data[0], &ifa->ifa_addr->sa_data[2], 4);
return data; return data;
} }
@ -54,7 +52,6 @@ inetAddr Host::getIp(std::string iface) {
} }
freeifaddrs(ifaddr); freeifaddrs(ifaddr);
return data; return data;
} }

View file

@ -12,9 +12,9 @@
class Host { class Host {
public: public:
Host(); Host(){};
macAddr getMac(); macAddr getMac();
inetAddr getIp(std::string); ipAddr getIp();
}; };
#endif /* HOST_H_ */ #endif /* HOST_H_ */

View file

@ -11,7 +11,8 @@
#include <ctime> #include <ctime>
#include "Packet.h" #include "Packet.h"
#include "Types.h" #include "Types.h"
#include "Utils.h" #include "Types/bytes.h"
#include "Types/datasets.h"
Packet::Packet(OpCode c) { Packet::Packet(OpCode c) {
srand(time(NULL)); srand(time(NULL));
@ -23,9 +24,8 @@ void Packet::printHeader() {
printf( printf(
"Header:\n\tOpCode:\t\t%s\n\tID:\t\t%d\n\tVersion:\t%hhd\n\tError:\t\t%.8X\n\tSwitch MAC:\t", "Header:\n\tOpCode:\t\t%s\n\tID:\t\t%d\n\tVersion:\t%hhd\n\tError:\t\t%.8X\n\tSwitch MAC:\t",
opCodeToString().c_str(), sequenceId, version, errorCode); opCodeToString().c_str(), sequenceId, version, errorCode);
utils::print(switchMac); std::cout << switchMac << "\n";
printf("\n\tHost MAC:\t"); std::cout << "\tHost MAC:\t"<< hostMac << "\n";
utils::print(hostMac);
printf("\n\tLength:\t%hd", this->getLength()); printf("\n\tLength:\t%hd", this->getLength());
printf("\n\tOffset:\t%hd", fragmentOffset); printf("\n\tOffset:\t%hd", fragmentOffset);
printf("\n\tFlags:\t%.4hX", flag); printf("\n\tFlags:\t%.4hX", flag);
@ -161,32 +161,31 @@ std::string Packet::opCodeToString() {
void Packet::encode(bytes &data) { void Packet::encode(bytes &data) {
int len = data.size(); int len = data.size();
bytes key = { 191, 155, 227, 202, 99, 162, 79, 104, 49, 18, 190, 164, 30, std::vector<unsigned char> t = { 191, 155, 227, 202, 99, 162, 79, 104, 49,
76, 189, 131, 23, 52, 86, 106, 207, 125, 126, 169, 196, 28, 172, 58, 18, 190, 164, 30, 76, 189, 131, 23, 52, 86, 106, 207, 125, 126, 169,
188, 132, 160, 3, 36, 120, 144, 168, 12, 231, 116, 44, 41, 97, 108, 196, 28, 172, 58, 188, 132, 160, 3, 36, 120, 144, 168, 12, 231, 116,
213, 42, 198, 32, 148, 218, 107, 247, 112, 204, 14, 66, 68, 91, 224, 44, 41, 97, 108, 213, 42, 198, 32, 148, 218, 107, 247, 112, 204, 14,
206, 235, 33, 130, 203, 178, 1, 134, 199, 78, 249, 123, 7, 145, 73, 66, 68, 91, 224, 206, 235, 33, 130, 203, 178, 1, 134, 199, 78, 249,
208, 209, 100, 74, 115, 72, 118, 8, 22, 243, 147, 64, 96, 5, 87, 60, 123, 7, 145, 73, 208, 209, 100, 74, 115, 72, 118, 8, 22, 243, 147,
113, 233, 152, 31, 219, 143, 174, 232, 153, 245, 158, 254, 70, 170, 64, 96, 5, 87, 60, 113, 233, 152, 31, 219, 143, 174, 232, 153, 245,
75, 77, 215, 211, 59, 71, 133, 214, 157, 151, 6, 46, 81, 94, 136, 158, 254, 70, 170, 75, 77, 215, 211, 59, 71, 133, 214, 157, 151, 6,
166, 210, 4, 43, 241, 29, 223, 176, 67, 63, 186, 137, 129, 40, 248, 46, 81, 94, 136, 166, 210, 4, 43, 241, 29, 223, 176, 67, 63, 186,
255, 55, 15, 62, 183, 222, 105, 236, 197, 127, 54, 179, 194, 229, 137, 129, 40, 248, 255, 55, 15, 62, 183, 222, 105, 236, 197, 127,
185, 37, 90, 237, 184, 25, 156, 173, 26, 187, 220, 2, 225, 0, 240, 54, 179, 194, 229, 185, 37, 90, 237, 184, 25, 156, 173, 26, 187,
50, 251, 212, 253, 167, 17, 193, 205, 177, 21, 181, 246, 82, 226, 220, 2, 225, 0, 240, 50, 251, 212, 253, 167, 17, 193, 205, 177, 21,
38, 101, 163, 182, 242, 92, 20, 11, 95, 13, 230, 16, 121, 124, 109, 181, 246, 82, 226, 38, 101, 163, 182, 242, 92, 20, 11, 95, 13, 230,
195, 117, 39, 98, 239, 84, 56, 139, 161, 47, 201, 51, 135, 250, 10, 16, 121, 124, 109, 195, 117, 39, 98, 239, 84, 56, 139, 161, 47, 201,
19, 150, 45, 111, 27, 24, 142, 80, 85, 83, 234, 138, 216, 57, 93, 51, 135, 250, 10, 19, 150, 45, 111, 27, 24, 142, 80, 85, 83, 234,
65, 154, 141, 122, 34, 140, 128, 238, 88, 89, 9, 146, 171, 149, 53, 138, 216, 57, 93, 65, 154, 141, 122, 34, 140, 128, 238, 88, 89, 9,
102, 61, 114, 69, 217, 175, 103, 228, 35, 180, 252, 200, 192, 165, 146, 171, 149, 53, 102, 61, 114, 69, 217, 175, 103, 228, 35, 180,
159, 221, 244, 110, 119, 48 }; 252, 200, 192, 165, 159, 221, 244, 110, 119, 48 };
bytes key = t;
bytes s = key; bytes s = key;
int i, t, j = 0; int i, j = 0;
for (int k = 0; k < len; k++) { for (int k = 0; k < len; k++) {
i = (k + 1) % 256; i = (k + 1) % 256;
j = (j + s[i]) % 256; j = (j + s[i]) % 256;
t = s[i]; std::swap(s[i], s[j]);
s[i] = s[j];
s[j] = t;
data[k] = data[k] ^ s[(s[i] + s[j]) % 256]; data[k] = data[k] ^ s[(s[i] + s[j]) % 256];
} }
} }
@ -205,14 +204,14 @@ void Packet::push(bytes &arr, int &index, bytes data) {
push(arr, index, data[j]); push(arr, index, data[j]);
} }
void Packet::push(bytes &arr, int &index, inetAddr &data) { void Packet::push(bytes &arr, int &index, ipAddr data) {
for (unsigned j = 0; j < 4; j++) for (unsigned j = 0; j < 4; j++)
push(arr, index, data[j]); push(arr, index, (byte) data[j]);
} }
void Packet::push(bytes &arr, int &index, macAddr &data) { void Packet::push(bytes &arr, int &index, macAddr data) {
for (unsigned j = 0; j < 6; j++) for (unsigned j = 0; j < 6; j++)
push(arr, index, data[j]); push(arr, index, (byte) data[j]);
} }
void Packet::push(bytes &arr, int &index, short data) { void Packet::push(bytes &arr, int &index, short data) {
@ -254,7 +253,7 @@ void Packet::pull(bytes &arr, int &index, macAddr &ret) {
index += 6; index += 6;
} }
void Packet::pull(bytes &arr, int &index, inetAddr &ret) { void Packet::pull(bytes &arr, int &index, ipAddr &ret) {
memcpy(&ret[0], &arr[index], 4); memcpy(&ret[0], &arr[index], 4);
index += 4; index += 4;
} }

View file

@ -12,6 +12,8 @@
#define PACKET_END 0xFFFF0000 #define PACKET_END 0xFFFF0000
#include "Types.h" #include "Types.h"
#include "Types/bytes.h"
#include "Types/datasets.h"
class Packet { class Packet {
public: public:
@ -19,8 +21,6 @@ public:
DISCOVERY, GET, SET, READ DISCOVERY, GET, SET, READ
}; };
Packet(OpCode); Packet(OpCode);
virtual ~Packet() {
}
void encode(bytes&); void encode(bytes&);
bytes getBytes(); bytes getBytes();
void parse(bytes); void parse(bytes);
@ -64,15 +64,15 @@ private:
void push(bytes&, int&, int); void push(bytes&, int&, int);
void push(bytes&, int&, byte); void push(bytes&, int&, byte);
void push(bytes&, int&, bytes); void push(bytes&, int&, bytes);
void push(bytes&, int&, inetAddr&); void push(bytes&, int&, ipAddr);
void push(bytes&, int&, macAddr&); void push(bytes&, int&, macAddr);
void push(bytes&, int&, dataset); void push(bytes&, int&, dataset);
void pull(bytes&, int&, short&); void pull(bytes&, int&, short&);
void pull(bytes&, int&, int&); void pull(bytes&, int&, int&);
void pull(bytes&, int&, byte&); void pull(bytes&, int&, byte&);
void pull(bytes&, int&, bytes&, unsigned); void pull(bytes&, int&, bytes&, unsigned);
void pull(bytes&, int&, inetAddr&); void pull(bytes&, int&, ipAddr&);
void pull(bytes&, int&, macAddr&); void pull(bytes&, int&, macAddr&);
void pull(bytes&, int&, dataset&); void pull(bytes&, int&, dataset&);
}; };

View file

@ -7,17 +7,13 @@
#include <cstdio> #include <cstdio>
#include <algorithm> #include <algorithm>
#include "Utils.h"
#include "Options.h" #include "Options.h"
#include "Program.h" #include "Program.h"
#include "Host.h" #include "Host.h"
#include "Socket.h" #include "Socket.h"
#include "Switch.h"
#include "Packet.h" #include "Packet.h"
Program::Program() {
// TODO Auto-generated constructor stub
}
int Program::list() { int Program::list() {
//Device d = Device(); //Device d = Device();
@ -34,27 +30,21 @@ int Program::list() {
try { try {
asio::io_service io_service; asio::io_service io_service;
Socket s(io_service); Socket s(io_service);
s.setHostIp(h.getIp(options.interface)); s.setHostIp(h.getIp());
s.init(DST_PORT, SRC_PORT); s.init(DST_PORT, SRC_PORT);
s.callback = [](Packet a) { s.callback = [](Packet a) {
if (options.flags & FLAG_HEADER) { if (options.flags & FLAG_HEADER) {
printf("Received Header:\t"); std::cout <<"Received Header:\t"<< a.getHead() <<"\n";
utils::printHex(a.getHead());
printf("\n");
} }
if (options.flags & FLAG_HEX) { if (options.flags & FLAG_HEX) {
printf("Received Payload:\t"); std::cout <<"Received Payload:\t"<<a.getBody()<<"\n";
utils::printHex(a.getBody());
printf("\n");
} }
datasets d =a.getPayload(); datasets d =a.getPayload();
printf("\t%s (%s)\tMAC: ", &d[2].value[0], &d[1].value[0]); std::cout <<"\t"<<d[2].value <<"("<< d[1].value<<")\tMAC: "<<d[3].value<<"\tIP: "<<d[4].value<<"\n";
utils::printHex(d[3].value); Switch s = Switch();
printf("\tIP: "); std::cout <<"\t"<<s.settings.hostname<<"("<< s.device.type<<")\tMAC: "<<s.device.mac<<"\tIP: "<<s.settings.ip_addr<<"\n";
utils::printDec(d[4].value); return 1;
printf("\n"); };
return 1;
};
s.send(a); s.send(a);
io_service.run(); io_service.run();
} catch (std::exception& e) { } catch (std::exception& e) {
@ -70,29 +60,26 @@ int Program::sniff() {
asio::io_service io_service; asio::io_service io_service;
Host h = Host(); Host h = Host();
Socket s(io_service); Socket s(io_service);
s.setHostIp(h.getIp(options.interface)); s.setHostIp(h.getIp());
s.init(DST_PORT, SRC_PORT); s.init(DST_PORT, SRC_PORT);
s.callback = [](Packet p) { s.callback = [](Packet p) {
if (options.flags & FLAG_HEADER) { if (options.flags & FLAG_HEADER) {
if (options.flags & FLAG_HEX) { if (options.flags & FLAG_HEX) {
printf("Received Header:\t"); std::cout <<"Received Header:\t"<< p.getHead() <<"\n";
utils::printHex(p.getHead());
} else { } else {
p.printHeader(); p.printHeader();
printf("\n");
} }
printf("\n");
} }
if (options.flags & FLAG_HEX) { if (options.flags & FLAG_HEX) {
printf("Received Payload:\t"); std::cout <<"Received Payload:\t"<<p.getBody()<<"\n";
utils::printHex(p.getBody());
printf("\n");
} }
for(auto a : p.getPayload()) { for(auto a : p.getPayload()) {
dataset d = a.second; dataset d = a.second;
printf("#%d\tLength: %d\n\tHex: ",d.type,d.len); printf("#%d\tLength: %d\n\tHex: ",d.type,d.len);
utils::printHex(d.value); std::cout << d.value;
printf("\n\tDec: "); printf("\n\tDec: ");
utils::printDec(d.value); std::cout <<d.value;
d.value.push_back(0U); d.value.push_back(0U);
printf("\n\tString: %s\n",&d.value[0]); printf("\n\tString: %s\n",&d.value[0]);
} }
@ -108,7 +95,7 @@ int Program::sniff() {
} }
int Program::encode(std::string s) { int Program::encode(std::string s) {
bytes d = utils::readHex(s); bytes d(s);
Packet p = Packet(Packet::DISCOVERY); Packet p = Packet(Packet::DISCOVERY);
p.encode(d); p.encode(d);
printf("%x", d[0]); printf("%x", d[0]);
@ -119,31 +106,30 @@ int Program::encode(std::string s) {
return 0; return 0;
} }
int Program::setProperty() {
int Program::setProperty(){
return 0; return 0;
} }
int Program::getProperty(){ int Program::getProperty() {
return 0; return 0;
} }
int Program::save(){ int Program::save() {
//File = fopen(otions.file)
return 0;
}
int Program::restore() {
//File = fopen(otions.file)
return 0;
}
int Program::flash() {
return 0; return 0;
} }
int Program::restore(){ int Program::reboot() {
return 0; return 0;
} }
int Program::flash(){ int Program::reset() {
return 0;
}
int Program::reboot(){
return 0;
}
int Program::reset(){
return 0; return 0;
} }

View file

@ -15,9 +15,7 @@
class Program { class Program {
public: public:
Program(); Program(){}
virtual ~Program() {
}
int list(); int list();
int sniff(); int sniff();
int encode(std::string); int encode(std::string);

View file

@ -14,7 +14,6 @@
#include "Socket.h" #include "Socket.h"
#include "Packet.h" #include "Packet.h"
#include "Types.h" #include "Types.h"
#include "Utils.h"
#include "Options.h" #include "Options.h"
#include "Host.h" #include "Host.h"
@ -30,9 +29,7 @@ void Socket::init(short dst_port, short src_port) {
src_port = p; src_port = p;
} }
printf("IP:\t"); std::cout <<"IP:\t"<<local_ip<<"\n";
utils::print(local_ip);
printf("\n");
wildcard_endpoint_ = asio::ip::udp::endpoint( wildcard_endpoint_ = asio::ip::udp::endpoint(
asio::ip::address_v4::from_string("0.0.0.0"), src_port); asio::ip::address_v4::from_string("0.0.0.0"), src_port);
@ -44,16 +41,16 @@ void Socket::init(short dst_port, short src_port) {
send_socket_.open(asio::ip::udp::v4()); send_socket_.open(asio::ip::udp::v4());
send_socket_.set_option(asio::socket_base::broadcast(true)); send_socket_.set_option(asio::socket_base::broadcast(true));
send_socket_.set_option(asio::socket_base::reuse_address(true)); send_socket_.set_option(asio::socket_base::reuse_address(true));
send_socket_.bind(local_endpoint_); //TODO reuse Address send_socket_.bind(local_endpoint_);
receive_socket_.open(asio::ip::udp::v4()); receive_socket_.open(asio::ip::udp::v4());
receive_socket_.set_option(asio::socket_base::broadcast(true)); receive_socket_.set_option(asio::socket_base::broadcast(true));
receive_socket_.set_option(asio::socket_base::reuse_address(true)); receive_socket_.set_option(asio::socket_base::reuse_address(true));
receive_socket_.bind(wildcard_endpoint_); //TODO reuse Address receive_socket_.bind(wildcard_endpoint_);
} }
void Socket::setHostIp(inetAddr ip) { void Socket::setHostIp(ipAddr ip) {
local_ip=ip; local_ip=ip;
} }

View file

@ -11,6 +11,7 @@
#include <asio.hpp> #include <asio.hpp>
#include "Packet.h" #include "Packet.h"
#include "Types.h" #include "Types.h"
//#include "Types.h"
#define MAX_LENGTH 1024 #define MAX_LENGTH 1024
@ -22,7 +23,7 @@ public:
void init(short, short); void init(short, short);
void send(bytes); void send(bytes);
void listen(); void listen();
void setHostIp(inetAddr); void setHostIp(ipAddr);
int (*callback)(Packet)=[](Packet a) { int (*callback)(Packet)=[](Packet a) {
return 0; return 0;
}; };
@ -36,7 +37,7 @@ private:
asio::ip::udp::endpoint wildcard_endpoint_; asio::ip::udp::endpoint wildcard_endpoint_;
asio::ip::udp::endpoint local_endpoint_; asio::ip::udp::endpoint local_endpoint_;
bytes data = bytes(MAX_LENGTH); bytes data = bytes(MAX_LENGTH);
inetAddr local_ip; ipAddr local_ip;
}; };

View file

@ -7,8 +7,7 @@
#include "Switch.h" #include "Switch.h"
Switch::Switch() { void Switch::parse(datasets arr){
// TODO Auto-generated constructor stub
} }

View file

@ -10,6 +10,8 @@
#include <string> #include <string>
#include "Types.h" #include "Types.h"
#include "Types/bytes.h"
#include "Types/datasets.h"
#define DEFAULT_USER "admin" #define DEFAULT_USER "admin"
#define DEFAULT_PASS "admin" #define DEFAULT_PASS "admin"
@ -20,7 +22,8 @@ struct vlan {
}; };
struct port { struct port {
int id; byte id;
byte status;
struct { struct {
std::vector<vlan*> tagged; std::vector<vlan*> tagged;
std::vector<vlan*> untagged; std::vector<vlan*> untagged;
@ -30,26 +33,25 @@ struct port {
class Switch { class Switch {
public: public:
Switch(); Switch() {
}
void parse(datasets); void parse(datasets);
private:
struct { struct {
std::string type; std::string type;
std::string hardware_version; std::string hardware_version;
std::string firmware_version; std::string firmware_version;
macAddr mac; macAddr mac {0x0,0x0,0x0,0x0,0x0,0x0};
} device; } device;
struct { struct {
std::string password = DEFAULT_PASS; std::string password = DEFAULT_PASS;
std::string username = DEFAULT_USER; std::string username = DEFAULT_USER;
struct { std::string hostname;
std::string hostname; ipAddr ip_addr {0,0,0,0,};
inetAddr ip_addr; ipAddr ip_mask;
inetAddr ip_mask; ipAddr gateway;
inetAddr gateway; byte dhcp;
byte dhcp;
} network;
} settings; } settings;
private:
std::vector<vlan> vlans; std::vector<vlan> vlans;
std::vector<port> ports; std::vector<port> ports;
}; };

View file

@ -8,10 +8,62 @@
#ifndef TYPES_H_ #ifndef TYPES_H_
#define TYPES_H_ #define TYPES_H_
#include <functional> #include <initializer_list>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector> #include <vector>
#include <array> #include <array>
#include <map> #include "Types/bytes.h"
class macAddr: public std::array<byte, 6> {
public:
friend std::ostream& operator<<(std::ostream& out, const macAddr& arr) {
out << std::hex << std::setw(2) << std::setfill('0')
<< (unsigned) arr[0];
for (unsigned i = 1; i < 6; i++) {
out << ":" << std::setw(2) << std::setfill('0')
<< (unsigned) arr[i];
}
return out;
}
macAddr() {
*this= {0,0,0,0,0,0};
}
macAddr(std::initializer_list<byte> s) {
int i = 0;
for (byte b : s) {
if(i<6) (*this)[i++]=b;
else break;
}
}
};
class ipAddr: public std::array<byte, 4> {
public:
ipAddr() {
*this= {0,0,0,0,0,0};
}
ipAddr(std::initializer_list<byte> s) {
int i = 0;
for (byte b : s) {
if(i<4) (*this)[i++]=b;
else break;
}
}
friend std::ostream& operator<<(std::ostream& out, ipAddr& arr) {
out << std::dec << (unsigned) arr[0];
for (unsigned i = 1; i < 4; i++) {
out << "." << (unsigned) arr[i];
}
return out;
}
};
template<typename T> template<typename T>
std::vector<T> operator+(const std::vector<T> &A, const std::vector<T> &B) { std::vector<T> operator+(const std::vector<T> &A, const std::vector<T> &B) {
@ -29,23 +81,6 @@ std::vector<T> &operator+=(std::vector<T> &A, const std::vector<T> &B) {
return A; return A;
} }
typedef std::array<unsigned char, 6> macAddr;
typedef std::array<unsigned char, 4> inetAddr;
typedef std::vector<unsigned char> bytes;
typedef unsigned char byte;
struct dataset {
short type;
short len;
bytes value;
};
//typedef std::vector<dataset> datasets;
typedef std::map<short, dataset> datasets;
//std::function<int()>;
//typedef int receiveCallback;
struct Options { struct Options {
unsigned flags = 0x00; unsigned flags = 0x00;
std::string user; std::string user;

View file

@ -1,68 +0,0 @@
/*
* Utils.h
*
* Created on: 24.09.2015
* Author: jdi
*/
#ifndef UTILS_H_
#define UTILS_H_
#include <string>
#include <cstring>
#include "Types.h"
namespace utils {
static bytes readHex(std::string d) {
std::string delimiter = ":";
std::string token;
size_t pos = 0;
bytes arr = { };
int hex;
byte b;
while ((pos = d.find(delimiter)) != std::string::npos) {
token = d.substr(0, pos);
sscanf(token.c_str(), "%x", &hex);
d.erase(0, pos + delimiter.length());
b = hex & 0xFF;
arr.push_back(b);
}
sscanf(d.c_str(), "%x", &hex);
b = hex & 0xFF;
arr.push_back(b);
return arr;
}
static void printHex(bytes d) {
if (d.size() > 0)
printf("%.2X", d[0]);
for (unsigned i = 1; i < d.size(); i++) {
printf(":%.2X", d[i]);
}
}
static void print(macAddr d) {
printf("%.2X", d[0]);
for (unsigned i = 1; i < 6; i++) {
printf(":%.2X", d[i]);
}
}
static void print(inetAddr d) {
printf("%.1d", d[0]);
for (unsigned i = 1; i < 4; i++) {
printf(".%.1d", d[i]);
}
}
static void printDec(bytes d) {
if (d.size() > 0)
printf("%.1d", d[0]);
for (unsigned i = 1; i < d.size(); i++) {
printf(".%.1d", d[i]);
}
}
}
#endif /* UTILS_H_ */

View file

@ -7,13 +7,13 @@
//============================================================================ //============================================================================
#include <cstring> #include <cstring>
#include <getopt.h>
#include <unistd.h>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <stdlib.h> #include <cstdlib>
#include <stdio.h> #include <cstdio>
#include <getopt.h>
#include <unistd.h>
#include "Options.h" #include "Options.h"
#include "Host.h" #include "Host.h"
@ -158,8 +158,7 @@ int main(int argc, char *argv[]) {
break; break;
default: default:
printf("Unknown command: %s\n", argv[optind]); printf("Unknown command: %s\n", cmd.c_str());
optind++;
while (optind < argc) { while (optind < argc) {
printf("->%s\n", argv[optind]); printf("->%s\n", argv[optind]);
optind++; optind++;