move C-style-list to std::list
This commit is contained in:
@@ -10,6 +10,7 @@ extern "C" {
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
//////////////////////////////
|
||||
extern ProcList *processes;
|
||||
@@ -33,7 +34,7 @@ static fd_set pc_loop_fd_set;
|
||||
static std::vector<int> pc_loop_fd_list;
|
||||
static bool pc_loop_use_select = true;
|
||||
|
||||
static handle *handles = NULL;
|
||||
static std::list<handle> handles;
|
||||
|
||||
static std::pair<int, int> create_self_pipe() {
|
||||
int pfd[2];
|
||||
@@ -117,7 +118,7 @@ static int nethogsmonitor_init(int devc, char **devicenames, bool all,
|
||||
if (dp_setnonblock(newhandle, 1, errbuf) == -1) {
|
||||
fprintf(stderr, "Error putting libpcap in nonblocking mode\n");
|
||||
}
|
||||
handles = new handle(newhandle, current_dev->name, handles);
|
||||
handles.push_front(handle(newhandle, current_dev->name));
|
||||
|
||||
if (pc_loop_use_select) {
|
||||
// some devices may not support pcap_get_selectable_fd
|
||||
@@ -264,15 +265,10 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb) {
|
||||
|
||||
static void nethogsmonitor_clean_up() {
|
||||
// clean up
|
||||
handle *current_handle = handles;
|
||||
handle *rem;
|
||||
while (current_handle != NULL) {
|
||||
for(auto current_handle = handles.begin(); current_handle != handles.end(); current_handle++){
|
||||
pcap_close(current_handle->content->pcap_handle);
|
||||
rem = current_handle;
|
||||
current_handle = current_handle->next;
|
||||
free(rem);
|
||||
}
|
||||
handles = NULL;
|
||||
handles.clear();
|
||||
|
||||
// close file descriptors
|
||||
for (std::vector<int>::const_iterator it = pc_loop_fd_list.begin();
|
||||
@@ -307,8 +303,7 @@ int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, char *filter,
|
||||
while (monitor_run_flag) {
|
||||
bool packets_read = false;
|
||||
|
||||
handle *current_handle = handles;
|
||||
while (current_handle != NULL) {
|
||||
for(auto current_handle = handles.begin(); current_handle != handles.end(); current_handle++) {
|
||||
userdata->device = current_handle->devicename;
|
||||
userdata->sa_family = AF_UNSPEC;
|
||||
int retval = dp_dispatch(current_handle->content, -1, (u_char *)userdata,
|
||||
@@ -320,7 +315,6 @@ int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, char *filter,
|
||||
} else {
|
||||
gettimeofday(&curtime, NULL);
|
||||
}
|
||||
current_handle = current_handle->next;
|
||||
}
|
||||
|
||||
time_t const now = ::time(NULL);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/capability.h>
|
||||
@@ -236,7 +237,7 @@ int main(int argc, char **argv) {
|
||||
int nb_devices = 0;
|
||||
int nb_failed_devices = 0;
|
||||
|
||||
handle *handles = NULL;
|
||||
std::list<handle> handles;
|
||||
device *current_dev = devices;
|
||||
while (current_dev != NULL) {
|
||||
++nb_devices;
|
||||
@@ -262,7 +263,7 @@ int main(int argc, char **argv) {
|
||||
if (dp_setnonblock(newhandle, 1, errbuf) == -1) {
|
||||
fprintf(stderr, "Error putting libpcap in nonblocking mode\n");
|
||||
}
|
||||
handles = new handle(newhandle, current_dev->name, handles);
|
||||
handles.push_front(handle(newhandle, current_dev->name));
|
||||
|
||||
if (pc_loop_use_select) {
|
||||
// some devices may not support pcap_get_selectable_fd
|
||||
@@ -308,8 +309,7 @@ int main(int argc, char **argv) {
|
||||
while (1) {
|
||||
bool packets_read = false;
|
||||
|
||||
for (handle *current_handle = handles; current_handle != NULL;
|
||||
current_handle = current_handle->next) {
|
||||
for (auto current_handle = handles.begin(); current_handle != handles.end(); current_handle ++) {
|
||||
userdata->device = current_handle->devicename;
|
||||
userdata->sa_family = AF_UNSPEC;
|
||||
int retval = dp_dispatch(current_handle->content, -1, (u_char *)userdata,
|
||||
|
||||
@@ -237,13 +237,10 @@ int process_ip6(u_char *userdata, const dp_header * /* header */,
|
||||
|
||||
class handle {
|
||||
public:
|
||||
handle(dp_handle *m_handle, const char *m_devicename = NULL,
|
||||
handle *m_next = NULL) {
|
||||
handle(dp_handle *m_handle, const char *m_devicename = NULL) {
|
||||
content = m_handle;
|
||||
next = m_next;
|
||||
devicename = m_devicename;
|
||||
}
|
||||
dp_handle *content;
|
||||
const char *devicename;
|
||||
handle *next;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user