sniffing function added
This commit is contained in:
parent
699ff4221d
commit
671a9df9d7
5 changed files with 47 additions and 11 deletions
|
|
@ -27,11 +27,10 @@ int Program::list() {
|
||||||
//Device d = Device();
|
//Device d = Device();
|
||||||
//printf(" %d\n", d.getName());
|
//printf(" %d\n", d.getName());
|
||||||
|
|
||||||
bytes b = { 255, 255, 0, 0 };
|
|
||||||
Host h = Host();
|
Host h = Host();
|
||||||
Packet p = Packet(Packet::DISCOVERY);
|
Packet p = Packet(Packet::DISCOVERY);
|
||||||
p.setBody(b);
|
|
||||||
p.setHostMac(h.getMac());
|
p.setHostMac(h.getMac());
|
||||||
|
p.setPayload({});
|
||||||
bytes a = p.getBytes();
|
bytes a = p.getBytes();
|
||||||
p.encode(a);
|
p.encode(a);
|
||||||
|
|
||||||
|
|
|
||||||
34
src/Utils.h
Normal file
34
src/Utils.h
Normal 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_ */
|
||||||
|
|
@ -163,7 +163,12 @@ void Packet::encode(bytes &data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packet::push(bytes &arr, int &index, byte 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) {
|
void Packet::push(bytes &arr, int &index, bytes data) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#define PACKET_H_
|
#define PACKET_H_
|
||||||
|
|
||||||
#define HEADER_LEN 32
|
#define HEADER_LEN 32
|
||||||
#define PACKET_END -65536
|
#define PACKET_END 0xFFFF0000
|
||||||
|
|
||||||
#include "../Types.h"
|
#include "../Types.h"
|
||||||
|
|
||||||
|
|
@ -19,11 +19,12 @@ public:
|
||||||
DISCOVERY, GET, SET, READ
|
DISCOVERY, GET, SET, READ
|
||||||
};
|
};
|
||||||
Packet(OpCode);
|
Packet(OpCode);
|
||||||
virtual ~Packet(){};
|
virtual ~Packet() {
|
||||||
|
}
|
||||||
void encode(bytes&);
|
void encode(bytes&);
|
||||||
bytes getBytes();
|
bytes getBytes();
|
||||||
void parse(bytes);
|
void parse(bytes);
|
||||||
short getLength() const ;
|
short getLength() const;
|
||||||
int getCheckSum() const;
|
int getCheckSum() const;
|
||||||
short getSequenceId() const;
|
short getSequenceId() const;
|
||||||
const bytes& getSwitchMac() const;
|
const bytes& getSwitchMac() const;
|
||||||
|
|
@ -39,13 +40,13 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bytes head = bytes(32);
|
bytes head = bytes(32);
|
||||||
bytes body;
|
bytes body = bytes(0);
|
||||||
datasets payload;
|
datasets payload;
|
||||||
|
|
||||||
byte version = 1;
|
byte version = 1;
|
||||||
byte opCode;
|
byte opCode;
|
||||||
bytes switchMac = { 0, 0, 0, 0, 0, 0 };
|
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 };
|
bytes broadcastMac = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
short sequenceId;
|
short sequenceId;
|
||||||
short tokenId = 0;
|
short tokenId = 0;
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,4 @@ void Socket::listen() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//printf("Listen\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue