[PATCH 0/3] iptraf-ng cleanups
by Vitezslav Samel
Vitezslav Samel (3):
itrafmon.c: ipmon(): invert one condition to make the source more readable
itrafmon.c: ipmon(): change sequence of if()s into switch()
use integer constant when dealing with integer variables
src/hostmon.c | 2 +-
src/ifstats.c | 4 +-
src/itrafmon.c | 740 ++++++++++++++++++++++++++++----------------------------
src/pktsize.c | 2 +-
src/serv.c | 2 +-
5 files changed, 376 insertions(+), 374 deletions(-)
--
1.7.8.4
11 years, 2 months
[PATCH 0/3] iptraf-ng: get the interface name only when needed
by Vitezslav Samel
Right now on every received packet we get the interface name
on which it arrived. This is not needed and is slow.
Make use of ifindex and retrieve interface name only when needed
(when capturing on "All interfaces").
Vitezslav Samel (3):
get the interface name only when needed
remove unused params from getpacket() and processpacket()
ifstats.c: detstats(): warning cleanup
src/hostmon.c | 19 ++++++++++++--
src/ifaces.c | 38 ++++++++++++++++++++++++++++++
src/ifaces.h | 2 +
src/ifstats.c | 70 ++++++++++++++++++++++++++++---------------------------
src/ifstats.h | 1 +
src/itrafmon.c | 19 ++++++++++++--
src/packet.c | 16 +-----------
src/packet.h | 4 +-
src/pktsize.c | 6 +---
src/serv.c | 5 +--
10 files changed, 117 insertions(+), 63 deletions(-)
--
1.7.8.4
11 years, 2 months
[PATCH 0/2] iptraf-ng: refactor and cleanup detstat()
by Vitezslav Samel
Vitezslav Samel (2):
ifstats.c: detstats(): keyboard event handling cleanup
ifstats.c: refactor detstat()
src/ifstats.c | 361 +++++++++++++++++++--------------------------------------
src/ifstats.h | 80 ++++----------
src/log.c | 110 +++++++++++-------
3 files changed, 204 insertions(+), 347 deletions(-)
--
1.7.8.4
11 years, 2 months
[PATCH 0/2] iptraf-ng: use bind() to lock the socket on interface
by Vitezslav Samel
To reduce number of compares of interface name (to throw away
packets we don't want) lock the socket to the given interface
using bind().
After binding the socket to the interface, we don't need to check
if the incoming packet belongs to the wanted interface, so remove
the check and the parameter.
Vitezslav Samel (2):
use bind() to lock the socket on given interface
remove ifptr parameter from processpacket()
src/hostmon.c | 18 +++++++++++++++---
src/ifstats.c | 29 ++++++++++++++++++++++++-----
src/iptraf-ng-compat.h | 2 ++
src/itrafmon.c | 22 +++++++++++++++++-----
src/packet.c | 9 +--------
src/packet.h | 2 +-
src/pktsize.c | 21 ++++++++++++++++-----
src/serv.c | 19 ++++++++++++++++---
src/wrapper.c | 24 ++++++++++++++++++++++++
9 files changed, 116 insertions(+), 30 deletions(-)
--
1.7.8.4
11 years, 2 months
[PATCH v2 0/2] iptraf-ng: use bind() to lock the socket on interface
by Vitezslav Samel
To reduce number of compares of interface name (to throw away
packets we don't want) lock the socket to the given interface
using bind().
After binding the socket to the interface, we don't need to check
if the incoming packet belongs to the wanted interface, so remove
the check and the parameter.
Vitezslav Samel (2):
use bind() to lock the socket on given interface
remove ifptr parameter from processpacket()
src/hostmon.c | 18 +++++++++++++++---
src/ifstats.c | 29 ++++++++++++++++++++++++-----
src/iptraf-ng-compat.h | 2 ++
src/itrafmon.c | 22 +++++++++++++++++-----
src/packet.c | 9 +--------
src/packet.h | 2 +-
src/pktsize.c | 21 ++++++++++++++++-----
src/serv.c | 19 ++++++++++++++++---
src/wrapper.c | 24 ++++++++++++++++++++++++
9 files changed, 116 insertions(+), 30 deletions(-)
--
1.7.8.4
11 years, 2 months
[PATCH] packet.c: adjustpacket(): support GRE-over-IP tunnels
by Vitezslav Samel
Reported-by: Sergey Popov <admin(a)pinkbyte.ru>
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/packet.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/packet.c b/src/packet.c
index 7d02a56..89e17eb 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -70,6 +70,7 @@ static void adjustpacket(char *tpacket, struct sockaddr_ll *fromaddr,
case ARPHRD_CSLIP6:
case ARPHRD_TUNNEL:
case ARPHRD_NONE:
+ case ARPHRD_IPGRE:
*packet = tpacket;
break;
case ARPHRD_FRAD:
--
1.7.8.4
11 years, 2 months
iptraf-ng-1.1.1 counters problem
by Sergey Popov
iptraf-ng-1.1.1 does not show traffic on some types of interfaces.
Older(1.0.2) version did not show traffic on tun devices under Linux,
new(1.1.1) also does not show it on ppp devices.
Which information could i provide to fix this issue?
My system: Gentoo Linux
Arch: x86_64(but tried on x86 too)
11 years, 2 months
[PATCH] Change bits/sec (bytes/sec) to kbps (kBps)
by Vitezslav Samel
Make the units shorter to have more room for interface name
in some windows.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/deskman.c | 2 +-
src/hostmon.c | 6 +---
src/ifstats.c | 53 +++++++++++++++++++++++++----------------------
src/iptraf-ng-compat.h | 2 +-
src/itrafmon.c | 5 +---
src/log.c | 47 ++++++++++++++++++------------------------
src/serv.c | 6 +---
7 files changed, 55 insertions(+), 66 deletions(-)
diff --git a/src/deskman.c b/src/deskman.c
index e137b39..91ac4af 100644
--- a/src/deskman.c
+++ b/src/deskman.c
@@ -198,7 +198,7 @@ void printlargenum(unsigned long long i, WINDOW * win)
if (i < 100000000) /* less than 100 million */
wprintw(win, "%9llu", i);
else if (i < 1000000000) /* less than 1 billion */
- wprintw(win, "%8lluK", i / 1000);
+ wprintw(win, "%8lluk", i / 1000);
else if (i < 1000000000000ULL) /* less than 1 trillion */
wprintw(win, "%8lluM", i / 1000000);
else if (i < 1000000000000000ULL) /* less than 1000 trillion */
diff --git a/src/hostmon.c b/src/hostmon.c
index 53d1d8e..4c18dc6 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -96,10 +96,8 @@ void initethtab(struct ethtab *table, int unit)
wmove(table->borderwin, LINES - 3, 40);
- char *unitstring = dispmode(unit);
-
- wprintw(table->borderwin, " InRate and OutRate are in %s/sec ",
- unitstring);
+ wprintw(table->borderwin, " InRate and OutRate are in %s ",
+ dispmode(unit));
wattrset(table->tabwin, STDATTR);
tx_colorwin(table->tabwin);
diff --git a/src/ifstats.c b/src/ifstats.c
index 0a4431b..dbd2a68 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -219,17 +219,17 @@ void updaterates(struct iftab *table, int unit, time_t starttime, time_t now,
wattrset(table->statwin, HIGHATTR);
do {
- wmove(table->statwin, ptmp->index - idx, 60 * COLS / 80);
+ wmove(table->statwin, ptmp->index - idx, 64 * COLS / 80);
if (unit == KBITS) {
ptmp->rate =
((float) (ptmp->spanbr * 8 / 1000)) /
((float) (now - starttime));
- wprintw(table->statwin, "%8.2f kbits/sec", ptmp->rate);
+ wprintw(table->statwin, "%8.2f %s", ptmp->rate, dispmode(unit));
} else {
ptmp->rate =
((float) (ptmp->spanbr / 1024)) /
((float) (now - starttime));
- wprintw(table->statwin, "%8.2f kbytes/sec", ptmp->rate);
+ wprintw(table->statwin, "%8.2f %s", ptmp->rate, dispmode(unit));
}
if (ptmp->rate > ptmp->peakrate)
@@ -253,16 +253,16 @@ void printifentry(struct iflist *ptmp, WINDOW * win, unsigned int idx)
wmove(win, target_row, 1);
wprintw(win, "%s", ptmp->ifname);
wattrset(win, HIGHATTR);
- wmove(win, target_row, 9 * COLS / 80);
+ wmove(win, target_row, 14 * COLS / 80);
printlargenum(ptmp->total, win);
- wmove(win, target_row, 19 * COLS / 80);
+ wmove(win, target_row, 24 * COLS / 80);
printlargenum(ptmp->iptotal, win);
- wmove(win, target_row, 29 * COLS / 80);
+ wmove(win, target_row, 34 * COLS / 80);
printlargenum(ptmp->ip6total, win);
- wmove(win, target_row, 39 * COLS / 80);
+ wmove(win, target_row, 44 * COLS / 80);
printlargenum(ptmp->noniptotal, win);
- wmove(win, target_row, 49 * COLS / 80);
- wprintw(win, "%8lu", ptmp->badtotal);
+ wmove(win, target_row, 53 * COLS / 80);
+ wprintw(win, "%7lu", ptmp->badtotal);
}
void preparescreen(struct iftab *table)
@@ -289,17 +289,21 @@ void labelstats(WINDOW * win)
{
wmove(win, 0, 1);
wprintw(win, " Iface ");
- wmove(win, 0, 12 * COLS / 80);
+ /* 14, 24, 34, ... from printifentry() */
+ /* 10 = strlen(printed number); from printlargenum() */
+ /* 7 = strlen(" Total ") */
+ /* 1 = align the string on 'l' from " Total " */
+ wmove(win, 0, (14 * COLS / 80) + 10 - 7 + 1);
wprintw(win, " Total ");
- wmove(win, 0, 22 * COLS / 80);
+ wmove(win, 0, (24 * COLS / 80) + 10 - 6 + 1);
wprintw(win, " IPv4 ");
- wmove(win, 0, 32 * COLS / 80);
+ wmove(win, 0, (34 * COLS / 80) + 10 - 6 + 1);
wprintw(win, " IPv6 ");
- wmove(win, 0, 42 * COLS / 80);
+ wmove(win, 0, (44 * COLS / 80) + 10 - 7 + 1);
wprintw(win, " NonIP ");
- wmove(win, 0, 52 * COLS / 80);
+ wmove(win, 0, (53 * COLS / 80) + 8 - 7 + 1);
wprintw(win, " BadIP ");
- wmove(win, 0, 65 * COLS / 80);
+ wmove(win, 0, (64 * COLS / 80) + 14 - 10);
wprintw(win, " Activity ");
}
@@ -880,7 +884,6 @@ void detstats(char *iface, const struct OPTIONS *options, int facilitytime,
//isdnfd = -1;
exitloop = 0;
- char *unitstring = dispmode(options->actmode);
/*
* Data-gathering loop
@@ -929,15 +932,15 @@ void detstats(char *iface, const struct OPTIONS *options, int facilitytime,
starttime = now;
wattrset(statwin, HIGHATTR);
- mvwprintw(statwin, 14, 19, "%8.1f %s/sec", activity,
- unitstring);
- mvwprintw(statwin, 15, 19, "%8.1f packets/sec", pps);
- mvwprintw(statwin, 17, 19, "%8.1f %s/sec", activity_in,
- unitstring);
- mvwprintw(statwin, 18, 19, "%8.1f packets/sec", pps_in);
- mvwprintw(statwin, 20, 19, "%8.1f %s/sec", activity_out,
- unitstring);
- mvwprintw(statwin, 21, 19, "%8.1f packets/sec",
+ mvwprintw(statwin, 14, 19, "%8.1f %s", activity,
+ dispmode(options->actmode));
+ mvwprintw(statwin, 15, 19, "%8.1f pps", pps);
+ mvwprintw(statwin, 17, 19, "%8.1f %s", activity_in,
+ dispmode(options->actmode));
+ mvwprintw(statwin, 18, 19, "%8.1f pps", pps_in);
+ mvwprintw(statwin, 20, 19, "%8.1f %s", activity_out,
+ dispmode(options->actmode));
+ mvwprintw(statwin, 21, 19, "%8.1f pps",
pps_out);
if (activity > peakactivity)
diff --git a/src/iptraf-ng-compat.h b/src/iptraf-ng-compat.h
index 197ee58..28af383 100644
--- a/src/iptraf-ng-compat.h
+++ b/src/iptraf-ng-compat.h
@@ -83,7 +83,7 @@
#define KBITS 0
#define dispmode(mode) \
- ((mode) == KBITS) ? "kbits": "kbytes";
+ (((mode) == KBITS) ? "kbps": "kBps")
#define NORETURN __attribute__((noreturn))
diff --git a/src/itrafmon.c b/src/itrafmon.c
index b841e20..4036b84 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -543,24 +543,21 @@ void update_flowrate(WINDOW * win, struct tcptableent *entry, time_t now,
int *cleared, int mode)
{
float rate = 0;
- char units[10];
wattrset(win, IPSTATLABELATTR);
mvwprintw(win, 0, COLS * 47 / 80, "TCP flow rate: ");
wattrset(win, IPSTATATTR);
if (mode == KBITS) {
- strcpy(units, "kbits/s");
rate =
(float) (entry->spanbr * 8 / 1000) / (float) (now -
entry->
starttime);
} else {
- strcpy(units, "kbytes/s");
rate =
(float) (entry->spanbr / 1024) / (float) (now -
entry->starttime);
}
- mvwprintw(win, 0, COLS * 50 / 80 + 13, "%8.2f %s", rate, units);
+ mvwprintw(win, 0, COLS * 53 / 80 + 13, "%8.2f %s", rate, dispmode(mode));
entry->spanbr = 0;
*cleared = 0;
}
diff --git a/src/log.c b/src/log.c
index 115bab3..075899e 100644
--- a/src/log.c
+++ b/src/log.c
@@ -253,22 +253,20 @@ void writegstatlog(struct iftab *table, int unit, unsigned long nsecs,
ptmp->noniptotal, ptmp->badtotal);
if (nsecs > 5) {
- char *unitstring = dispmode(unit);
-
if (unit == KBITS) {
- fprintf(fd, ", average activity %.2f %s/s",
+ fprintf(fd, ", average activity %.2f %s",
(float) (ptmp->br * 8 / 1000) /
- (float) nsecs, unitstring);
+ (float) nsecs, dispmode(unit));
} else {
- fprintf(fd, ", average activity %.2f %s/s",
+ fprintf(fd, ", average activity %.2f %s",
(float) (ptmp->br / 1024) /
- (float) nsecs, unitstring);
+ (float) nsecs, dispmode(unit));
}
- fprintf(fd, ", peak activity %.2f %s/s", ptmp->peakrate,
- unitstring);
- fprintf(fd, ", last 5-second activity %.2f %s/s",
- ptmp->rate, unitstring);
+ fprintf(fd, ", peak activity %.2f %s", ptmp->peakrate,
+ dispmode(unit));
+ fprintf(fd, ", last 5-second activity %.2f %s",
+ ptmp->rate, dispmode(unit));
}
fprintf(fd, "\n");
@@ -285,7 +283,6 @@ void writedstatlog(char *ifname, int unit, float activity, float pps,
struct iftotals *ts, unsigned long nsecs, FILE * fd)
{
char atime[TIME_TARGET_MAX];
- char *unitstring = dispmode(unit);
genatime(time((time_t *) NULL), atime);
@@ -374,12 +371,12 @@ void writedstatlog(char *ifname, int unit, float activity, float pps,
}
fprintf(fd,
- "\nPeak total activity: %.2f %s/s, %.2f packets/s\n",
- peakactivity, unitstring, peakpps);
- fprintf(fd, "Peak incoming rate: %.2f %s/s, %.2f packets/s\n",
- peakactivity_in, unitstring, peakpps_in);
- fprintf(fd, "Peak outgoing rate: %.2f %s/s, %.2f packets/s\n\n",
- peakactivity_out, unitstring, peakpps_out);
+ "\nPeak total activity: %.2f %s, %.2f packets/s\n",
+ peakactivity, dispmode(unit), peakpps);
+ fprintf(fd, "Peak incoming rate: %.2f %s, %.2f packets/s\n",
+ peakactivity_in, dispmode(unit), peakpps_in);
+ fprintf(fd, "Peak outgoing rate: %.2f %s, %.2f packets/s\n\n",
+ peakactivity_out, dispmode(unit), peakpps_out);
}
fprintf(fd, "IP checksum errors: %lu\n\n", ts->badtotal);
fprintf(fd, "Running time: %lu seconds\n", nsecs);
@@ -394,8 +391,6 @@ void writeutslog(struct portlistent *list, unsigned long nsecs, int units,
float inrate, outrate, totalrate;
time_t now = time(NULL);
- char *unitstring = dispmode(units);
-
genatime(time((time_t *) NULL), atime);
fprintf(fd, "\n*** TCP/UDP traffic log, generated %s\n\n", atime);
@@ -436,19 +431,19 @@ void writeutslog(struct portlistent *list, unsigned long nsecs, int units,
ptmp->bcount);
if (totalrate >= 0.0)
- fprintf(fd, ", %.2f %s/s", totalrate, unitstring);
+ fprintf(fd, ", %.2f %s", totalrate, dispmode(units));
fprintf(fd, "; %llu packets, %llu bytes incoming", ptmp->icount,
ptmp->ibcount);
if (inrate >= 0.0)
- fprintf(fd, ", %.2f %s/s", inrate, unitstring);
+ fprintf(fd, ", %.2f %s", inrate, dispmode(units));
fprintf(fd, "; %llu packets, %llu bytes outgoing", ptmp->ocount,
ptmp->obcount);
if (outrate >= 0.0)
- fprintf(fd, ", %.2f %s/s", outrate, unitstring);
+ fprintf(fd, ", %.2f %s", outrate, dispmode(units));
fprintf(fd, "\n\n");
ptmp = ptmp->next_entry;
@@ -464,8 +459,6 @@ void writeethlog(struct ethtabent *list, int unit, unsigned long nsecs,
char atime[TIME_TARGET_MAX];
struct ethtabent *ptmp = list;
- char *unitstring = dispmode(unit);
-
genatime(time((time_t *) NULL), atime);
fprintf(fd, "\n*** LAN traffic log, generated %s\n\n", atime);
@@ -516,9 +509,9 @@ void writeethlog(struct ethtabent *list, int unit, unsigned long nsecs,
if (nsecs > 5)
fprintf(fd,
- "\tLast 5-second rates: %.2f %s/s incoming, %.2f %s/s outgoing\n",
- ptmp->un.figs.inrate, unitstring,
- ptmp->un.figs.outrate, unitstring);
+ "\tLast 5-second rates: %.2f %s incoming, %.2f %s outgoing\n",
+ ptmp->un.figs.inrate, dispmode(unit),
+ ptmp->un.figs.outrate, dispmode(unit));
}
ptmp = ptmp->next_entry;
diff --git a/src/serv.c b/src/serv.c
index f7fcb7d..3d8d682 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -671,12 +671,10 @@ void update_serv_rates(struct portlist *list, WINDOW * win, int actmode,
starttime);
}
- char *act_unit = dispmode(actmode);
-
wattrset(win, IPSTATLABELATTR);
mvwprintw(win, 0, 1,
- "Protocol data rates (%s/s): in out total",
- act_unit);
+ "Protocol data rates (%s): in out total",
+ dispmode(actmode));
wattrset(win, IPSTATATTR);
mvwprintw(win, 0, 31, "%10.2f", inrate);
mvwprintw(win, 0, 46, "%10.2f", outrate);
--
1.7.8.4
11 years, 2 months
[PATCH 0/3] iptraf-ng: fix: ETH description printing
by Vitezslav Samel
Fix the bug Danilo Câmara reported on iptraf-ng mailing list.
Vitezslav Samel (3):
landesc.c: check_mac_addr(): make room for trailing '\0'
hostmon.c: convmacaddr(): fix MAC addr to ASCII conversion
hostmon.c: addethentry(): make the MAC addr description searching
case insensitive
src/hostmon.c | 19 +++++++++----------
src/hostmon.h | 2 +-
src/landesc.c | 2 +-
3 files changed, 11 insertions(+), 12 deletions(-)
--
1.7.8.4
11 years, 2 months
Ethernet host descriptions
by Danilo Câmara
Hi
I have my Ethernet host descriptions listed in
"Configure.../Ethernet/PLIP host descriptions..." but I can't have
them to show in "LAN station monitor". In the original iptraf they
work fine. I noticed that iptraf-ng changed the configuration to
include ":" (colon) in the MAC address input.
I'm running iptraf-ng-1.1.1-2.el6.x86_64 (Scientific Linux 6.2)
Thanks
--
--
Danilo Câmara
11 years, 2 months