Commit 9addd978 by Paul Warren

Option to display packet counts - Frédéric Perrin <fperrin@brocade.com>

Add a "-u unit" CLI option, as well as a "bandwidth-unit" configuration
file option. With "-u packets", traffic is accounted using packets per
second; the other options are "-u bits" and "-u bytes".

"-B" is still recognized as synonym to "-u bytes".

The default is "-u bits", keeping the current behaviour of iftop
(everything is in bits/s, except the cumulative totals).
1 parent eb087b0c
Pipeline #69 skipped in 0 seconds
...@@ -30,7 +30,8 @@ char * config_directives[] = { ...@@ -30,7 +30,8 @@ char * config_directives[] = {
"promiscuous", "promiscuous",
"hide-source", "hide-source",
"hide-destination", "hide-destination",
"use-bytes", "use-bytes",
"bandwidth-unit",
"sort", "sort",
"line-display", "line-display",
"show-totals", "show-totals",
......
...@@ -11,7 +11,7 @@ iftop - display bandwidth usage on an interface by host ...@@ -11,7 +11,7 @@ iftop - display bandwidth usage on an interface by host
.SH SYNOPSIS .SH SYNOPSIS
\fBiftop\fP \fB-h\fP | \fBiftop\fP \fB-h\fP |
[\fB-nNpblBP\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-F\fP \fInet\fP/\fImask\fP] [\fB-nNpblP\fP] [\fB-u\fP \fIunit\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-F\fP \fInet\fP/\fImask\fP]
[\fB-G\fP \fInet6\fP/\fImask6\fP] [\fB-G\fP \fInet6\fP/\fImask6\fP]
.SH DESCRIPTION .SH DESCRIPTION
\fBiftop\fP listens to network traffic on a named \fIinterface\fP, or on the \fBiftop\fP listens to network traffic on a named \fIinterface\fP, or on the
...@@ -75,8 +75,11 @@ Don't display bar graphs of traffic. ...@@ -75,8 +75,11 @@ Don't display bar graphs of traffic.
\fB-m\fP \fIlimit\fP \fB-m\fP \fIlimit\fP
Set the upper limit for the bandwidth scale. Specified as a number with a 'K', 'M' or 'G' suffix. Set the upper limit for the bandwidth scale. Specified as a number with a 'K', 'M' or 'G' suffix.
.TP .TP
\fB-u\fP \fIbits\fP|\fIbytes\fP|\fIpackets\fP
Display bandwidth rates in the given unit (per second).
.TP
\fB-B\fP \fB-B\fP
Display bandwidth rates in bytes/sec rather than bits/sec. Synonym for \fB-u\fP \fIbits\fP.
.TP .TP
\fB-i\fP \fIinterface\fP \fB-i\fP \fIinterface\fP
Listen to packets on \fIinterface\fP. Listen to packets on \fIinterface\fP.
...@@ -236,8 +239,11 @@ Hides source host names. ...@@ -236,8 +239,11 @@ Hides source host names.
\fBhide-destination:\fP \fI(yes|no)\fP \fBhide-destination:\fP \fI(yes|no)\fP
Hides destination host names. Hides destination host names.
.TP .TP
\fBbandwidth-unit:\fP \fI(bits|bytes|packets)\fP
Use the specified unit for bandwidth display. The default is bits.
.TP
\fBuse-bytes:\fP \fI(yes|no)\fP \fBuse-bytes:\fP \fI(yes|no)\fP
Use bytes for bandwidth display, rather than bits. \fBuse-bytes: yes\fP is a synonym of \fBbandwidth-unit: packets\fP.
.TP .TP
\fBsort:\fP \fI(2s|10s|40s|source|destination)\fP \fBsort:\fP \fI(2s|10s|40s|source|destination)\fP
Sets which column is used to sort the display. Sets which column is used to sort the display.
......
...@@ -431,14 +431,22 @@ static void handle_ip_packet(struct ip* iptr, int hw_dir) ...@@ -431,14 +431,22 @@ static void handle_ip_packet(struct ip* iptr, int hw_dir)
} }
/* Do accounting. */ /* Do accounting. */
switch (IP_V(iptr)) { switch (options.bandwidth_unit) {
case 4: case OPTION_BW_BITS:
len = ntohs(iptr->ip_len); case OPTION_BW_BYTES:
break; switch (IP_V(iptr)) {
case 6: case 4:
len = ntohs(ip6tr->ip6_plen) + 40; len = ntohs(iptr->ip_len);
default: break;
break; case 6:
len = ntohs(ip6tr->ip6_plen) + 40;
default:
break;
}
break;
case OPTION_BW_PKTS:
len = 1;
break;
} }
/* Update record */ /* Update record */
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
options_t options; options_t options;
char optstr[] = "+i:f:nNF:G:lhpbBPm:c:s:tL:o:"; char optstr[] = "+i:f:nNF:G:lhpbBu:Pm:c:s:tL:o:";
/* Global options. */ /* Global options. */
...@@ -75,6 +75,13 @@ config_enumeration_type showports_enumeration[] = { ...@@ -75,6 +75,13 @@ config_enumeration_type showports_enumeration[] = {
{ NULL, -1 } { NULL, -1 }
}; };
config_enumeration_type bandwidth_unit_enumeration[] = {
{ "bits", OPTION_BW_BITS },
{ "bytes", OPTION_BW_BYTES },
{ "packets", OPTION_BW_PKTS },
{ NULL, -1 }
};
static int is_bad_interface_name(char *i) { static int is_bad_interface_name(char *i) {
char **p; char **p;
for (p = bad_interface_names; *p; ++p) for (p = bad_interface_names; *p; ++p)
...@@ -145,7 +152,7 @@ void options_set_defaults() { ...@@ -145,7 +152,7 @@ void options_set_defaults() {
options.aggregate_dest = 0; options.aggregate_dest = 0;
options.paused = 0; options.paused = 0;
options.showhelp = 0; options.showhelp = 0;
options.bandwidth_in_bytes = 0; options.bandwidth_unit = OPTION_BW_BITS;
options.sort = OPTION_SORT_DIV2; options.sort = OPTION_SORT_DIV2;
options.screenfilter = NULL; options.screenfilter = NULL;
options.freezeorder = 0; options.freezeorder = 0;
...@@ -188,7 +195,8 @@ static void usage(FILE *fp) { ...@@ -188,7 +195,8 @@ static void usage(FILE *fp) {
" -p run in promiscuous mode (show traffic between other\n" " -p run in promiscuous mode (show traffic between other\n"
" hosts on the same network segment)\n" " hosts on the same network segment)\n"
" -b don't display a bar graph of traffic\n" " -b don't display a bar graph of traffic\n"
" -B Display bandwidth in bytes\n" " -B display bandwidth in bytes\n"
" -a display bandwidth in packets\n"
" -i interface listen on named interface\n" " -i interface listen on named interface\n"
" -f filter code use filter code to select packets to count\n" " -f filter code use filter code to select packets to count\n"
" (default: none, but only IP packets are counted)\n" " (default: none, but only IP packets are counted)\n"
...@@ -271,9 +279,13 @@ void options_read_args(int argc, char **argv) { ...@@ -271,9 +279,13 @@ void options_read_args(int argc, char **argv) {
break; break;
case 'B': case 'B':
config_set_string("use-bytes", "true"); config_set_string("bandwidth-unit", "bytes");
break; break;
case 'u':
config_set_string("bandwidth-unit", optarg);
break;
case 's': case 's':
config_set_string("timed-output", optarg); config_set_string("timed-output", optarg);
break; break;
...@@ -370,6 +382,23 @@ int options_config_get_promiscuous() { ...@@ -370,6 +382,23 @@ int options_config_get_promiscuous() {
return 0; return 0;
} }
int options_config_get_bw_unit() {
int i;
if (options_config_get_enum("bandwidth-unit", bandwidth_unit_enumeration,
(int*)&options.bandwidth_unit))
return 1;
/* compatibility with use-bytes / -B */
if (options_config_get_bool("use-bytes", &i)) {
if (i)
options.bandwidth_unit = OPTION_BW_BYTES;
else
options.bandwidth_unit = OPTION_BW_BITS;
return 1;
}
return 0;
}
int options_config_get_bw_rate(char *directive, long long* result) { int options_config_get_bw_rate(char *directive, long long* result) {
char* units; char* units;
long long mult = 1; long long mult = 1;
...@@ -544,7 +573,7 @@ void options_make() { ...@@ -544,7 +573,7 @@ void options_make() {
options_config_get_promiscuous(); options_config_get_promiscuous();
options_config_get_bool("hide-source", &options.aggregate_src); options_config_get_bool("hide-source", &options.aggregate_src);
options_config_get_bool("hide-destination", &options.aggregate_dest); options_config_get_bool("hide-destination", &options.aggregate_dest);
options_config_get_bool("use-bytes", &options.bandwidth_in_bytes); options_config_get_bw_unit();
options_config_get_enum("sort", sort_enumeration, (int*)&options.sort); options_config_get_enum("sort", sort_enumeration, (int*)&options.sort);
options_config_get_enum("line-display", linedisplay_enumeration, (int*)&options.linedisplay); options_config_get_enum("line-display", linedisplay_enumeration, (int*)&options.linedisplay);
options_config_get_bool("show-totals", &options.show_totals); options_config_get_bool("show-totals", &options.show_totals);
......
...@@ -34,6 +34,12 @@ typedef enum { ...@@ -34,6 +34,12 @@ typedef enum {
OPTION_LINEDISPLAY_ONE_LINE_SENT OPTION_LINEDISPLAY_ONE_LINE_SENT
} option_linedisplay_t; } option_linedisplay_t;
typedef enum {
OPTION_BW_BITS,
OPTION_BW_BYTES,
OPTION_BW_PKTS,
} option_bw_unit_t;
/* /*
* This structure has to be defined in the same order as the config * This structure has to be defined in the same order as the config
* directives in cfgfile.c. Clearly this is EBW. * directives in cfgfile.c. Clearly this is EBW.
...@@ -59,7 +65,7 @@ typedef struct { ...@@ -59,7 +65,7 @@ typedef struct {
int timed_output; int timed_output;
int no_curses; int no_curses;
int num_lines; int num_lines;
int bandwidth_in_bytes; option_bw_unit_t bandwidth_unit;
option_sort_t sort; option_sort_t sort;
int bar_interval; int bar_interval;
......
...@@ -87,7 +87,7 @@ void tui_print() { ...@@ -87,7 +87,7 @@ void tui_print() {
/* Send rate per connection */ /* Send rate per connection */
printf("%4d %s%s", l, host1, " =>"); printf("%4d %s%s", l, host1, " =>");
for(j = 0; j < HISTORY_DIVISIONS; j++) { for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_in_bytes); readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10); printf(" %10s", buf0_10);
} }
/* Cumulative sent data per connection */ /* Cumulative sent data per connection */
...@@ -97,7 +97,7 @@ void tui_print() { ...@@ -97,7 +97,7 @@ void tui_print() {
/* Receive rate per connection */ /* Receive rate per connection */
printf(" %s%s", host2, " <="); printf(" %s%s", host2, " <=");
for(j = 0; j < HISTORY_DIVISIONS; j++) { for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_in_bytes); readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10); printf(" %10s", buf0_10);
} }
/* Cumulative received data per connection */ /* Cumulative received data per connection */
...@@ -115,21 +115,21 @@ void tui_print() { ...@@ -115,21 +115,21 @@ void tui_print() {
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send rate:"); snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send rate:");
printf("%s ", labellong); printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) { for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size((((host_pair_line *)&totals)->sent[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes); readable_size(((host_pair_line *)&totals)->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' '); printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
} }
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total receive rate:"); snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total receive rate:");
printf("%s ", labellong); printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) { for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size((((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes); readable_size(((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' '); printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
} }
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send and receive rate:"); snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send and receive rate:");
printf("%s ", labellong); printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) { for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size((((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes); readable_size(((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' '); printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
} }
...@@ -141,9 +141,9 @@ void tui_print() { ...@@ -141,9 +141,9 @@ void tui_print() {
/* Peak traffic */ /* Peak traffic */
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Peak rate (sent/received/total):"); snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Peak rate (sent/received/total):");
readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_in_bytes); readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_unit);
readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_in_bytes); readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_unit);
readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_in_bytes); readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_unit);
printf("%s %10s %10s %10s\n", labellong, buf0_10, buf1_10, buf2_10); printf("%s %10s %10s %10s\n", labellong, buf0_10, buf1_10, buf2_10);
/* Cumulative totals */ /* Cumulative totals */
......
...@@ -153,7 +153,7 @@ static void draw_bar_scale(int* y) { ...@@ -153,7 +153,7 @@ static void draw_bar_scale(int* y) {
char s[40], *p; char s[40], *p;
int x; int x;
/* This 1024 vs 1000 stuff is just plain evil */ /* This 1024 vs 1000 stuff is just plain evil */
readable_size(i, s, sizeof s, options.log_scale ? 1000 : 1024, options.bandwidth_in_bytes); readable_size(i, s, sizeof s, options.log_scale ? 1000 : 1024, options.bandwidth_unit);
p = s + strspn(s, " "); p = s + strspn(s, " ");
x = get_bar_length(i * 8); x = get_bar_length(i * 8);
mvaddch(*y + 1, x, ACS_BTEE); mvaddch(*y + 1, x, ACS_BTEE);
...@@ -177,13 +177,13 @@ static void draw_bar_scale(int* y) { ...@@ -177,13 +177,13 @@ static void draw_bar_scale(int* y) {
} }
} }
void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, int bytes) { void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, option_bw_unit_t unit) {
char buf[10]; char buf[10];
float n = 0; float n = 0;
switch(linedisplay) { switch(linedisplay) {
case OPTION_LINEDISPLAY_TWO_LINE: case OPTION_LINEDISPLAY_TWO_LINE:
draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, bytes); draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, unit);
draw_line_total(sent, recv, y+1, x, OPTION_LINEDISPLAY_ONE_LINE_RECV, bytes); draw_line_total(sent, recv, y+1, x, OPTION_LINEDISPLAY_ONE_LINE_RECV, unit);
break; break;
case OPTION_LINEDISPLAY_ONE_LINE_SENT: case OPTION_LINEDISPLAY_ONE_LINE_SENT:
n = sent; n = sent;
...@@ -196,7 +196,7 @@ void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t ...@@ -196,7 +196,7 @@ void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t
break; break;
} }
if(linedisplay != OPTION_LINEDISPLAY_TWO_LINE) { if(linedisplay != OPTION_LINEDISPLAY_TWO_LINE) {
readable_size(n, buf, 10, 1024, bytes); readable_size(n, buf, 10, 1024, unit);
mvaddstr(y, x, buf); mvaddstr(y, x, buf);
} }
} }
...@@ -214,7 +214,7 @@ void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t linedisp ...@@ -214,7 +214,7 @@ void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t linedisp
int x = (COLS - 8 * HISTORY_DIVISIONS); int x = (COLS - 8 * HISTORY_DIVISIONS);
for(j = 0; j < HISTORY_DIVISIONS; j++) { for(j = 0; j < HISTORY_DIVISIONS; j++) {
draw_line_total(line->sent[j], line->recv[j], y, x, linedisplay, options.bandwidth_in_bytes); draw_line_total(line->sent[j], line->recv[j], y, x, linedisplay, options.bandwidth_unit);
x += 8; x += 8;
} }
...@@ -247,7 +247,7 @@ void draw_totals(host_pair_line* totals) { ...@@ -247,7 +247,7 @@ void draw_totals(host_pair_line* totals) {
draw_line_totals(y, totals, OPTION_LINEDISPLAY_TWO_LINE); draw_line_totals(y, totals, OPTION_LINEDISPLAY_TWO_LINE);
y += 2; y += 2;
for(j = 0; j < HISTORY_DIVISIONS; j++) { for(j = 0; j < HISTORY_DIVISIONS; j++) {
readable_size((totals->sent[j] + totals->recv[j]) , buf, 10, 1024, options.bandwidth_in_bytes); readable_size((totals->sent[j] + totals->recv[j]) , buf, 10, 1024, options.bandwidth_unit);
mvaddstr(y, x, buf); mvaddstr(y, x, buf);
x += 8; x += 8;
} }
...@@ -262,6 +262,7 @@ void ui_print() { ...@@ -262,6 +262,7 @@ void ui_print() {
static char *line; static char *line;
static int lcols; static int lcols;
int y = 0; int y = 0;
option_bw_unit_t cumunit;
if (dontshowdisplay) if (dontshowdisplay)
return; return;
...@@ -375,25 +376,31 @@ void ui_print() { ...@@ -375,25 +376,31 @@ void ui_print() {
/* Cummulative totals */ /* Cummulative totals */
mvaddstr(y, 16, "cum: "); mvaddstr(y, 16, "cum: ");
readable_size(history_totals.total_sent, line, 10, 1024, 1); /* Previous versions of iftop always displayed totals in bytes, even when
use-bytes = false. Stay compatible when the default unit hasn't been
changed. */
cumunit = options.bandwidth_unit;
if (cumunit == OPTION_BW_BITS)
cumunit = OPTION_BW_BYTES;
readable_size(history_totals.total_sent, line, 10, 1024, cumunit);
mvaddstr(y, 22, line); mvaddstr(y, 22, line);
readable_size(history_totals.total_recv, line, 10, 1024, 1); readable_size(history_totals.total_recv, line, 10, 1024, cumunit);
mvaddstr(y+1, 22, line); mvaddstr(y+1, 22, line);
readable_size(history_totals.total_recv + history_totals.total_sent, line, 10, 1024, 1); readable_size(history_totals.total_recv + history_totals.total_sent, line, 10, 1024, cumunit);
mvaddstr(y+2, 22, line); mvaddstr(y+2, 22, line);
/* peak traffic */ /* peak traffic */
mvaddstr(y, 32, "peak: "); mvaddstr(y, 32, "peak: ");
readable_size(peaksent / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes); readable_size(peaksent / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y, 39, line); mvaddstr(y, 39, line);
readable_size(peakrecv / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes); readable_size(peakrecv / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y+1, 39, line); mvaddstr(y+1, 39, line);
readable_size(peaktotal / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes); readable_size(peaktotal / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y+2, 39, line); mvaddstr(y+2, 39, line);
mvaddstr(y, COLS - 8 * HISTORY_DIVISIONS - 8, "rates:"); mvaddstr(y, COLS - 8 * HISTORY_DIVISIONS - 8, "rates:");
......
...@@ -21,8 +21,11 @@ ...@@ -21,8 +21,11 @@
int history_divs[HISTORY_DIVISIONS] = {1, 5, 20}; int history_divs[HISTORY_DIVISIONS] = {1, 5, 20};
#define UNIT_DIVISIONS 4 #define UNIT_DIVISIONS 4
char* unit_bits[UNIT_DIVISIONS] = { "b", "Kb", "Mb", "Gb"}; char* unit_disp[][UNIT_DIVISIONS] = {
char* unit_bytes[UNIT_DIVISIONS] = { "B", "KB", "MB", "GB"}; [OPTION_BW_BITS] = { "b", "Kb", "Mb", "Gb"},
[OPTION_BW_BYTES] = { "B", "KB", "MB", "GB"},
[OPTION_BW_PKTS] = { "p", "Kp", "Mp", "GB"},
};
extern hash_type* history; extern hash_type* history;
extern int history_pos; extern int history_pos;
...@@ -121,29 +124,34 @@ int screen_line_compare(void* a, void* b) { ...@@ -121,29 +124,34 @@ int screen_line_compare(void* a, void* b) {
/* /*
* Format a data size in human-readable format * Format a data size in human-readable format
*/ */
void readable_size(float n, char* buf, int bsize, int ksize, int bytes) { void readable_size(float n, char* buf, int bsize, int ksize,
option_bw_unit_t unit) {
int i = 0; int i = 0;
float size = 1; float size = 1;
/* Convert to bits? */ /* Convert to bits? */
if(bytes == 0) { if (unit == OPTION_BW_BITS) {
n *= 8; n *= 8;
} }
/* Force power of ten for pps */
if (unit == OPTION_BW_PKTS)
ksize = 1000;
while(1) { while(1) {
if(n < size * 1000 || i >= UNIT_DIVISIONS - 1) { if(n < size * 1000 || i >= UNIT_DIVISIONS - 1) {
snprintf(buf, bsize, " %4.0f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]); snprintf(buf, bsize, " %4.0f%s", n / size, unit_disp[unit][i]);
break; break;
} }
i++; i++;
size *= ksize; size *= ksize;
if(n < size * 10) { if(n < size * 10) {
snprintf(buf, bsize, " %4.2f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]); snprintf(buf, bsize, " %4.2f%s", n / size, unit_disp[unit][i]);
break; break;
} }
else if(n < size * 100) { else if(n < size * 100) {
snprintf(buf, bsize, " %4.1f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]); snprintf(buf, bsize, " %4.1f%s", n / size, unit_disp[unit][i]);
break; break;
} }
} }
......
...@@ -43,6 +43,6 @@ hash_type* service_hash; ...@@ -43,6 +43,6 @@ hash_type* service_hash;
void analyse_data(void); void analyse_data(void);
void screen_list_init(void); void screen_list_init(void);
void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port, unsigned int protocol, int L, int unspecified_as_star); void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port, unsigned int protocol, int L, int unspecified_as_star);
void readable_size(float, char*, int, int, int); void readable_size(float, char*, int, int, option_bw_unit_t);
#endif /* __UI_COMMON_H_ */ #endif /* __UI_COMMON_H_ */
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!