Commit a438a94d authored by chris's avatar chris

""

parent 1388f3ad
......@@ -2,10 +2,10 @@
#CC = gcc
CFLAGS += -g -Wall -I/usr/include/pcap
CFLAGS += -g -Wall -I/usr/local/include -I/usr/include/pcap
LDFLAGS += -g
LDLIBS += -L/usr/local/lib -lpcap -lpthread -lcurses
LDLIBS += -L/usr/local/lib -lpcap -lpthread -lcurses -lm
SRCS = iftop.c \
addr_hash.c \
......@@ -43,140 +43,3 @@ nodepend:
rm -f depend
# DO NOT DELETE
iftop.o: /usr/include/stdio.h /usr/include/features.h
iftop.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
iftop.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h
iftop.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stdarg.h
iftop.o: /usr/include/bits/types.h /usr/include/libio.h
iftop.o: /usr/include/_G_config.h /usr/include/bits/stdio_lim.h
iftop.o: /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h
iftop.o: /usr/include/endian.h /usr/include/bits/endian.h
iftop.o: /usr/include/sys/select.h /usr/include/bits/select.h
iftop.o: /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h
iftop.o: /usr/include/alloca.h /usr/include/net/ethernet.h
iftop.o: /usr/include/linux/if_ether.h /usr/include/netinet/ip.h
iftop.o: /usr/include/netinet/in.h /usr/include/limits.h
iftop.o: /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h
iftop.o: /usr/include/linux/limits.h /usr/include/bits/posix2_lim.h
iftop.o: /usr/include/stdint.h /usr/include/bits/wordsize.h
iftop.o: /usr/include/bits/socket.h /usr/include/bits/sockaddr.h
iftop.o: /usr/include/asm/socket.h /usr/include/asm/sockios.h
iftop.o: /usr/include/bits/in.h /usr/include/bits/byteswap.h
iftop.o: /usr/include/pthread.h /usr/include/sched.h
iftop.o: /usr/include/bits/sched.h /usr/include/signal.h
iftop.o: /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h
iftop.o: /usr/include/curses.h /usr/include/ncurses/unctrl.h
iftop.o: /usr/include/ncurses/curses.h /usr/include/string.h iftop.h
iftop.o: addr_hash.h /usr/include/sys/socket.h /usr/include/arpa/inet.h
iftop.o: hash.h resolver.h ui.h
addr_hash.o: /usr/include/stdio.h /usr/include/features.h
addr_hash.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
addr_hash.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h
addr_hash.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stdarg.h
addr_hash.o: /usr/include/bits/types.h /usr/include/libio.h
addr_hash.o: /usr/include/_G_config.h /usr/include/bits/stdio_lim.h
addr_hash.o: /usr/include/stdlib.h /usr/include/sys/types.h
addr_hash.o: /usr/include/time.h /usr/include/endian.h
addr_hash.o: /usr/include/bits/endian.h /usr/include/sys/select.h
addr_hash.o: /usr/include/bits/select.h /usr/include/bits/sigset.h
addr_hash.o: /usr/include/sys/sysmacros.h /usr/include/alloca.h addr_hash.h
addr_hash.o: /usr/include/sys/socket.h /usr/include/bits/socket.h
addr_hash.o: /usr/include/limits.h /usr/include/bits/posix1_lim.h
addr_hash.o: /usr/include/bits/local_lim.h /usr/include/linux/limits.h
addr_hash.o: /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h
addr_hash.o: /usr/include/asm/socket.h /usr/include/asm/sockios.h
addr_hash.o: /usr/include/netinet/in.h /usr/include/stdint.h
addr_hash.o: /usr/include/bits/wordsize.h /usr/include/bits/in.h
addr_hash.o: /usr/include/bits/byteswap.h /usr/include/arpa/inet.h hash.h
hash.o: /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h
hash.o: /usr/include/gnu/stubs.h
hash.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h
hash.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stdarg.h
hash.o: /usr/include/bits/types.h /usr/include/libio.h
hash.o: /usr/include/_G_config.h /usr/include/bits/stdio_lim.h
hash.o: /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h
hash.o: /usr/include/endian.h /usr/include/bits/endian.h
hash.o: /usr/include/sys/select.h /usr/include/bits/select.h
hash.o: /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h
hash.o: /usr/include/alloca.h hash.h
ns_hash.o: /usr/include/stdio.h /usr/include/features.h
ns_hash.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
ns_hash.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h
ns_hash.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stdarg.h
ns_hash.o: /usr/include/bits/types.h /usr/include/libio.h
ns_hash.o: /usr/include/_G_config.h /usr/include/bits/stdio_lim.h
ns_hash.o: /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h
ns_hash.o: /usr/include/endian.h /usr/include/bits/endian.h
ns_hash.o: /usr/include/sys/select.h /usr/include/bits/select.h
ns_hash.o: /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h
ns_hash.o: /usr/include/alloca.h /usr/include/sys/socket.h
ns_hash.o: /usr/include/bits/socket.h /usr/include/limits.h
ns_hash.o: /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h
ns_hash.o: /usr/include/linux/limits.h /usr/include/bits/posix2_lim.h
ns_hash.o: /usr/include/bits/sockaddr.h /usr/include/asm/socket.h
ns_hash.o: /usr/include/asm/sockios.h /usr/include/netinet/in.h
ns_hash.o: /usr/include/stdint.h /usr/include/bits/wordsize.h
ns_hash.o: /usr/include/bits/in.h /usr/include/bits/byteswap.h
ns_hash.o: /usr/include/arpa/inet.h ns_hash.h hash.h
resolver.o: /usr/include/netinet/in.h /usr/include/features.h
resolver.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
resolver.o: /usr/include/limits.h /usr/include/bits/posix1_lim.h
resolver.o: /usr/include/bits/local_lim.h /usr/include/linux/limits.h
resolver.o: /usr/include/bits/posix2_lim.h /usr/include/stdint.h
resolver.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h
resolver.o: /usr/include/bits/wordsize.h /usr/include/sys/types.h
resolver.o: /usr/include/bits/types.h /usr/include/time.h
resolver.o: /usr/include/endian.h /usr/include/bits/endian.h
resolver.o: /usr/include/sys/select.h /usr/include/bits/select.h
resolver.o: /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h
resolver.o: /usr/include/bits/socket.h /usr/include/bits/sockaddr.h
resolver.o: /usr/include/asm/socket.h /usr/include/asm/sockios.h
resolver.o: /usr/include/bits/in.h /usr/include/bits/byteswap.h
resolver.o: /usr/include/sys/socket.h /usr/include/arpa/inet.h
resolver.o: /usr/include/pthread.h /usr/include/sched.h
resolver.o: /usr/include/bits/sched.h /usr/include/signal.h
resolver.o: /usr/include/bits/pthreadtypes.h /usr/include/bits/sigthread.h
resolver.o: /usr/include/stdio.h
resolver.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stdarg.h
resolver.o: /usr/include/libio.h /usr/include/_G_config.h
resolver.o: /usr/include/bits/stdio_lim.h /usr/include/stdlib.h
resolver.o: /usr/include/alloca.h /usr/include/netdb.h
resolver.o: /usr/include/rpc/netdb.h /usr/include/errno.h
resolver.o: /usr/include/bits/errno.h /usr/include/linux/errno.h
resolver.o: /usr/include/asm/errno.h /usr/include/string.h ns_hash.h hash.h
ui.o: /usr/include/curses.h /usr/include/stdio.h /usr/include/features.h
ui.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
ui.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h
ui.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stdarg.h
ui.o: /usr/include/bits/types.h /usr/include/libio.h /usr/include/_G_config.h
ui.o: /usr/include/bits/stdio_lim.h /usr/include/ncurses/unctrl.h
ui.o: /usr/include/ncurses/curses.h /usr/include/string.h
ui.o: /usr/include/pthread.h /usr/include/sched.h /usr/include/time.h
ui.o: /usr/include/bits/sched.h /usr/include/signal.h
ui.o: /usr/include/bits/sigset.h /usr/include/bits/pthreadtypes.h
ui.o: /usr/include/bits/sigthread.h /usr/include/stdlib.h
ui.o: /usr/include/sys/types.h /usr/include/endian.h
ui.o: /usr/include/bits/endian.h /usr/include/sys/select.h
ui.o: /usr/include/bits/select.h /usr/include/sys/sysmacros.h
ui.o: /usr/include/alloca.h addr_hash.h /usr/include/sys/socket.h
ui.o: /usr/include/bits/socket.h /usr/include/limits.h
ui.o: /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h
ui.o: /usr/include/linux/limits.h /usr/include/bits/posix2_lim.h
ui.o: /usr/include/bits/sockaddr.h /usr/include/asm/socket.h
ui.o: /usr/include/asm/sockios.h /usr/include/netinet/in.h
ui.o: /usr/include/stdint.h /usr/include/bits/wordsize.h
ui.o: /usr/include/bits/in.h /usr/include/bits/byteswap.h
ui.o: /usr/include/arpa/inet.h hash.h iftop.h resolver.h sorted_list.h
sorted_list.o: /usr/include/stdlib.h /usr/include/features.h
sorted_list.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
sorted_list.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h
sorted_list.o: /usr/include/sys/types.h /usr/include/bits/types.h
sorted_list.o: /usr/include/time.h /usr/include/endian.h
sorted_list.o: /usr/include/bits/endian.h /usr/include/sys/select.h
sorted_list.o: /usr/include/bits/select.h /usr/include/bits/sigset.h
sorted_list.o: /usr/include/sys/sysmacros.h /usr/include/alloca.h
sorted_list.o: /usr/include/stdio.h
sorted_list.o: /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stdarg.h
sorted_list.o: /usr/include/libio.h /usr/include/_G_config.h
sorted_list.o: /usr/include/bits/stdio_lim.h sorted_list.h
......@@ -5,9 +5,11 @@
#include <curses.h>
#include <string.h>
#include <math.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/time.h>
#include "addr_hash.h"
#include "iftop.h"
......@@ -52,6 +54,36 @@ void readable_size(float n, char* buf, int bsize) {
}
}
/* Maximum and minimum rate which we plot on the bar chart. */
static int min_rate = 1; /* 1 byte/s */
static int max_rate = (10000000 / 8); /* 10 Mbit/s */
static int get_bar_length(const int rate) {
float l;
if (rate <= 0)
return 0;
l = (log(rate) - log(min_rate)) / (log(max_rate) - log(min_rate));
return l * COLS;
}
static void draw_bar_scale(void) {
int i;
/* Draw bar graph scale on top of the window. */
mvhline(1, 0, 0, COLS);
for (i = min_rate; i <= max_rate; i *= 10) {
char s[40], *p;
int x;
readable_size(i, s, sizeof s);
p = s + strspn(s, " ");
x = get_bar_length(i);
mvaddch(1, x, ACS_BTEE);
if (x + strlen(p) >= COLS)
x = COLS - strlen(p);
mvaddstr(0, x, p);
}
mvaddch(1, 0, ACS_LLCORNER);
}
void ui_print() {
hash_node_type* n = NULL;
sorted_list_node* nn = NULL;
......@@ -64,6 +96,7 @@ void ui_print() {
sorted_list_initialise(&screen_list);
erase();
draw_bar_scale();
while(hash_next_item(history, &n) == HASH_STATUS_OK) {
history_type* d = (history_type*)n->rec;
......@@ -90,8 +123,16 @@ void ui_print() {
while((nn = sorted_list_next_item(&screen_list, nn)) != NULL) {
int x = 0;
int j;
int L;
int t;
host_pair_line* screen_line = (host_pair_line*)nn->data;
if(history_len < history_divs[j]) {
t = history_len * RESOLUTION;
} else {
t = history_divs[j] * RESOLUTION;
}
resolve(&screen_line->ap->src, hostname, HOSTNAME_LENGTH);
sprintf(line, "%s ", hostname);
mvaddstr(y, x, line);
......@@ -103,13 +144,6 @@ void ui_print() {
x += 24;
for(j = 0; j < HISTORY_DIVISIONS; j++) {
int t;
if(history_len < history_divs[j]) {
t = history_len * RESOLUTION;
}
else {
t = history_divs[j] * RESOLUTION;
}
readable_size(screen_line->sent[j] / t, line, 10);
mvaddstr(y, x, line);
x += strlen(line);
......@@ -118,6 +152,13 @@ void ui_print() {
mvaddstr(y, x, line);
x += strlen(line);
}
/* Do some sort of primitive bar graph thing. */
mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
L = get_bar_length(screen_line->recv[0] / t);
if (L > 0)
mvchgat(y, 0, L, A_REVERSE, 0, NULL);
y++;
free(screen_line);
}
......@@ -137,13 +178,21 @@ void ui_loop() {
(void) cbreak(); /* take input chars one at a time, no wait for \n */
(void) noecho(); /* don't echo input */
erase();
pthread_mutex_init(&tick_wait_mutex, NULL);
pthread_cond_init(&tick_wait_cond, NULL);
while(foad == 0) {
struct timeval tv;
struct timespec t;
int i;
t.tv_sec = time(NULL) + 1;
t.tv_nsec = 0;
gettimeofday(&tv, NULL);
tv.tv_usec += 250000;
if (tv.tv_usec > 999999) {
++tv.tv_sec;
tv.tv_usec -= 1000000;
}
t.tv_sec = tv.tv_sec;
t.tv_nsec = 1000 * tv.tv_usec;
pthread_cond_timedwait(&tick_wait_cond, &tick_wait_mutex, &t);
//fprintf(stderr,"timeout tick\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment