void eRTSPStreamClient::process_pids(int op, const std::string &pid_str) { eDebug("%s: operation %d, pid_str %s (len pids: %d)", __FUNCTION__, op, pid_str.c_str(), pids.size()); if (op == _PIDS) { pids.clear(); if (pid_str.find("all") != std::string::npos) { pids.insert(8192); update_service_list(); return; } } std::stringstream ss(pid_str); std::string s; while (!ss.eof()) { std::getline(ss, s, ','); if (s.empty()) break; int p = atoi(s.c_str()); if (p < 0 || p > 8191) continue; if (op == _PIDS || op == _ADD_PIDS) add_pid(p); if (op == _DEL_PIDS) del_pid(p); } update_service_list(); }
int main(int argc, char *argv[]) { char errbuf[PCAP_ERRBUF_SIZE]; char *dev; struct iface_config *ifc; int optind; int i; bzero(&cfg, sizeof(cfg)); /* Default configuration */ // cfg.ratelimit = 0; cfg.hashsize = 1; // cfg.quiet = 0; cfg.promisc_flag = 1; // cfg.ratelimit = 0; // cfg.sqlite_file = NULL; // cfg.uname = NULL; cfg.shm_data.size = DEFAULT_SHM_LOG_SIZE; cfg.shm_data.name = DEFAULT_SHM_LOG_NAME; #if HAVE_LIBSQLITE3 cfg.sqlite_table = PACKAGE; #endif log_open(PACKAGE_NAME); argp_parse(&argp, argc, argv, 0, &optind, 0); if (!cfg.hostname) { cfg.hostname_len = sysconf(_SC_HOST_NAME_MAX); cfg.hostname = (char *)calloc(cfg.hostname_len, sizeof(char)); gethostname(cfg.hostname, cfg.hostname_len); } daemonize(); save_pid(); libevent_init(); if (cfg.ratelimit > 0) log_msg(LOG_DEBUG, "Ratelimiting duplicate entries to 1 per %d seconds", cfg.ratelimit); else if (cfg.ratelimit == -1) log_msg(LOG_DEBUG, "Duplicate entries supressed indefinitely"); else log_msg(LOG_DEBUG, "Duplicate entries ratelimiting disabled"); if (cfg.promisc_flag) log_msg(LOG_DEBUG, "PROMISC mode enabled"); else log_msg(LOG_DEBUG, "PROMISC mode disabled"); if (argc > optind) { for (i = optind; i < argc; i++) add_iface(argv[i]); } else { dev = pcap_lookupdev(errbuf); if (dev != NULL) add_iface(dev); } if (!cfg.interfaces) log_msg(LOG_ERR, "No suitable interfaces found!"); if (cfg.uname) drop_root(cfg.uname); output_flatfile_init(); output_sqlite_init(); output_shm_init(); /* main loop */ #if HAVE_LIBEVENT2 event_base_dispatch(cfg.eb); #else event_dispatch(); #endif output_shm_close(); output_sqlite_close(); output_flatfile_close(); for (ifc = cfg.interfaces; ifc != NULL; ifc = del_iface(ifc)); libevent_close(); log_close(); del_pid(); blacklist_free(); free(cfg.hostname); return 0; }