diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/wifi-triangulator/core.h | 65 |
1 files changed, 65 insertions, 0 deletions
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 <cstdint> +#include <sstream> +#include <iomanip> +#include <functional> + +#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<void(const class data &)>); + +} // namespace wifi_triangulator + +namespace std { +string to_string(wifi_triangulator::pb::packet_type t); +} // namespace std |