Skip to content

Commit d30c522

Browse files
committed
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
1 parent 80df004 commit d30c522

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed

src/cui.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ void show_trace(Line *lines[], int nproc) {
336336
}
337337

338338
/* print the 'unknown' connections, for debugging */
339-
for (auto it = unknowntcp->connections.begin(); it != unknowntcp->connections.end(); ++it) {
340-
std::cout << "Unknown connection: "
341-
<< (*it)->refpacket->gethashstring()
339+
for (auto it = unknowntcp->connections.begin();
340+
it != unknowntcp->connections.end(); ++it) {
341+
std::cout << "Unknown connection: " << (*it)->refpacket->gethashstring()
342342
<< std::endl;
343343
}
344344
}

src/libnethogs.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,12 @@ static void nethogsmonitor_clean_up() {
277277
}
278278

279279
int nethogsmonitor_loop(NethogsMonitorCallback cb, char *filter, int to_ms) {
280-
return nethogsmonitor_loop_devices(cb, filter, 0, NULL, false, to_ms);
280+
return nethogsmonitor_loop_devices(cb, filter, 0, NULL, false, to_ms);
281281
}
282282

283283
int nethogsmonitor_loop_devices(NethogsMonitorCallback cb, char *filter,
284-
int devc, char **devicenames, bool all, int to_ms) {
284+
int devc, char **devicenames, bool all,
285+
int to_ms) {
285286
if (monitor_run_flag) {
286287
return NETHOGS_STATUS_FAILURE;
287288
}

src/libnethogs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ typedef void (*NethogsMonitorCallback)(int action,
6262
*/
6363

6464
NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb,
65-
char *filter,
66-
int to_ms);
65+
char *filter, int to_ms);
6766

6867
/**
6968
* @brief Enter the process monitoring loop and reports updates using the
@@ -87,8 +86,7 @@ NETHOGS_DSO_VISIBLE int nethogsmonitor_loop(NethogsMonitorCallback cb,
8786
NETHOGS_DSO_VISIBLE int nethogsmonitor_loop_devices(NethogsMonitorCallback cb,
8887
char *filter, int devc,
8988
char **devicenames,
90-
bool all,
91-
int to_ms);
89+
bool all, int to_ms);
9290

9391
/**
9492
* @brief Makes the call to nethogsmonitor_loop return.

src/main.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ static void help(bool iserror) {
5151
output << " -C : capture TCP and UDP.\n";
5252
output << " -g : garbage collection period in number of refresh. "
5353
"default is 50.\n";
54-
output << " -b : Short program name. Displays only the program name.\n";
54+
output << " -b : Short program name. Displays only the program "
55+
"name.\n";
5556
output << " -f : EXPERIMENTAL: specify string pcap filter (like "
5657
"tcpdump)."
5758
" This may be removed or changed in a future version.\n";
@@ -150,7 +151,6 @@ int main(int argc, char **argv) {
150151
char *filter = NULL;
151152
int garbage_collection_period = 50;
152153

153-
154154
int opt;
155155
while ((opt = getopt(argc, argv, "Vhxtpsd:v:c:laf:Cbg:P:")) != -1) {
156156
switch (opt) {
@@ -201,7 +201,7 @@ int main(int argc, char **argv) {
201201
garbage_collection_period = (time_t)atoi(optarg);
202202
break;
203203
case 'P':
204-
pidsToWatch.insert((pid_t) atoi(optarg));
204+
pidsToWatch.insert((pid_t)atoi(optarg));
205205
break;
206206
default:
207207
help(true);
@@ -287,10 +287,11 @@ int main(int argc, char **argv) {
287287

288288
if (nb_devices == nb_failed_devices) {
289289
if (geteuid() != 0)
290-
fprintf(stderr, "To run nethogs without being root, you need to enable "
291-
"capabilities on the program (cap_net_admin, cap_net_raw, "
292-
"cap_dac_read_search, cap_sys_ptrace). "
293-
"See the documentation for details.\n");
290+
fprintf(stderr,
291+
"To run nethogs without being root, you need to enable "
292+
"capabilities on the program (cap_net_admin, cap_net_raw, "
293+
"cap_dac_read_search, cap_sys_ptrace). "
294+
"See the documentation for details.\n");
294295
forceExit(false, "Error opening pcap handlers for all devices.\n");
295296
}
296297

src/packet.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,8 @@ bool Packet::match(const Packet *other) const {
300300

301301
bool Packet::matchSource(const Packet *other) const {
302302
return sa_family == other->sa_family && (sport == other->sport) &&
303-
(sa_family == AF_INET
304-
? (sameinaddr(sip, other->sip))
305-
: (samein6addr(sip6, other->sip6)));
303+
(sa_family == AF_INET ? (sameinaddr(sip, other->sip))
304+
: (samein6addr(sip6, other->sip6)));
306305
}
307306

308307
Packet Packet::onlySource() const {
@@ -313,7 +312,7 @@ Packet Packet::onlySource() const {
313312
return p;
314313
}
315314

316-
bool Packet::operator< (const Packet& other) const {
315+
bool Packet::operator<(const Packet &other) const {
317316
if (sa_family != other.sa_family)
318317
return dir < other.sa_family;
319318
/* source address first */

