Added popup status messages.

This commit is contained in:
pdw
2002-10-24 16:15:12 +00:00
parent e1c4cb7adf
commit 0be11c0e8a
5 changed files with 93 additions and 25 deletions

View File

@@ -43,7 +43,6 @@ CFLAGS += -DUSE_GETHOSTBYADDR_R
# Uncomment if you are using libresolv. # Uncomment if you are using libresolv.
# #
#LDLIBS += -lresolv # or /usr/lib/libresolv.a on Linux? #LDLIBS += -lresolv # or /usr/lib/libresolv.a on Linux?
# #
# Uncomment if you are using ares. # Uncomment if you are using ares.
# #

View File

@@ -54,6 +54,7 @@ static void finish(int sig) {
/* Only need ethernet and IP headers (48) + first 2 bytes of tcp/udp header */ /* Only need ethernet and IP headers (48) + first 2 bytes of tcp/udp header */
#define CAPTURE_LENGTH 68 #define CAPTURE_LENGTH 68
@@ -112,8 +113,8 @@ void tick(int print) {
history_rotate(); history_rotate();
last_timestamp = t; last_timestamp = t;
} }
else if(print) { else {
ui_print(); ui_tick(print);
} }
pthread_mutex_unlock(&tick_mutex); pthread_mutex_unlock(&tick_mutex);

View File

