From 84939234eb66fe7957eaf39956f18224e3108c25 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 7 Apr 2017 17:45:02 +0200 Subject: o Refactoring into two parts, sender and receiver that sends protobuf messages over UDP. --- include/wifi-triangulator/core.h | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 include/wifi-triangulator/core.h (limited to 'include') diff --git a/include/wifi-triangulator/core.h b/include/wifi-triangulator/core.h new file mode 100644 index 0000000..042490a --- /dev/null +++ b/include/wifi-triangulator/core.h @@ -0,0 +1,65 @@ +#pragma once + +#include +#include +#include +#include + +#include "wifi-triangulator.pb.h" + +namespace wifi_triangulator { + +struct eth_mac { + uint8_t a, b, c, d, e, f; + + eth_mac() {} + + eth_mac(uint64_t value) : a(uint8_t(value >> 40 & 0xff)), + b(uint8_t(value >> 32 & 0xff)), + c(uint8_t(value >> 24 & 0xff)), + d(uint8_t(value >> 16 & 0xff)), + e(uint8_t(value >> 9 & 0xff)), + f(uint8_t(value & 0xff)) {} + + std::string to_string() const { + std::stringstream s; + s << std::hex << std::setw(2) << std::setfill('0') + << (int) a << ":" + << std::setw(2) << std::setfill('0') << (int) b << ":" + << std::setw(2) << std::setfill('0') << (int) c << ":" + << std::setw(2) << std::setfill('0') << (int) d << ":" + << std::setw(2) << std::setfill('0') << (int) e << ":" + << std::setw(2) << std::setfill('0') << (int) f; + return s.str(); + } + + operator uint64_t() const { + return uint64_t(a) << 40 | + uint64_t(b) << 32 | + uint64_t(c) << 24 | + uint64_t(d) << 16 | + uint64_t(e) << 8 | + uint64_t(f); + } +} __attribute__((packed)); + +class data { +public: + pb::packet_type type; + long sec; + long usec; + + int rssi; + eth_mac src, dst; + + data(pb::packet_type type, long sec, long usec, int rssi, eth_mac src, eth_mac dst) : + type(type), sec(sec), usec(usec), src(src), rssi(rssi), dst(dst) {} +}; + +int launch_capture(std::string dev, std::function); + +} // namespace wifi_triangulator + +namespace std { +string to_string(wifi_triangulator::pb::packet_type t); +} // namespace std -- cgit v1.2.3