diff options
Diffstat (limited to 'src/capture.cpp')
-rw-r--r-- | src/capture.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
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 <iostream> +#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<uint64_t>(data.dst)); + probe->set_rssi(data.rssi); + } + + envelope.SerializeToString(&str); + cout << static_cast<uint16_t>(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; +} |