#pragma once #include #include #include #include #include "wifi-triangulator.pb.h" namespace wifi_triangulator { extern std::string app_name; typedef std::basic_string bstring; 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::frame_type type; long sec; long usec; int rssi; int mhz; eth_mac src, dst; data(pb::frame_type type, long sec, long usec, int rssi, int mhz, eth_mac src, eth_mac dst) : type(type), sec(sec), usec(usec), rssi(rssi), mhz(mhz), src(src), dst(dst) {} }; int launch_capture(std::string dev, std::function); int launch_reader(std::function on_buffer); int launch_reader_envelope(std::function on_envelope); ssize_t read_stdin(uint8_t *data, size_t left); //void write_stdout(const bstring &s); void write_stdout(const std::string &s); void write_stdout(const uint8_t *data, size_t count); void write_envelope(pb::letter_type lt, pb::envelope &envelope); } // namespace wifi_triangulator namespace std { string to_string(wifi_triangulator::pb::frame_type t); } // namespace std