diff --git a/conninode.cpp b/conninode.cpp index b3e7b14..6cd7ddb 100644 --- a/conninode.cpp +++ b/conninode.cpp @@ -1,4 +1,4 @@ -/* +/* * conninode.cpp * * Copyright (c) 2008,2009 Arnout Engelen @@ -35,7 +35,6 @@ #endif extern local_addr * local_addrs; - /* * connection-inode table. takes information from /proc/net/tcp. * key contains source ip, source port, destination ip, destination @@ -47,8 +46,8 @@ std::map conninode; /* * parses a /proc/net/tcp-line of the form: * sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode - * 10: 020310AC:1770 9DD8A9C3:A525 01 00000000:00000000 00:00000000 00000000 0 0 2119 1 c0f4f0c0 206 40 10 3 -1 - * 11: 020310AC:0404 936B2ECF:0747 01 00000000:00000000 00:00000000 00000000 1000 0 2109 1 c0f4fc00 368 40 20 2 -1 + * 10: 020310AC:1770 9DD8A9C3:A525 01 00000000:00000000 00:00000000 00000000 0 0 2119 1 c0f4f0c0 206 40 10 3 -1 + * 11: 020310AC:0404 936B2ECF:0747 01 00000000:00000000 00:00000000 00000000 1000 0 2109 1 c0f4fc00 368 40 20 2 -1 * * and of the form: * 2: 0000000000000000FFFF0000020310AC:0016 0000000000000000FFFF00009DD8A9C3:A526 01 00000000:00000000 02:000A7214 00000000 0 0 2525 2 c732eca0 201 40 1 2 -1 @@ -76,9 +75,9 @@ void addtoconninode (char * buffer) fprintf(stderr,"Unexpected buffer: '%s'\n",buffer); exit(0); } - + if (inode == 0) { - /* connection is in TIME_WAIT state. We rely on + /* connection is in TIME_WAIT state. We rely on * the old data still in the table. */ return; } @@ -88,7 +87,7 @@ void addtoconninode (char * buffer) /* this is an IPv6-style row */ /* Demangle what the kernel gives us */ - sscanf(local_addr, "%08X%08X%08X%08X", + sscanf(local_addr, "%08X%08X%08X%08X", &in6_local.s6_addr32[0], &in6_local.s6_addr32[1], &in6_local.s6_addr32[2], &in6_local.s6_addr32[3]); sscanf(rem_addr, "%08X%08X%08X%08X", @@ -141,14 +140,14 @@ void addtoconninode (char * buffer) /* workaround: sometimes, when a connection is actually from 172.16.3.1 to * 172.16.3.3, packages arrive from 195.169.216.157 to 172.16.3.3, where - * 172.16.3.1 and 195.169.216.157 are the local addresses of different + * 172.16.3.1 and 195.169.216.157 are the local addresses of different * interfaces */ - struct local_addr * current_local_addr = local_addrs; - while (current_local_addr != NULL) { + for (class local_addr *current_local_addr = local_addrs; + current_local_addr != NULL; + current_local_addr = current_local_addr->next) { /* TODO maybe only add the ones with the same sa_family */ snprintf(hashkey, HASHKEYSIZE * sizeof(char), "%s:%d-%s:%d", current_local_addr->string, local_port, remote_string, rem_port); conninode[hashkey] = inode; - current_local_addr = current_local_addr->next; } free (hashkey); free (remote_string); @@ -162,7 +161,7 @@ int addprocinfo (const char * filename) { if (procinfo == NULL) return 0; - + fgets(buffer, sizeof(buffer), procinfo); do diff --git a/nethogs.h b/nethogs.h index 6de37fe..28b3fcd 100644 --- a/nethogs.h +++ b/nethogs.h @@ -1,4 +1,4 @@ -/* +/* * nethogs.h * * Copyright (c) 2004-2006,2008,2010 Arnout Engelen @@ -73,7 +73,7 @@ #define VIEWMODE_TOTAL_B 2 #define VIEWMODE_TOTAL_MB 3 #define VIEWMODE_COUNT 4 - + #define NORETURN __attribute__ ((__noreturn__)) void forceExit(bool success, const char *msg, ...) NORETURN;