diff options
Diffstat (limited to 'src/formatter.cpp')
-rw-r--r-- | src/formatter.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/formatter.cpp b/src/formatter.cpp new file mode 100644 index 0000000..b165a89 --- /dev/null +++ b/src/formatter.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include "wifi-triangulator/core.h" + +using namespace std; +using namespace wifi_triangulator; + +void on_probe_request(const pb::probe &p) { + cout << "PROBE REQUEST" + << ", src=" << eth_mac(p.src()).to_string() + << ", dst=" << eth_mac(p.dst()).to_string() + << ", rssi=" << p.rssi() + << flush + << endl; +} + +void on_envelope(pb::envelope envelope) { + if (envelope.type() == pb::probe_request) { + on_probe_request(envelope.probe()); + } else { + cout << to_string(envelope.type()) << endl; + } +} + +int main(int argc, char *argv[]) { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + if (argc != 1) { + fprintf(stderr, "usage: %s\n", argv[0]); + return EXIT_FAILURE; + } + + int count = 0; + uint8_t buffer[1 << 16]; + while (!feof(stdin)) { + pb::envelope envelope; + + uint16_t size; + cin >> size; + cin.read(reinterpret_cast<char *>(buffer), size); + bool ok = envelope.ParseFromArray(buffer, size); + if (!ok) { + cerr << "bad read" << endl; + continue; + } + +// cerr << "count=" << count++ << endl; + + on_envelope(envelope); + } + + google::protobuf::ShutdownProtobufLibrary(); + + return EXIT_SUCCESS; +} |