@@ -44,6 +44,9 @@ int tail;
#if defined(USE_GETHOSTBYADDR_R) #if defined(USE_GETHOSTBYADDR_R)
/** /**
* Implementation of do_resolve for platforms with working gethostbyaddr_r * Implementation of do_resolve for platforms with working gethostbyaddr_r
*
* Some implementations of libc choose to implement gethostbyaddr_r as
* a non thread-safe wrapper to gethostbyaddr. An interesting choice...
*/ */
char* do_resolve(struct in_addr * addr) { char* do_resolve(struct in_addr * addr) {
struct hostent hostbuf, *hp; struct hostent hostbuf, *hp;
@@ -103,6 +106,7 @@ char *do_resolve(struct in_addr *addr) {
/** /**
* libresolv implementation * libresolv implementation
* resolver functions may not be thread safe
*/ */
char* do_resolve(struct in_addr * addr) { char* do_resolve(struct in_addr * addr) {
char msg[PACKETSZ]; char msg[PACKETSZ];

105
ui.c
View File

@@ -24,6 +24,8 @@
#define HISTORY_DIVISIONS 3 #define HISTORY_DIVISIONS 3
#define BARGRAPH_INTERVAL 1 /* which division used for bars. */ #define BARGRAPH_INTERVAL 1 /* which division used for bars. */
#define HELP_TIME 2
#define HELP_MESSAGE \ #define HELP_MESSAGE \
"Host display:\n"\ "Host display:\n"\
" r - toggle DNS host resolution \n"\ " r - toggle DNS host resolution \n"\
@@ -71,7 +73,10 @@ sorted_list_type screen_list;
host_pair_line totals; host_pair_line totals;
int peaksent, peakrecv, peaktotal; int peaksent, peakrecv, peaktotal;
#define HELP_MSG_SIZE 80
int showhelphint = 0; int showhelphint = 0;
int helptimer = 0;
char helpmsg[HELP_MSG_SIZE];
int screen_line_compare(void* a, void* b) { int screen_line_compare(void* a, void* b) {
int i; int i;
@@ -381,14 +386,7 @@ void sprint_host(char * line, struct in_addr* addr, unsigned int port, unsigned
sprintf(line + left, "%-*s", L-left, service); sprintf(line + left, "%-*s", L-left, service);
} }
void write_in_line(int y, int x, char * s) {
/* Peak traffic */
mvaddch(y, x, ACS_RTEE);
addstr(" ");
addstr(s);
addstr(" ");
addch(ACS_LTEE);
}
void ui_print() { void ui_print() {
sorted_list_node* nn = NULL; sorted_list_node* nn = NULL;
@@ -402,7 +400,6 @@ void ui_print() {
line = calloc(COLS + 1, 1); line = calloc(COLS + 1, 1);
} }
/* /*
* erase() is faster than clear(). Dunno why we switched to * erase() is faster than clear(). Dunno why we switched to
* clear() -pdw 24/10/02 * clear() -pdw 24/10/02
@@ -416,7 +413,6 @@ void ui_print() {
} }
else { else {
/* 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. */
@@ -490,10 +486,9 @@ void ui_print() {
draw_totals(&totals); draw_totals(&totals);
if(showhelphint > 0) { if(showhelphint) {
mvaddstr(0, 0, "Press h for help "); mvaddstr(0, 0, helpmsg);
clrtoeol(); clrtoeol();
showhelphint--;
} }
refresh(); refresh();
@@ -505,6 +500,16 @@ void ui_print() {
} }
} }
void ui_tick(int print) {
if(print) {
ui_print();
}
else if(showhelphint && (time(NULL) - helptimer > HELP_TIME)) {
showhelphint = 0;
ui_print();
}
}
void ui_init() { void ui_init() {
(void) initscr(); /* initialize the curses library */ (void) initscr(); /* initialize the curses library */
keypad(stdscr, TRUE); /* enable keyboard mapping */ keypad(stdscr, TRUE); /* enable keyboard mapping */
@@ -524,6 +529,28 @@ void ui_init() {
} }
void showhelp(const char * s) {
strncpy(helpmsg, s, HELP_MSG_SIZE);
showhelphint = 1;
helptimer = time(NULL);
tick(1);
}
void showportstatus() {
if(options.showports == OPTION_PORTS_ON) {
showhelp("Port display ON");
}
else if(options.showports == OPTION_PORTS_OFF) {
showhelp("Port display OFF");
}
else if(options.showports == OPTION_PORTS_DEST) {
showhelp("Port display DEST");
}
else if(options.showports == OPTION_PORTS_SRC) {
showhelp("Port display SOURCE");
}
}
void ui_loop() { void ui_loop() {
extern sig_atomic_t foad; extern sig_atomic_t foad;
while(foad == 0) { while(foad == 0) {
@@ -535,12 +562,26 @@ void ui_loop() {
break; break;
case 'r': case 'r':
options.dnsresolution = !options.dnsresolution; if(options.dnsresolution) {
options.dnsresolution = 0;
showhelp("DNS resolution off");
}
else {
options.dnsresolution = 1;
showhelp("DNS resolution on");
}
tick(1); tick(1);
break; break;
case 'R': case 'R':
options.portresolution = !options.portresolution; if(options.portresolution) {
options.portresolution = 0;
showhelp("Port resolution off");
}
else {
options.portresolution = 1;
showhelp("Port resolution on");
}
tick(1); tick(1);
break; break;
@@ -550,16 +591,36 @@ void ui_loop() {
break; break;
case 'b': case 'b':
options.showbars = !options.showbars; if(options.showbars) {
options.showbars = 0;
showhelp("Bars off");
}
else {
options.showbars = 1;
showhelp("Bars on");
}
tick(1); tick(1);
break; break;
case 's': case 's':
options.aggregate_src = !options.aggregate_src; if(options.aggregate_src) {
options.aggregate_src = 0;
showhelp("Show source host");
}
else {
options.aggregate_src = 1;
showhelp("Hide source host");
}
break; break;
case 'd': case 'd':
options.aggregate_dest = !options.aggregate_dest; if(options.aggregate_dest) {
options.aggregate_dest = 0;
showhelp("Show dest host");
}
else {
options.aggregate_dest = 1;
showhelp("Hide dest host");
}
break; break;
case 'S': case 'S':
/* Show source ports */ /* Show source ports */
@@ -575,6 +636,7 @@ void ui_loop() {
else { else {
options.showports = OPTION_PORTS_OFF; options.showports = OPTION_PORTS_OFF;
} }
showportstatus();
break; break;
case 'D': case 'D':
/* Show dest ports */ /* Show dest ports */
@@ -590,12 +652,14 @@ void ui_loop() {
else { else {
options.showports = OPTION_PORTS_OFF; options.showports = OPTION_PORTS_OFF;
} }
showportstatus();
break; break;
case 'p': case 'p':
options.showports = options.showports =
(options.showports == OPTION_PORTS_OFF) (options.showports == OPTION_PORTS_OFF)
? OPTION_PORTS_ON ? OPTION_PORTS_ON
: OPTION_PORTS_OFF; : OPTION_PORTS_OFF;
showportstatus();
// Don't tick here, otherwise we get a bogus display // Don't tick here, otherwise we get a bogus display
break; break;
case 'P': case 'P':
@@ -604,8 +668,7 @@ void ui_loop() {
case ERR: case ERR:
break; break;
default: default:
showhelphint = 2; showhelp("Press h for help");
tick(1);
break; break;
} }
tick(0); tick(0);

1
ui.h
View File

@@ -10,5 +10,6 @@
void ui_print(); void ui_print();
void ui_loop(); void ui_loop();
void ui_finish(); void ui_finish();
void ui_tick(int);
#endif /* __UI_H_ */ #endif /* __UI_H_ */