From d30c5226a0996f2596cb407999e7c1296ccbb5e5 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Mon, 9 Jan 2023 12:39:07 +0100 Subject: [PATCH] Format source code It appears we have failed to run `make format` in the last few commits. Doing it now. We should really add it to CI --- src/cui.cpp | 6 +++--- src/libnethogs.cpp | 5 +++-- src/libnethogs.h | 6 ++---- src/main.cpp | 15 ++++++++------- src/packet.cpp | 7 +++---- src/packet.h | 2 +- src/process.cpp | 13 +++++++------ src/process.h | 8 ++++---- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/cui.cpp b/src/cui.cpp index 8ce50fd..e232c41 100644 --- a/src/cui.cpp +++ b/src/cui.cpp @@ -336,9 +336,9 @@ void show_trace(Line *lines[], int nproc) { } /* print the 'unknown' connections, for debugging */ - for (auto it = unknowntcp->connections.begin(); it != unknowntcp->connections.end(); ++it) { - std::cout << "Unknown connection: " - << (*it)->refpacket->gethashstring() + for (auto it = unknowntcp->connections.begin(); + it != unknowntcp->connections.end(); ++it) { + std::cout << "Unknown connection: " << (*it)->refpacket->gethashstring() << std::endl; } } diff --git a/src/libnethogs.cpp b/src/libnethogs.cpp index ef4df82..2d02d05 100644 --- a/src/libnethogs.cpp +++ b/src/libnethogs.cpp @@ -277,11 +277,12 @@ static void nethogsmonitor_clean_up() { } int nethogsmonitor_loop(NethogsMonitorCallback cb, char *filter, int to_ms) { - return nethogsmonitor_loop_devices(cb, filter, 0, NULL, false, to_ms); + return nethogsmonitor_loop_devices(cb, filter, 0, NULL, false, to_ms); } int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, char *filter, - int devc, char **devicenames, bool all, int to_ms) { + int devc, char **devicenames, bool all, + int to_ms) { if (monitor_run_flag) { return NETHOGS_STATUS_FAILURE; } diff --git a/src/libnethogs.h b/src/libnethogs.h index 81d127d..2ea0167 100644 --- a/src/libnethogs.h +++ b/src/libnethogs.h @@ -62,8 +62,7 @@ typedef void (*NethogsMonitorCallback)(int action, */ NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb, - char *filter, - int to_ms); + char *filter, int to_ms); /** * @brief Enter the process monitoring loop and reports updates using the @@ -87,8 +86,7 @@ NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb, NETHOGS_DSO_VISIBLE int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, char *filter, int devc, char **devicenames, - bool all, - int to_ms); + bool all, int to_ms); /** * @brief Makes the call to nethogsmonitor_loop return. diff --git a/src/main.cpp b/src/main.cpp index 2c71f88..da10cca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,7 +51,8 @@ static void help(bool iserror) { output << " -C : capture TCP and UDP.\n"; output << " -g : garbage collection period in number of refresh. " "default is 50.\n"; - output << " -b : Short program name. Displays only the program name.\n"; + output << " -b : Short program name. Displays only the program " + "name.\n"; output << " -f : EXPERIMENTAL: specify string pcap filter (like " "tcpdump)." " This may be removed or changed in a future version.\n"; @@ -150,7 +151,6 @@ int main(int argc, char **argv) { char *filter = NULL; int garbage_collection_period = 50; - int opt; while ((opt = getopt(argc, argv, "Vhxtpsd:v:c:laf:Cbg:P:")) != -1) { switch (opt) { @@ -201,7 +201,7 @@ int main(int argc, char **argv) { garbage_collection_period = (time_t)atoi(optarg); break; case 'P': - pidsToWatch.insert((pid_t) atoi(optarg)); + pidsToWatch.insert((pid_t)atoi(optarg)); break; default: help(true); @@ -287,10 +287,11 @@ int main(int argc, char **argv) { if (nb_devices == nb_failed_devices) { if (geteuid() != 0) - fprintf(stderr, "To run nethogs without being root, you need to enable " - "capabilities on the program (cap_net_admin, cap_net_raw, " - "cap_dac_read_search, cap_sys_ptrace). " - "See the documentation for details.\n"); + fprintf(stderr, + "To run nethogs without being root, you need to enable " + "capabilities on the program (cap_net_admin, cap_net_raw, " + "cap_dac_read_search, cap_sys_ptrace). " + "See the documentation for details.\n"); forceExit(false, "Error opening pcap handlers for all devices.\n"); } diff --git a/src/packet.cpp b/src/packet.cpp index 34b8791..323ae44 100644 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -300,9 +300,8 @@ bool Packet::match(const Packet *other) const { bool Packet::matchSource(const Packet *other) const { return sa_family == other->sa_family && (sport == other->sport) && - (sa_family == AF_INET - ? (sameinaddr(sip, other->sip)) - : (samein6addr(sip6, other->sip6))); + (sa_family == AF_INET ? (sameinaddr(sip, other->sip)) + : (samein6addr(sip6, other->sip6))); } Packet Packet::onlySource() const { @@ -313,7 +312,7 @@ Packet Packet::onlySource() const { return p; } -bool Packet::operator< (const Packet& other) const { +bool Packet::operator<(const Packet &other) const { if (sa_family != other.sa_family) return dir < other.sa_family; /* source address first */ diff --git a/src/packet.h b/src/packet.h index 0fde51b..0eb4cfe 100644 --- a/src/packet.h +++ b/src/packet.h @@ -74,7 +74,7 @@ public: bool matchSource(const Packet *other) const; /* returns a copy with destination information stripped (for comparisons) */ Packet onlySource() const; - bool operator< (const Packet& other) const; + bool operator<(const Packet &other) const; /* returns '1.2.3.4:5-1.2.3.4:6'-style string */ char *gethashstring(); diff --git a/src/process.cpp b/src/process.cpp index 1cfc741..6c6dd30 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -30,12 +30,12 @@ #endif #include #include +#include #include #include #include #include #include -#include #include "conninode.h" #include "inode2prog.h" @@ -81,7 +81,6 @@ float tokbps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / KB; } float tombps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / MB; } float togbps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / GB; } - void process_init() { unknowntcp = new Process(0, "", "unknown TCP"); processes = new ProcList(unknowntcp, NULL); @@ -92,7 +91,6 @@ void process_init() { // unknownip = new Process (0, "", "unknown IP"); // processes = new ProcList (unknownip, processes); } - } int Process::getLastPacket() { @@ -110,7 +108,8 @@ static void sum_active_connections(Process *process_ptr, u_int64_t &sum_sent, u_int64_t &sum_recv) { /* walk though all process_ptr process's connections, and sum * them up */ - for (auto it = process_ptr->connections.begin(); it != process_ptr->connections.end(); ) { + for (auto it = process_ptr->connections.begin(); + it != process_ptr->connections.end();) { if ((*it)->getLastPacket() <= curtime.tv_sec - CONNTIMEOUT) { /* capture sent and received totals before deleting */ process_ptr->sent_by_closed_bytes += (*it)->sumSent; @@ -158,7 +157,8 @@ void Process::getgbps(float *recvd, float *sent) { /** get total values for this process */ void Process::gettotal(u_int64_t *recvd, u_int64_t *sent) { u_int64_t sum_sent = 0, sum_recv = 0; - for (auto it = this->connections.begin(); it != this->connections.end(); ++it) { + for (auto it = this->connections.begin(); it != this->connections.end(); + ++it) { Connection *conn = (*it); sum_sent += conn->sumSent; sum_recv += conn->sumRecv; @@ -253,7 +253,8 @@ Process *getProcess(unsigned long inode, const char *devicename) { if (proc != NULL) return proc; - if ( !(pidsToWatch.empty()) && pidsToWatch.find(node->pid) == pidsToWatch.end() ) { + if (!(pidsToWatch.empty()) && + pidsToWatch.find(node->pid) == pidsToWatch.end()) { return NULL; } diff --git a/src/process.h b/src/process.h index 3730e33..5396b41 100644 --- a/src/process.h +++ b/src/process.h @@ -36,19 +36,19 @@ void check_all_procs(); /* compares Connection pointers by their refpacket */ struct ConnectionComparator { using is_transparent = void; - bool operator()(const Connection* l, const Connection* r) const { + bool operator()(const Connection *l, const Connection *r) const { return *l->refpacket < *r->refpacket; } - bool operator()(const Packet* l, const Connection* r) const { + bool operator()(const Packet *l, const Connection *r) const { return *l < *r->refpacket; } - bool operator()(const Connection* l, const Packet* r) const { + bool operator()(const Connection *l, const Packet *r) const { return *l->refpacket < *r; } }; /* ordered set of Connection pointers */ -typedef std::multiset ConnList; +typedef std::multiset ConnList; class Process { public: