Merge pull request #134 from jantman/issues/129

fixes #129 - libnethogs support for limiting to specific devices
This commit is contained in:
Arnout Engelen
2017-08-27 13:49:52 +02:00
committed by GitHub
3 changed files with 69 additions and 6 deletions

View File

@@ -72,10 +72,10 @@ static bool wait_for_next_trigger() {
return true;
}
static int nethogsmonitor_init() {
static int nethogsmonitor_init(int devc, char **devicenames, bool all) {
process_init();
device *devices = get_default_devices();
device *devices = get_devices(devc, devicenames, all);
if (devices == NULL) {
std::cerr << "No devices to monitor" << std::endl;
return NETHOGS_STATUS_NO_DEVICE;
@@ -272,11 +272,16 @@ static void nethogsmonitor_clean_up() {
}
int nethogsmonitor_loop(NethogsMonitorCallback cb) {
return nethogsmonitor_loop_devices(cb, 0, NULL, false);
}
int nethogsmonitor_loop_devices(NethogsMonitorCallback cb,
int devc, char **devicenames, bool all) {
if (monitor_run_flag) {
return NETHOGS_STATUS_FAILURE;
}
int return_value = nethogsmonitor_init();
int return_value = nethogsmonitor_init(devc, devicenames, all);
if (return_value != NETHOGS_STATUS_OK) {
return return_value;
}

View File

@@ -57,6 +57,24 @@ typedef void (*NethogsMonitorCallback)(int action,
NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb);
/**
* @brief Enter the process monitoring loop and reports updates using the
* callback provided as parameter. Specify which network devices to monitor.
* All parameters other than cb are passed through to get_devices().
* This call will block until nethogsmonitor_breakloop() is called or a failure
* occurs.
* @param cb A pointer to a callback function following the
* NethogsMonitorCallback definition
* @param devc number of values in devicenames array
* @param devicenames pointer to array of devicenames (char arrays)
* @param all when false, loopback interface and down/not running interfaces
* will be avoided. When true, find all interfaces including down/not running.
*/
NETHOGS_DSO_VISIBLE int nethogsmonitor_loop_devices(NethogsMonitorCallback cb,
int devc, char **devicenames,
bool all);
/**
* @brief Makes the call to nethogsmonitor_loop return.
*/