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
This commit is contained in:
Arnout Engelen
2023-01-09 12:39:07 +01:00
parent 80df0044ec
commit d30c5226a0
8 changed files with 31 additions and 31 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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.

View File

@@ -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");
}

View File

@@ -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 */

View File

@@ -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();

View File

@@ -30,12 +30,12 @@
#endif
#include <map>
#include <pwd.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#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;
}

View File

@@ -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<Connection*, ConnectionComparator> ConnList;
typedef std::multiset<Connection *, ConnectionComparator> ConnList;
class Process {
public: