sniffing function added

This commit is contained in:
/jdi/ 2015-09-26 14:02:24 +02:00
parent 699ff4221d
commit 671a9df9d7
5 changed files with 47 additions and 11 deletions

View file

@ -27,11 +27,10 @@ int Program::list() {
//Device d = Device();
//printf(" %d\n", d.getName());
bytes b = { 255, 255, 0, 0 };
Host h = Host();
Packet p = Packet(Packet::DISCOVERY);
p.setBody(b);
p.setHostMac(h.getMac());
p.setPayload({});
bytes a = p.getBytes();
p.encode(a);

34
src/Utils.h Normal file
View file

@ -0,0 +1,34 @@
/*
* 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 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 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

@ -163,7 +163,12 @@ void Packet::encode(bytes &data) {
}
void Packet::push(bytes &arr, int &index, byte data) {
arr[index++] = data;
if (arr.size() > index) {
arr[index++] = data;
} else {
arr.push_back(data);
index++;
}
}
void Packet::push(bytes &arr, int &index, bytes data) {

View file

@ -9,7 +9,7 @@
#define PACKET_H_
#define HEADER_LEN 32
#define PACKET_END -65536
#define PACKET_END 0xFFFF0000
#include "../Types.h"
@ -19,11 +19,12 @@ public:
DISCOVERY, GET, SET, READ
};
Packet(OpCode);
virtual ~Packet(){};
virtual ~Packet() {
}
void encode(bytes&);
bytes getBytes();
void parse(bytes);
short getLength() const ;
short getLength() const;
int getCheckSum() const;
short getSequenceId() const;
const bytes& getSwitchMac() const;
@ -39,13 +40,13 @@ public:
private:
bytes head = bytes(32);
bytes body;
bytes body = bytes(0);
datasets payload;
byte version = 1;
byte opCode;
bytes switchMac = { 0, 0, 0, 0, 0, 0 };
bytes hostMac = { 0, 0, 0, 0, 0, 0 };// TODO set Mac
bytes hostMac = { 0, 0, 0, 0, 0, 0 }; // TODO set Mac
bytes broadcastMac = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
short sequenceId;
short tokenId = 0;

View file

@ -73,7 +73,4 @@ void Socket::listen() {
}
}
});
//printf("Listen\n");
}