*** empty log message ***

This commit is contained in:
pdw
2003-03-01 01:55:13 +00:00
parent 2dc4a06dda
commit 0d66972bef
8 changed files with 164 additions and 54 deletions

View File

@@ -1,6 +1,11 @@
Change log for iftop Change log for iftop
$Id$ $Id$
0.12
Added 1-line display options.
Added display scrolling.
0.11 08/01/03 0.11 08/01/03
Added support for token ring networks Added support for token ring networks

7
TODO
View File

@@ -1,9 +1,7 @@
Things to do for iftop Things to do for iftop
$Id$ $Id$
* 1-line per host display * Attempt to assign direction based on IP of selected interface for DLT_RAW.
* Up and down arrows to scroll through host list
* Search for BSD interface names - need to know what to look for. * Search for BSD interface names - need to know what to look for.
@@ -18,6 +16,3 @@ $Id$
* Configurable refresh rates. * Configurable refresh rates.
* Filtering of items included in diplay
* Attempt to assign direction based on IP of selected interface for DLT_RAW.

View File

@@ -17,7 +17,7 @@ dnl
AC_INIT(iftop.c) AC_INIT(iftop.c)
AC_CONFIG_AUX_DIR(config) AC_CONFIG_AUX_DIR(config)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(iftop, "0.11") AM_INIT_AUTOMAKE(iftop, "0.12pre1")
AC_DEFINE_UNQUOTED(IFTOP_VERSION, "$VERSION", [The iftop version number]) AC_DEFINE_UNQUOTED(IFTOP_VERSION, "$VERSION", [The iftop version number])

25
iftop.8
View File

@@ -128,6 +128,12 @@ machine.
\fBS\fP or \fBD\fP toggle the display of source and destination ports \fBS\fP or \fBD\fP toggle the display of source and destination ports
respectively. \fBp\fP will toggle port display on/off. respectively. \fBp\fP will toggle port display on/off.
.SH DISPLAY TYPE
\fBt\fP cycles through the four line display modes; the default 2-line display,
with sent and received traffic on separate lines, and 3 1-line displays, with
sent, received, or total traffic shown.
.SH DISPLAY ORDER .SH DISPLAY ORDER
By default, the display is ordered according to the 10s average (2nd column). By default, the display is ordered according to the 10s average (2nd column).
@@ -140,7 +146,8 @@ source or destination hostname respectively.
\fBl\fP allows you to enter a POSIX extended regular expression that will be \fBl\fP allows you to enter a POSIX extended regular expression that will be
used to filter hostnames shown in the display. This is a good way to quickly used to filter hostnames shown in the display. This is a good way to quickly
limit what is shown on the display. Note that this happens at a much later limit what is shown on the display. Note that this happens at a much later
stage than filter code, and does not affect what is actually captured. stage than filter code, and does not affect what is actually captured. Display
filters DO NOT affect the totals at the bottom of the screen.
.SH PAUSE DISPLAY / FREEZE ORDER .SH PAUSE DISPLAY / FREEZE ORDER
@@ -150,6 +157,11 @@ stage than filter code, and does not affect what is actually captured.
traffic between hosts not shown on the screen at the time will not be shown at traffic between hosts not shown on the screen at the time will not be shown at
all, although it will be included in the totals at the bottom of the screen. all, although it will be included in the totals at the bottom of the screen.
.SH SCROLL DISPLAY
\fBj\fP and \fBk\fP will scroll the display of hosts. This feature is most
useful when the display order is frozen (see above).
.SH FILTER CODE .SH FILTER CODE
\fBf\fP allows you to edit the filter code whilst iftop running. This \fBf\fP allows you to edit the filter code whilst iftop running. This
@@ -170,11 +182,12 @@ you, but is included in the totals.
A more subtle explanation comes about when running in promiscuous mode A more subtle explanation comes about when running in promiscuous mode
without specifying a \fB-N\fP option. In this case there is no easy way without specifying a \fB-N\fP option. In this case there is no easy way
to assign the direction of traffic between two other hosts. For the to assign the direction of traffic between two third parties. For the purposes
purposes of the main display this is done in an arbitrary fashion (by of the main display this is done in an arbitrary fashion (by ordering of IP
ordering of IP addresses), but for the sake of totals all traffic addresses), but for the sake of totals all traffic between other hosts is
between other hosts is accounted as incoming, because that's what it is accounted as incoming, because that's what it is from the point of view of your
from the point of view of your interface. interface. The \fB-N\fP option allows you to specify an arbitrary network
boundary, and to show traffic flowing across it.
\fBPeak totals don't add up\fP \fBPeak totals don't add up\fP

View File

@@ -20,7 +20,7 @@ typedef struct {
int last_write; int last_write;
} history_type; } history_type;
void tick(void); void tick(int print);
void *xmalloc(size_t n); void *xmalloc(size_t n);
void *xcalloc(size_t n, size_t m); void *xcalloc(size_t n, size_t m);

