Commit 671a9df9 authored by /jdi/'s avatar /jdi/
Browse files

sniffing function added

parent 699ff422
......@@ -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);
......
/*
* 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) {
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) {
......
......@@ -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;
......
......@@ -73,7 +73,4 @@ void Socket::listen() {
}
}
});
//printf("Listen\n");
}
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