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/capture.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/capture.cpp (limited to 'src/capture.cpp') diff --git a/src/capture.cpp b/src/capture.cpp new file mode 100644 index 0000000..5844b25 --- /dev/null +++ b/src/capture.cpp @@ -0,0 +1,47 @@ +#include +#include "wifi-triangulator/core.h" + +using namespace std; +using namespace wifi_triangulator; + +int main(int argc, char *argv[]) { + if (argc != 2) { + fprintf(stderr, "usage: %s [interface]\n", argv[0]); + return EXIT_FAILURE; + } + + string dev = argv[1]; + + GOOGLE_PROTOBUF_VERIFY_VERSION; + + string str; + str.reserve(1 << 16); + + int ret = launch_capture(dev, [&](const data &data) { + pb::envelope envelope; + envelope.set_time_s(data.sec); + envelope.set_time_us(data.usec); + envelope.set_type(data.type); + + if (data.type == pb::packet_type::probe_request) { + pb::probe *probe = envelope.mutable_probe(); + probe->set_src(data.src); + probe->set_dst(static_cast(data.dst)); + probe->set_rssi(data.rssi); + } + + envelope.SerializeToString(&str); + cout << static_cast(str.length()) << str << flush; + +// static int count = 0; +// cerr << "count=" << count << "!\r" << flush; +// count++; + }); + + google::protobuf::ShutdownProtobufLibrary(); + + cerr << "Capture exiting" << endl; + cout.flush(); + + return ret; +} -- cgit v1.2.3