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