From 501a379af5982f452af2abf215bb57a415a0f273 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Sun, 5 Feb 2006 17:24:19 +0000 Subject: [PATCH] add tracing to getLocal --- nethogs.cpp | 2 +- packet.cpp | 6 +++++- packet.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/nethogs.cpp b/nethogs.cpp index a033f75..135fb13 100644 --- a/nethogs.cpp +++ b/nethogs.cpp @@ -313,7 +313,7 @@ int main (int argc, char** argv) handle * handles = NULL; device * current_dev = devices; while (current_dev != NULL) { - getLocal(current_dev->name); + getLocal(current_dev->name, tracemode); if ((!tracemode) && (!DEBUG)){ //caption->append(current_dev->name); //caption->append(" "); diff --git a/packet.cpp b/packet.cpp index 94c09cf..7b9aac9 100644 --- a/packet.cpp +++ b/packet.cpp @@ -31,7 +31,7 @@ char * stripspaces (char * input) * uses ioctl to get address of this device, and adds it to the * local_addrs-list. */ -void getLocal (const char *device) +void getLocal (const char *device, bool tracemode) { /* get local IPv4 addresses */ int sock; @@ -48,6 +48,10 @@ void getLocal (const char *device) saddr=(struct sockaddr_in*)&iFreq.ifr_addr; local_addrs = new local_addr (saddr->sin_addr.s_addr, local_addrs); + if (tracemode || DEBUG) { + printf ("Adding local address: %s\n", inet_ntoa(saddr->sin_addr)); + } + /* also get local IPv6 addresses */ FILE * ifinfo = fopen ("/proc/net/if_inet6", "r"); char buffer [500]; diff --git a/packet.h b/packet.h index 85b9570..d040184 100644 --- a/packet.h +++ b/packet.h @@ -17,7 +17,7 @@ enum direction { /* To initialise this module, call getLocal with the currently * monitored device (e.g. "eth0:1") */ -void getLocal (const char *device); +void getLocal (const char *device, bool tracemode); class Packet {