aboutsummaryrefslogtreecommitdiff
path: root/receiver.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-04-07 19:03:05 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-04-07 19:03:05 +0200
commit36e59a1991f075e36e117a08321d5e4c4dc00eac (patch)
tree2c89d0b9ad67eb6ebdcd5ed4b1789ebc61ce6723 /receiver.cpp
parent84939234eb66fe7957eaf39956f18224e3108c25 (diff)
downloadwifi-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 'receiver.cpp')
-rw-r--r--receiver.cpp80
1 files changed, 0 insertions, 80 deletions
diff --git a/receiver.cpp b/receiver.cpp
deleted file mode 100644
index c6c8f72..0000000
--- a/receiver.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-#include "wifi-triangulator/core.h"
-#include "wifi-triangulator.pb.h"
-
-#include <iostream>
-#include <unistd.h>
-
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <exception>
-#include <cstring>
-
-using namespace std;
-using namespace wifi_triangulator;
-
-void on_probe_request(const pb::probe &p) {
- cerr << "PROBE REQUEST"
- << ", src=" << eth_mac(p.src()).to_string()
- << ", dst=" << eth_mac(p.dst()).to_string()
- << ", rssi=" << p.rssi()
- << endl;
-}
-
-int main(int argc, char *argv[]) {
- if (argc != 1) {
- fprintf(stderr, "usage: %s\n", argv[0]);
- return EXIT_FAILURE;
- }
-
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- uint16_t port = 3333;
- int s;
- struct sockaddr_in si_me;
- if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
- throw std::runtime_error("socket");
-
- memset((char *) &si_me, 0, sizeof(si_me));
- si_me.sin_family = AF_INET;
- si_me.sin_port = htons(port);
- si_me.sin_addr.s_addr = htonl(INADDR_ANY);
- if (::bind(s, reinterpret_cast<struct sockaddr *>(&si_me), sizeof(si_me)) == -1) {
- throw std::runtime_error("bind");
- }
-
- sockaddr *me = reinterpret_cast<sockaddr *>(&si_me);
-
- pb::envelope envelope;
- while (true) {
- size_t len = 64 * 1024;
- uint8_t bytes[len];
- ssize_t n_read;
-
- struct sockaddr_in si_other;
- socklen_t addr_len;
- if ((n_read = ::recvfrom(s, bytes, len, 0, reinterpret_cast<struct sockaddr *>(&si_other), &addr_len)) == -1) {
- throw std::runtime_error("recvfrom");
- }
-
- string str;
- for (socklen_t i = 0; i < n_read; i++) {
- str += bytes[i];
- }
-
- istringstream ss{str};
- bool ok = envelope.ParseFromIstream(&ss);
- if (ok) {
- if (envelope.type() == pb::probe_request) {
- on_probe_request(envelope.probe());
- }
- } else {
- cerr << "FAIL n_read=" << n_read << flush << endl;
- }
- }
-
- google::protobuf::ShutdownProtobufLibrary();
-}