#include #include "wifi-triangulator/core.h" #include #include #include using namespace std; using namespace wifi_triangulator; class human_output { public: void handle(const data &data) { printf("timestamp=%lu, rssi=%d, src=%s, dst=%s, type=%s\n", ((data.sec * 1000 * 1000) + data.usec) * 1000, data.rssi, data.src.to_string().c_str(), data.dst.to_string().c_str(), to_string(data.type).c_str()); fflush(stdout); }; }; int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "usage: %s [host]\n", argv[0]); return EXIT_FAILURE; } string host = argv[1]; GOOGLE_PROTOBUF_VERIFY_VERSION; int s; struct sockaddr_in addr_si; struct sockaddr *addr; socklen_t addr_len; if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { throw std::runtime_error("socket"); } memset((char *) &addr_si, 0, sizeof(addr_si)); addr_si.sin_family = AF_INET; addr_si.sin_port = htons(3333); if (inet_aton(host.c_str(), &addr_si.sin_addr) == 0) { throw std::runtime_error("Could not resolve " + host); } addr = reinterpret_cast(&addr_si); addr_len = sizeof(addr_si); launch_reader([&](uint16_t size, const uint8_t* data) { if (sendto(s, data, size, 0, addr, addr_len) == -1) { throw std::runtime_error("sendto failed"); } return true; }); cerr << app_name << " exiting" << endl; google::protobuf::ShutdownProtobufLibrary(); return EXIT_SUCCESS; }