View File

@@ -98,6 +98,8 @@ static void set_defaults() {
options.sort = OPTION_SORT_DIV2; options.sort = OPTION_SORT_DIV2;
options.screenfilter = NULL; options.screenfilter = NULL;
options.freezeorder = 0; options.freezeorder = 0;
options.linedisplay = OPTION_LINEDISPLAY_TWO_LINE;
options.screen_offset = 0;
} }
static void die(char *msg) { static void die(char *msg) {

View File

@@ -26,6 +26,13 @@ typedef enum {
OPTION_SORT_DEST OPTION_SORT_DEST
} option_sort_t; } option_sort_t;
typedef enum {
OPTION_LINEDISPLAY_TWO_LINE,
OPTION_LINEDISPLAY_ONE_LINE_BOTH,
OPTION_LINEDISPLAY_ONE_LINE_RECV,
OPTION_LINEDISPLAY_ONE_LINE_SENT
} option_linedisplay_t;
typedef struct { typedef struct {
/* interface on which to listen */ /* interface on which to listen */
char *interface; char *interface;
@@ -52,6 +59,10 @@ typedef struct {
char* screenfilter; char* screenfilter;
int freezeorder; int freezeorder;
int screen_offset;
option_linedisplay_t linedisplay;
} options_t; } options_t;
#endif /* __OPTIONS_H_ */ #endif /* __OPTIONS_H_ */

164
ui.c
View File

@@ -38,6 +38,7 @@
" r - toggle DNS host resolution P - pause display\n"\ " r - toggle DNS host resolution P - pause display\n"\
" s - toggle show source host h - toggle this help display\n"\ " s - toggle show source host h - toggle this help display\n"\
" d - toggle show destination host b - toggle bar graph display\n"\ " d - toggle show destination host b - toggle bar graph display\n"\
" t - cycle line display mode j/k - scroll display\n"\
" f - edit filter code\n"\ " f - edit filter code\n"\
"Port display: l - set screen filter\n"\ "Port display: l - set screen filter\n"\
" R - toggle service resolution ! - shell command\n"\ " R - toggle service resolution ! - shell command\n"\
@@ -245,30 +246,60 @@ int history_length(const int d) {
return history_divs[d] * RESOLUTION; return history_divs[d] * RESOLUTION;
} }
void draw_line_totals(int y, host_pair_line* line) { void draw_line_total(float n, int y, int x) {
int j, L;
char buf[10]; char buf[10];
readable_size(n, buf, 10, 1024, options.bandwidth_in_bytes);
mvaddstr(y, x, buf);
}
void draw_bar(float n, int y) {
int L;
mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
L = get_bar_length(8 * n);
if (L > 0)
mvchgat(y, 0, L + 1, A_REVERSE, 0, NULL);
}
void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t linedisplay) {
int j;
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++) {
readable_size(line->sent[j], buf, 10, 1024, options.bandwidth_in_bytes); switch(linedisplay) {
mvaddstr(y, x, buf); case OPTION_LINEDISPLAY_TWO_LINE:
draw_line_total(line->sent[j], y, x);
draw_line_total(line->recv[j], y+1, x);
break;
case OPTION_LINEDISPLAY_ONE_LINE_SENT:
draw_line_total(line->sent[j], y, x);
break;
case OPTION_LINEDISPLAY_ONE_LINE_RECV:
draw_line_total(line->recv[j], y, x);
break;
case OPTION_LINEDISPLAY_ONE_LINE_BOTH:
draw_line_total(line->recv[j] + line->sent[j], y, x);
break;
}
readable_size(line->recv[j], buf, 10, 1024, options.bandwidth_in_bytes); x += 8;
mvaddstr(y+1, x, buf);
x += 8;
} }
if(options.showbars) { if(options.showbars) {
mvchgat(y, 0, -1, A_NORMAL, 0, NULL); switch(linedisplay) {
L = get_bar_length(8 * line->sent[BARGRAPH_INTERVAL] ); case OPTION_LINEDISPLAY_TWO_LINE:
if (L > 0) draw_bar(line->sent[BARGRAPH_INTERVAL],y);
mvchgat(y, 0, L + 1, A_REVERSE, 0, NULL); draw_bar(line->recv[BARGRAPH_INTERVAL],y+1);
break;
mvchgat(y+1, 0, -1, A_NORMAL, 0, NULL); case OPTION_LINEDISPLAY_ONE_LINE_SENT:
L = get_bar_length(8 * line->recv[BARGRAPH_INTERVAL] ); draw_bar(line->sent[BARGRAPH_INTERVAL],y);
if (L > 0) break;
mvchgat(y+1, 0, L + 1, A_REVERSE, 0, NULL); case OPTION_LINEDISPLAY_ONE_LINE_RECV:
draw_bar(line->recv[BARGRAPH_INTERVAL],y);
break;
case OPTION_LINEDISPLAY_ONE_LINE_BOTH:
draw_bar(line->recv[BARGRAPH_INTERVAL] + line->sent[BARGRAPH_INTERVAL],y);
break;
}
} }
} }
@@ -279,7 +310,7 @@ void draw_totals(host_pair_line* totals) {
char buf[10]; char buf[10];
int x = (COLS - 8 * HISTORY_DIVISIONS); int x = (COLS - 8 * HISTORY_DIVISIONS);
y++; y++;
draw_line_totals(y, totals); 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_in_bytes);
@@ -513,44 +544,69 @@ void ui_print() {
mvaddstr(y,0,HELP_MESSAGE); mvaddstr(y,0,HELP_MESSAGE);
} }
else { else {
int i = 0;
while(i < options.screen_offset && ((nn = sorted_list_next_item(&screen_list, nn)) != NULL)) {
i++;
}
/* Screen layout: we have 2 * HISTORY_DIVISIONS 6-character wide history /* Screen layout: we have 2 * HISTORY_DIVISIONS 6-character wide history
* items, and so can use COLS - 12 * HISTORY_DIVISIONS to print the two * items, and so can use COLS - 12 * HISTORY_DIVISIONS to print the two
* host names. */ * host names. */
while((y < LINES - 5) && ((nn = sorted_list_next_item(&screen_list, nn)) != NULL)) { if(i == 0 || nn != NULL) {
int x = 0, L; while((y < LINES - 5) && ((nn = sorted_list_next_item(&screen_list, nn)) != NULL)) {
int x = 0, L;
host_pair_line* screen_line = (host_pair_line*)nn->data; host_pair_line* screen_line = (host_pair_line*)nn->data;
if(y < LINES - 5) { if(y < LINES - 5) {
L = (COLS - 8 * HISTORY_DIVISIONS - 4) / 2; L = (COLS - 8 * HISTORY_DIVISIONS - 4) / 2;
if(L > HOSTNAME_LENGTH) { if(L > HOSTNAME_LENGTH) {
L = HOSTNAME_LENGTH; L = HOSTNAME_LENGTH;
} }
sprint_host(host1, &(screen_line->ap.src), screen_line->ap.src_port, screen_line->ap.protocol, L); sprint_host(host1, &(screen_line->ap.src), screen_line->ap.src_port, screen_line->ap.protocol, L);
sprint_host(host2, &(screen_line->ap.dst), screen_line->ap.dst_port, screen_line->ap.protocol, L); sprint_host(host2, &(screen_line->ap.dst), screen_line->ap.dst_port, screen_line->ap.protocol, L);
if(!screen_filter_match(host1) && !screen_filter_match(host2)) { if(!screen_filter_match(host1) && !screen_filter_match(host2)) {
continue; continue;
} }
mvaddstr(y, x, host1); mvaddstr(y, x, host1);
x += L; x += L;
mvaddstr(y, x, " => "); switch(options.linedisplay) {
mvaddstr(y+1, x, " <= "); case OPTION_LINEDISPLAY_TWO_LINE:
mvaddstr(y, x, " => ");
mvaddstr(y+1, x, " <= ");
break;
case OPTION_LINEDISPLAY_ONE_LINE_BOTH:
mvaddstr(y, x, "<=> ");
break;
case OPTION_LINEDISPLAY_ONE_LINE_SENT:
mvaddstr(y, x, " => ");
break;
case OPTION_LINEDISPLAY_ONE_LINE_RECV:
mvaddstr(y, x, " <= ");
break;
}
x += 4; x += 4;
mvaddstr(y, x, host2); mvaddstr(y, x, host2);
draw_line_totals(y, screen_line); draw_line_totals(y, screen_line, options.linedisplay);
} }
y += 2; if(options.linedisplay == OPTION_LINEDISPLAY_TWO_LINE) {
y += 2;
}
else {
y += 1;
}
}
} }
} }
@@ -831,6 +887,34 @@ void ui_loop() {
options.sort = OPTION_SORT_DEST; options.sort = OPTION_SORT_DEST;
showhelp("Sort by dest"); showhelp("Sort by dest");
break; break;
case 'j':
options.screen_offset++;
ui_print();
break;
case 'k':
if(options.screen_offset > 0) {
options.screen_offset--;
ui_print();
}
break;
case 't':
options.linedisplay = (options.linedisplay + 1) % 4;
switch(options.linedisplay) {
case OPTION_LINEDISPLAY_TWO_LINE:
showhelp("Two lines per host");
break;
case OPTION_LINEDISPLAY_ONE_LINE_SENT:
showhelp("Sent traffic only");
break;
case OPTION_LINEDISPLAY_ONE_LINE_RECV:
showhelp("Received traffic only");
break;
case OPTION_LINEDISPLAY_ONE_LINE_BOTH:
showhelp("One line per host");
break;
}
ui_print();
break;
case 'f': { case 'f': {
char *s; char *s;
dontshowdisplay = 1; dontshowdisplay = 1;