#include #include #include #include #include #include #include #include "ext/toml.hpp" extern "C" { #include "ext/lpm.h" } using namespace std; class LPMWrapper { public: LPMWrapper() { d_lpm = lpm_create(); } ~LPMWrapper() { lpm_destroy(d_lpm); } void insert(const std::string& str, void* val=(void*)1) { char addr[16]; size_t len=sizeof(addr); unsigned preflen=0; lpm_strtobin(str.c_str(), addr, &len, &preflen); if(lpm_insert(d_lpm, addr, len, preflen, val) < 0) throw std::runtime_error("Error inserting prefix"); } void* lookup(const char*str) { char addr[16]; size_t len=sizeof(addr); unsigned preflen=0; lpm_strtobin(str, addr, &len, &preflen); return lpm_lookup(d_lpm, addr, len); } private: lpm_t* d_lpm; }; struct TrackerConf { double freq{400}; double balance{0.5}; // 0 is left, 1 is right std::atomic counter{0}; }; void playerThread(const TrackerConf* tcptr) { auto& counter = tcptr->counter; audio_object* ao; ao=create_audio_device_object(0, "teller", ""); if(!ao) { cerr<<"Unable to open audio file "< data; int ourcounter=0; data.reserve(44100); while(counter >= 0) { data.clear(); if(ourcounter < counter) { for(int n=0; n < 250; ++n) { int16_t val = 20000 * sin((n/44100.0) * tcptr->freq * 2 * M_PI); int16_t lval = tcptr->balance * val; int16_t rval = (1.0-tcptr->balance) * val; data.push_back(lval); data.push_back(rval); } ourcounter++; if(counter - ourcounter > 1000) ourcounter = counter; } else { for(int n=0; n < 150; ++n) { data.push_back(0); data.push_back(0); } } audio_object_write(ao, &data[0], data.size() * sizeof(decltype(data)::value_type)); // audio_object_flush(ao); } } int main(int argc, char** argv) { toml::table conftbl, trackertbl; try { trackertbl = toml::parse_file("trackers.conf"); conftbl = toml::parse_file("teller.conf"); // std::cout << tbl << "\n"; } catch (const toml::parse_error& err) { std::cerr << "Parsing failed:\n" << err << "\n"; return 1; } map trackerdb; auto tellerarr = conftbl.as_table(); for(const auto& t : *tellerarr) { auto& entry = trackerdb[(string)t.first]; entry.balance = conftbl[t.first]["balance"].value_or(0.5); entry.freq = conftbl[t.first]["freq"].value_or(500); cout <<"Want to play sound for tracker "<for_each([&trackspos, &trackerptr](auto&& el) { if constexpr (toml::is_string) { trackspos.insert(*el, (void*)trackerptr); } }); } else { cout<<"Not array?"<for_each([&tracksneg, &trackerptr](auto&& el) { if constexpr (toml::is_string) { tracksneg.insert(*el, (void*)trackerptr); } }); } else { cout<<"Negative "< 10.0.0.3.32902: tcp 1186 22:42:25.323997 IP 10.0.0.3.32902 > 13.81.0.219.29601: tcp 0 22:42:25.327216 b0:95:75:c3:68:92 > ff:ff:ff:ff:ff:ff, RRCP-0x25 query */ auto pos = line.find('>'); if(pos == string::npos) continue; auto pos2 = line.find('.', pos); if(pos2 == string::npos) continue; pos2 = line.find('.', pos2+1); if(pos2 == string::npos) continue; pos2 = line.find('.', pos2+1); if(pos2 == string::npos) continue; pos2 = line.find_first_of(".:", pos2+1); if(pos2 == string::npos) continue; line.resize(pos2); string ip=line.substr(pos+2, pos2 - pos - 2); // cout<<&line.at(pos+2)<counter++; } } sleep(1); }