fixes #29 - change all sent/recv counters from int32 to int64 to prevent wraparound

This commit is contained in:
Jason Antman
2017-08-27 10:32:16 -04:00
parent e5455240c9
commit 2a2ce7c909
7 changed files with 26 additions and 26 deletions

View File

@@ -51,8 +51,8 @@ void PackList::add(Packet *p) {
}
/* sums up the total bytes used and removes 'old' packets */
u_int32_t PackList::sumanddel(timeval t) {
u_int32_t retval = 0;
u_int64_t PackList::sumanddel(timeval t) {
u_int64_t retval = 0;
PackListNode *current = content;
PackListNode *previous = NULL;
@@ -206,7 +206,7 @@ Connection *findConnection(Packet *packet) {
* Returns sum of sent packages (by address)
* sum of received packages (by address)
*/
void Connection::sumanddel(timeval t, u_int32_t *recv, u_int32_t *sent) {
void Connection::sumanddel(timeval t, u_int64_t *recv, u_int64_t *sent) {
(*sent) = (*recv) = 0;
*sent = sent_packets->sumanddel(t);

View File

@@ -53,7 +53,7 @@ public:
}
/* sums up the total bytes used and removes 'old' packets */
u_int32_t sumanddel(timeval t);
u_int64_t sumanddel(timeval t);
/* calling code may delete packet */
void add(Packet *p);
@@ -83,15 +83,15 @@ public:
/* sums up the total bytes used
* and removes 'old' packets. */
void sumanddel(timeval curtime, u_int32_t *recv, u_int32_t *sent);
void sumanddel(timeval curtime, u_int64_t *recv, u_int64_t *sent);
/* for checking if a packet is part of this connection */
/* the reference packet is always *outgoing*. */
Packet *refpacket;
/* total sum or sent/received bytes */
u_int32_t sumSent;
u_int32_t sumRecv;
u_int64_t sumSent;
u_int64_t sumRecv;
private:
PackList *sent_packets;

View File

@@ -204,8 +204,8 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb) {
// continue;
} else {
const u_int32_t uid = curproc->getVal()->getUid();
u_int32_t sent_bytes;
u_int32_t recv_bytes;
u_int64_t sent_bytes;
u_int64_t recv_bytes;
float sent_kbs;
float recv_kbs;
curproc->getVal()->getkbps(&recv_kbs, &sent_kbs);

View File

@@ -24,8 +24,8 @@ typedef struct NethogsMonitorRecord {
int pid;
uint32_t uid;
const char *device_name;
uint32_t sent_bytes;
uint32_t recv_bytes;
uint64_t sent_bytes;
uint64_t recv_bytes;
float sent_kbs;
float recv_kbs;
} NethogsMonitorRecord;

View File

@@ -65,10 +65,10 @@ Process *unknownudp;
Process *unknownip;
ProcList *processes;
float tomb(u_int32_t bytes) { return ((double)bytes) / 1024 / 1024; }
float tokb(u_int32_t bytes) { return ((double)bytes) / 1024; }
float tomb(u_int64_t bytes) { return ((double)bytes) / 1024 / 1024; }
float tokb(u_int64_t bytes) { return ((double)bytes) / 1024; }
float tokbps(u_int32_t bytes) { return (((double)bytes) / PERIOD) / 1024; }
float tokbps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / 1024; }
void process_init() {
unknowntcp = new Process(0, "", "unknown TCP");
@@ -94,7 +94,7 @@ int Process::getLastPacket() {
/** Get the kb/s values for this process */
void Process::getkbps(float *recvd, float *sent) {
u_int32_t sum_sent = 0, sum_recv = 0;
u_int64_t sum_sent = 0, sum_recv = 0;
/* walk though all this process's connections, and sum
* them up */
@@ -116,7 +116,7 @@ void Process::getkbps(float *recvd, float *sent) {
delete (todelete);
delete (conn_todelete);
} else {
u_int32_t sent = 0, recv = 0;
u_int64_t sent = 0, recv = 0;
curconn->getVal()->sumanddel(curtime, &recv, &sent);
sum_sent += sent;
sum_recv += recv;
@@ -129,8 +129,8 @@ void Process::getkbps(float *recvd, float *sent) {
}
/** get total values for this process */
void Process::gettotal(u_int32_t *recvd, u_int32_t *sent) {
u_int32_t sum_sent = 0, sum_recv = 0;
void Process::gettotal(u_int64_t *recvd, u_int64_t *sent) {
u_int64_t sum_sent = 0, sum_recv = 0;
ConnList *curconn = this->connections;
while (curconn != NULL) {
Connection *conn = curconn->getVal();
@@ -145,7 +145,7 @@ void Process::gettotal(u_int32_t *recvd, u_int32_t *sent) {
}
void Process::gettotalmb(float *recvd, float *sent) {
u_int32_t sum_sent = 0, sum_recv = 0;
u_int64_t sum_sent = 0, sum_recv = 0;
gettotal(&sum_recv, &sum_sent);
*recvd = tomb(sum_recv);
*sent = tomb(sum_sent);
@@ -153,14 +153,14 @@ void Process::gettotalmb(float *recvd, float *sent) {
/** get total values for this process */
void Process::gettotalkb(float *recvd, float *sent) {
u_int32_t sum_sent = 0, sum_recv = 0;
u_int64_t sum_sent = 0, sum_recv = 0;
gettotal(&sum_recv, &sum_sent);
*recvd = tokb(sum_recv);
*sent = tokb(sum_sent);
}
void Process::gettotalb(float *recvd, float *sent) {
u_int32_t sum_sent = 0, sum_recv = 0;
u_int64_t sum_sent = 0, sum_recv = 0;
gettotal(&sum_recv, &sum_sent);
// std::cout << "Total sent: " << sum_sent << std::endl;
*sent = sum_sent;

View File

@@ -91,7 +91,7 @@ public:
}
int getLastPacket();
void gettotal(u_int32_t *recvd, u_int32_t *sent);
void gettotal(u_int64_t *recvd, u_int64_t *sent);
void getkbps(float *recvd, float *sent);
void gettotalmb(float *recvd, float *sent);
void gettotalkb(float *recvd, float *sent);
@@ -101,8 +101,8 @@ public:
char *cmdline;
const char *devicename;
int pid;
u_int32_t sent_by_closed_bytes;
u_int32_t rcvd_by_closed_bytes;
u_int64_t sent_by_closed_bytes;
u_int64_t rcvd_by_closed_bytes;
ConnList *connections;
uid_t getUid() { return uid; }