diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 19:03:05 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 19:03:05 +0200 |
commit | 36e59a1991f075e36e117a08321d5e4c4dc00eac (patch) | |
tree | 2c89d0b9ad67eb6ebdcd5ed4b1789ebc61ce6723 /src/capture.cpp | |
parent | 84939234eb66fe7957eaf39956f18224e3108c25 (diff) | |
download | wifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.tar.gz wifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.tar.bz2 wifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.tar.xz wifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.zip |
o Splitting capture into just two, capture and send to stdout and transmit from stdin.
o Adding formatter that formats the incoming message.
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; +} |