fix: Expose to_ms / packet buffer timeout to libnethogs

This commit is contained in:
Aaron France
2019-10-01 00:24:04 +02:00
parent dbbee09d79
commit a3f0586ef8
2 changed files with 11 additions and 8 deletions

View File

@@ -73,7 +73,7 @@ static bool wait_for_next_trigger() {
} }
static int nethogsmonitor_init(int devc, char **devicenames, bool all, static int nethogsmonitor_init(int devc, char **devicenames, bool all,
char *filter) { char *filter, int to_ms) {
process_init(); process_init();
device *devices = get_devices(devc, devicenames, all); device *devices = get_devices(devc, devicenames, all);
@@ -101,7 +101,7 @@ static int nethogsmonitor_init(int devc, char **devicenames, bool all,
char errbuf[PCAP_ERRBUF_SIZE]; char errbuf[PCAP_ERRBUF_SIZE];
dp_handle *newhandle = dp_open_live(current_dev->name, BUFSIZ, promiscuous, dp_handle *newhandle = dp_open_live(current_dev->name, BUFSIZ, promiscuous,
100, filter, errbuf); to_ms, filter, errbuf);
if (newhandle != NULL) { if (newhandle != NULL) {
dp_addcb(newhandle, dp_packet_ip, process_ip); dp_addcb(newhandle, dp_packet_ip, process_ip);
dp_addcb(newhandle, dp_packet_ip6, process_ip6); dp_addcb(newhandle, dp_packet_ip6, process_ip6);
@@ -276,17 +276,17 @@ static void nethogsmonitor_clean_up() {
procclean(); procclean();
} }
int nethogsmonitor_loop(NethogsMonitorCallback cb, char *filter) { int nethogsmonitor_loop(NethogsMonitorCallback cb, char *filter, int to_ms) {
return nethogsmonitor_loop_devices(cb, filter, 0, NULL, false); return nethogsmonitor_loop_devices(cb, filter, 0, NULL, false, to_ms);
} }
int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, char *filter, int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, char *filter,
int devc, char **devicenames, bool all) { int devc, char **devicenames, bool all, int to_ms) {
if (monitor_run_flag) { if (monitor_run_flag) {
return NETHOGS_STATUS_FAILURE; return NETHOGS_STATUS_FAILURE;
} }
int return_value = nethogsmonitor_init(devc, devicenames, all, filter); int return_value = nethogsmonitor_init(devc, devicenames, all, filter, to_ms);
if (return_value != NETHOGS_STATUS_OK) { if (return_value != NETHOGS_STATUS_OK) {
return return_value; return return_value;
} }

View File

@@ -58,10 +58,12 @@ typedef void (*NethogsMonitorCallback)(int action,
* that of tcpdump(1); for full details, see the man page for pcap-filter(7). * that of tcpdump(1); for full details, see the man page for pcap-filter(7).
* Note that this is EXPERIMENTAL, and may be removed or changed in a future * Note that this is EXPERIMENTAL, and may be removed or changed in a future
* version. * version.
* @param to_ms: <insert documentation>
*/ */
NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb, NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb,
char *filter); char *filter,
int to_ms);
/** /**
* @brief Enter the process monitoring loop and reports updates using the * @brief Enter the process monitoring loop and reports updates using the
@@ -85,7 +87,8 @@ NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb,
NETHOGS_DSO_VISIBLE int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, NETHOGS_DSO_VISIBLE int nethogsmonitor_loop_devices(NethogsMonitorCallback cb,
char *filter, int devc, char *filter, int devc,
char **devicenames, char **devicenames,
bool all); bool all,
int to_ms);
/** /**
* @brief Makes the call to nethogsmonitor_loop return. * @brief Makes the call to nethogsmonitor_loop return.