aboutsummaryrefslogtreecommitdiff
path: root/src/receiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/receiver.cpp')
-rw-r--r--src/receiver.cpp29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/receiver.cpp b/src/receiver.cpp
index c6c5bdc..7ac940a 100644
--- a/src/receiver.cpp
+++ b/src/receiver.cpp
@@ -9,15 +9,9 @@
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[]) {
+ app_name = argv[0];
+
if (argc != 1) {
fprintf(stderr, "usage: %s\n", argv[0]);
return EXIT_FAILURE;
@@ -48,23 +42,12 @@ int main(int argc, char *argv[]) {
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");
+ throw std::runtime_error("recvfrom: " + string(strerror(errno)));
}
- 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;
- }
+ uint16_t size = static_cast<uint16_t>(n_read);
+ write_stdout(reinterpret_cast<uint8_t *>(&size), 2);
+ write_stdout(bytes, static_cast<size_t>(n_read));
}
google::protobuf::ShutdownProtobufLibrary();