From 36e59a1991f075e36e117a08321d5e4c4dc00eac Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 7 Apr 2017 19:03:05 +0200 Subject: o Splitting capture into just two, capture and send to stdout and transmit from stdin. o Adding formatter that formats the incoming message. --- src/formatter.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/formatter.cpp (limited to 'src/formatter.cpp') 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 +#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(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; +} -- cgit v1.2.3