src/packet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Packet {
7474
bool matchSource(const Packet *other) const;
7575
/* returns a copy with destination information stripped (for comparisons) */
7676
Packet onlySource() const;
77-
bool operator< (const Packet& other) const;
77+
bool operator<(const Packet &other) const;
7878
/* returns '1.2.3.4:5-1.2.3.4:6'-style string */
7979
char *gethashstring();
8080

src/process.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
#endif
3131
#include <map>
3232
#include <pwd.h>
33+
#include <signal.h>
3334
#include <stdlib.h>
3435
#include <sys/socket.h>
3536
#include <sys/stat.h>
3637
#include <sys/types.h>
3738
#include <unistd.h>
38-
#include <signal.h>
3939

4040
#include "conninode.h"
4141
#include "inode2prog.h"
@@ -81,7 +81,6 @@ float tokbps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / KB; }
8181
float tombps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / MB; }
8282
float togbps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / GB; }
8383

84-
8584
void process_init() {
8685
unknowntcp = new Process(0, "", "unknown TCP");
8786
processes = new ProcList(unknowntcp, NULL);
@@ -92,7 +91,6 @@ void process_init() {
9291
// unknownip = new Process (0, "", "unknown IP");
9392
// processes = new ProcList (unknownip, processes);
9493
}
95-
9694
}
9795

9896
int Process::getLastPacket() {
@@ -110,7 +108,8 @@ static void sum_active_connections(Process *process_ptr, u_int64_t &sum_sent,
110108
u_int64_t &sum_recv) {
111109
/* walk though all process_ptr process's connections, and sum
112110
* them up */
113-
for (auto it = process_ptr->connections.begin(); it != process_ptr->connections.end(); ) {
111+
for (auto it = process_ptr->connections.begin();
112+
it != process_ptr->connections.end();) {
114113
if ((*it)->getLastPacket() <= curtime.tv_sec - CONNTIMEOUT) {
115114
/* capture sent and received totals before deleting */
116115
process_ptr->sent_by_closed_bytes += (*it)->sumSent;
@@ -158,7 +157,8 @@ void Process::getgbps(float *recvd, float *sent) {
158157
/** get total values for this process */
159158
void Process::gettotal(u_int64_t *recvd, u_int64_t *sent) {
160159
u_int64_t sum_sent = 0, sum_recv = 0;
161-
for (auto it = this->connections.begin(); it != this->connections.end(); ++it) {
160+
for (auto it = this->connections.begin(); it != this->connections.end();
161+
++it) {
162162
Connection *conn = (*it);
163163
sum_sent += conn->sumSent;
164164
sum_recv += conn->sumRecv;
@@ -253,7 +253,8 @@ Process *getProcess(unsigned long inode, const char *devicename) {
253253
if (proc != NULL)
254254
return proc;
255255

256-
if ( !(pidsToWatch.empty()) && pidsToWatch.find(node->pid) == pidsToWatch.end() ) {
256+
if (!(pidsToWatch.empty()) &&
257+
pidsToWatch.find(node->pid) == pidsToWatch.end()) {
257258
return NULL;
258259
}
259260

src/process.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ void check_all_procs();
3636
/* compares Connection pointers by their refpacket */
3737
struct ConnectionComparator {
3838
using is_transparent = void;
39-
bool operator()(const Connection* l, const Connection* r) const {
39+
bool operator()(const Connection *l, const Connection *r) const {
4040
return *l->refpacket < *r->refpacket;
4141
}
42-
bool operator()(const Packet* l, const Connection* r) const {
42+
bool operator()(const Packet *l, const Connection *r) const {
4343
return *l < *r->refpacket;
4444
}
45-
bool operator()(const Connection* l, const Packet* r) const {
45+
bool operator()(const Connection *l, const Packet *r) const {
4646
return *l->refpacket < *r;
4747
}
4848
};
4949

5050
/* ordered set of Connection pointers */
51-
typedef std::multiset<Connection*, ConnectionComparator> ConnList;
51+
typedef std::multiset<Connection *, ConnectionComparator> ConnList;
5252

5353
class Process {
5454
public:

0 commit comments

Comments
 (0)