Commit 6458ed04 by pdw

Created iftop-dump

1 parent 86013fab
......@@ -22,8 +22,8 @@ CFLAGS += -I/usr/include/pcap -g
# Do you want to use curses or ncurses? Probably ncurses, unless curses
# is ncurses on your machine.
CURSES = ncurses
#CURSES = curses
# CURSES = -lncurses
#CURSES = -lcurses
#
# Name resolution. Sensible systems have gethostbyaddr_r, which is reentrant
......@@ -66,7 +66,7 @@ CFLAGS += -DUSE_GETHOSTBYADDR_R
#
# Solaris needs a library to make sockets go and lacks inet_aton.
#
LDLIBS += -lsocket -lnsl
#LDLIBS += -lsocket -lnsl
CFLAGS += -DFAKE_INET_ATON
# PREFIX specifies the base directory for the installation.
......@@ -83,23 +83,32 @@ MANDIR = man
# You shouldn't need to change anything below this point.
CFLAGS += -g -Wall "-DIFTOP_VERSION=\"$(VERSION)\""
LDFLAGS += -g #-pthread
LDLIBS += -lpcap -l$(CURSES) -lm -lpthread
SRCS = iftop.c addr_hash.c hash.c ns_hash.c resolver.c ui.c util.c sorted_list.c\
options.c serv_hash.c threadprof.c edline.c screenfilter.c
LDLIBS += -lpcap $(CURSES) -lm -lpthread
COMMON_SRCS = addr_hash.c hash.c ns_hash.c util.c sorted_list.c\
options.c serv_hash.c threadprof.c screenfilter.c cfgfile.c stringmap.c addrs_ioctl.c
IFTOP_ONLY_SRCS = iftop.c ui.c stringmap.c
IFTOPDUMP_ONLY_SRCS = iftop-dump.c counter_hash.c
SRCS = $(COMMON_SRCS) $(IFTOPDUMP_ONLY_SRCS) $(IFTOP_ONLY_SRCS)
IFTOP_SRCS = $(IFTOP_ONLY_SRCS) $(COMMON_SRCS)
IFTOPDUMP_SRCS = $(IFTOPDUMP_ONLY_SRCS) $(COMMON_SRCS)
HDRS = addr_hash.h hash.h iftop.h ns_hash.h resolver.h sorted_list.h ui.h options.h sll.h\
serv_hash.h threadprof.h ether.h ip.h tcp.h screenfilter.h token.h llc.h \
extract.h ethertype.h
TXTS = README CHANGES INSTALL TODO iftop.8 COPYING
SPECFILE = iftop.spec iftop.spec.in
OBJS = $(SRCS:.c=.o)
IFTOP_OBJS = $(IFTOP_SRCS:.c=.o)
IFTOPDUMP_OBJS = $(IFTOPDUMP_SRCS:.c=.o)
iftop: $(IFTOP_OBJS) Makefile
$(CC) $(LDFLAGS) -o $@ $(IFTOP_OBJS) $(LDLIBS)
iftop: $(OBJS) Makefile
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
iftop-dump: $(IFTOPDUMP_OBJS) Makefile
$(CC) $(LDFLAGS) -o $@ $(IFTOPDUMP_OBJS) $(LDLIBS)
integers.h: integers
./integers
#integers.h: integers
# ./integers
install: iftop
install -D iftop $(PREFIX)/$(BINDIR)/iftop
......
......@@ -10,7 +10,7 @@
# $Id$
#
sbin_PROGRAMS = iftop
sbin_PROGRAMS = iftop iftop-dump
iftop_SOURCES = addr_hash.c edline.c hash.c iftop.c ns_hash.c \
options.c resolver.c screenfilter.c serv_hash.c \
......@@ -18,6 +18,14 @@ iftop_SOURCES = addr_hash.c edline.c hash.c iftop.c ns_hash.c \
addrs_ioctl.c addrs_dlpi.c dlcommon.c \
stringmap.c cfgfile.c vector.c
iftop_dump_SOURCES = counter_hash.c hash.c iftop-dump.c \
options.c \
util.c \
addrs_ioctl.c addrs_dlpi.c dlcommon.c \
stringmap.c cfgfile.c
noinst_HEADERS = addr_hash.h ether.h ethertype.h extract.h hash.h iftop.h \
integers.h ip.h llc.h ns_hash.h options.h resolver.h \
screenfilter.h serv_hash.h sll.h sorted_list.h tcp.h \
......
......@@ -29,7 +29,7 @@ AC_CONFIG_AUX_DIR(config)
AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(iftop, "0.17pre3")
AM_INIT_AUTOMAKE(iftop, "0.17")
AC_DEFINE_UNQUOTED(IFTOP_VERSION, "$VERSION", [The iftop version number])
......
/* hash table */
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include "counter_hash.h"
#include "hash.h"
#include "iftop.h"
#define hash_table_size 256
int counter_hash_compare(void* a, void* b) {
return *(long*)a == *(long*)b;
}
int counter_hash_hash(void* key) {
int hash;
long addr;
addr = *(long*)key;
hash = ((addr & 0x000000FF)
+ (addr & 0x0000FF00 >> 8)
+ (addr & 0x00FF0000 >> 16)
+ (addr & 0xFF000000 >> 24)
) % 0xFF;
return hash;
}
void* counter_hash_copy_key(void* orig) {
struct in_addr* copy;
copy = xmalloc(sizeof *copy);
*copy = *(struct in_addr*)orig;
return copy;
}
void counter_hash_delete_key(void* key) {
free(key);
}
/*
* Allocate and return a hash
*/
hash_type* counter_hash_create() {
hash_type* hash_table;
hash_table = xcalloc(hash_table_size, sizeof *hash_table);
hash_table->size = hash_table_size;
hash_table->compare = &counter_hash_compare;
hash_table->hash = &counter_hash_hash;
hash_table->delete_key = &counter_hash_delete_key;
hash_table->copy_key = &counter_hash_copy_key;
hash_initialise(hash_table);
return hash_table;
}
/*
* addr_hash.h:
*
*/
#ifndef __ADDR_HASH_H_ /* include guard */
#define __ADDR_HASH_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "hash.h"
typedef struct {
unsigned long long sent;
unsigned long long recv;
} counter_type;
typedef counter_type key_type; /* index into hash table */
hash_type* counter_hash_create(void);
#endif /* __ADDR_HASH_H_ */
This diff is collapsed. Click to expand it.
......@@ -11,6 +11,7 @@
/* 40 / 2 */
#define HISTORY_LENGTH 20
#define RESOLUTION 2
#define DUMP_RESOLUTION 15
typedef struct {
long recv[HISTORY_LENGTH];
......@@ -28,10 +29,6 @@ void *xrealloc(void *w, size_t n);
char *xstrdup(const char *s);
void xfree(void *v);
/* ui.c */
void analyse_data(void);
void ui_init(void);
/* options.c */
void options_read(int argc, char **argv);
......
......@@ -11,5 +11,7 @@ void ui_print(void);
void ui_loop(void);
void ui_finish(void);
void ui_tick(int);
void analyse_data(void);
void ui_init(void);
#endif /* __UI_H_ */
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!