Commit 89d8384f authored by Markus Koschany's avatar Markus Koschany

Imported Upstream version 1.0~pre2

parents
Another file that automake insists on.
Written by
Paul Warren, pdw@ex-parrot.com
Chris Lightfoot, chris@ex-parrot.com
Mangled for Solaris by
Jonathan Abbey, jonabbey@ganymeta.org
This diff is collapsed.
Change log for iftop
$Id: ChangeLog,v 1.39 2011/10/04 18:55:35 pdw Exp $
Attributions apply to all preceding items up to the next blank line.
Unattributed items are by Paul Warren and Chris Lightfoot.
1.0
* Various typos in the UI
Gerben Roest <g.roest@grepit.nl>
* Documentation fixes
A. Costa <agcosta@gis.net> (via Debian)
* Fix for armeb specific bug
Lennert Buytenhek <buytenh+debian@wantstofly.org> (via Debian)
* Fix frozen order drives line totals crazy.
Max Alekseyev <relf@os2.ru> (via Debian)
* Fix for crash on arm.
Joey Hess <joeyh@debian.org> (via Debian)
* Fixed behaviour of "-b" option.
Eric Cooper <ecc@cmu.edu> (via Debian)
* Support for PFLOG Interfaces
Richard Tóth <risko@iklub.sk>
* Support for IPv6
* Fix for performance issue with address hashing
* Fix for failing link address detection for GNU/kfreebsd
Mats Erik Andersson <mats.andersson@gisladisker.se>
* Improved behaviour of sort in sent/recv only mode
Damián Viano <des@debian.org>
* FreeBSD compilation fix
* IPv6 reverse resolution
Frédéric Perrin <frederic.perrin@resel.fr>
* Improved IPv6 code (removed s6_addr32 dependency)
* Fixed support for DLT_NULL
Scott Bertilson <ssb@umn.edu>
* Typo in usage message
* Workaround for PuTTY issue (https://bugzilla.redhat.com/show_bug.cgi?id=546032)
Robert Scheck <robert@fedoraproject.org>
* Attempt to detect if interface is actually up when doing autodetection.
* Fixed segfault when selecting interfaces with empty MAC address (e.g. gprs
interface on Nokia N900)
Graham Inggs <graham@nerve.org.za>
* Avoid autodetecting wmaster interfaces
* Experimental support for IEEE802_11 radiotap interfaces (DLT 127)
* Fixed segfault / hang when supplying multiple -i options
0.17 12/02/06
* Display top scale in bytes when measuring in bytes
Marcin Kryczek <mkay@gentoo.org>
* Added support for ppp interfaces on FreeBSD (and others using DLT_PPP)
* Fixed segfault bug in config file handling.
* Fixes to man page
William Robinet <william.robinet@conostix.com>
* Fix for hash table memory handling bug (caused segfaults on Mac OS X)
* Header fixes for Mac OS X
Ken McLeod <thecloud@apple.com>
* Fixes for compile time errors apparent on Mac OS 10.4.3
Georg Schwarz <georg.schwarz@freenet.de>
* Improvements to configure to support cross-compilation
* Addition of "NO_SYSTEM" compiler flag to prevent subshell execution
Tim Freeman <tim@fungible.com>
* Fix to get hardware address on FreeBSD and OpenBSD
Nicolas Bernard <n.bernard@worldonline.fr>
* Added 802.1q VLAN support
Jacek Konieczny <jajcus@bnet.pl>
0.16 28/02/04
* Added support for DLT_NULL
* Fix for pthread.c behaviour on Solaris.
* Build fixes for gcc 3.4+
Henne Vogelsang <hvogel@suse.de>
* Fixed behaviour of -n and -N options
Klaus Sperner <klaus@heaven.escape.de>
0.15 10/11/03
* Added linear bar scales (default) ("L")
* Added fixed upper limit for bandwidth
* Choose which average bars display ("B")
* Renamed some buttons and command line options
* Added config file support
* Added command line to turn of port resolution ("-N")
* Fixed the search for libpcap in the configure script
Thomas Schwinge <tschwinge@gmx.net>
* Updated RPM spec file
Richard Lucassen <spamtrap@lucassen.org>
0.14 06/09/03
* Added forking resolver as fall-back resolver
* Fixed DNS resolution so that no lookups are done if options.dns_resolution ==
0
* Configure/compilation fixes for Mac OS X
* MacOS interfaces to avoid by default
Siri Dhyan Singh <sirid@positivemind.com>
0.13 11/06/03
* Fixed configure.in to properly specify libraries without the leading -l
* Separated the IP/ethernet identifying routine from iftop.c into addrs_ioctl.c
* Added addrs_dlpi.c, dlcommon.c, dlcommon.h to support the STREAMS DataLink
Programming Interface on Solaris
* Hacked options.h, options.c, iftop.c to enable promiscuous_but_choosy mode
which runs the interface in promiscuous mode but filters out non-broadcast
packets not addressed to or from the interface
* Added NEWS, AUTHORS, ChangeLog
* Improved interface auto-detect logic in iftop.c
* Fixed configure.in to not overload prefix in the pcap test section
Jonathan Abbey <jonabbey@ganymeta.org>
* Made errors during IP/MAC address discovery non-fatal
* Added cummulative line totals ("T")
0.12 21/05/03
* Added 1-line display options ("t")
* Added display scrolling ("j", "k")
* Fixed code for obtaining hardware address (on Linux at least)
* Added IP-based direction assignment
0.11 08/01/03
* Added support for token ring networks
* Token ring network direction determination
Martin Garton <Martin.Garton@DCSTRANS.COM>
* Added autoconf/automake build system
* Improved network interface auto selection
0.10 29/10/02
* User selectable sort criteria
* On-the-fly filter code changes
* Shell escape
* Alternative resolver back-ends
* Improved totals display
* Added regexp based screen filtering
* Fixed pause functionality
* Change option names to be more like tcpdump
0.9 22/10/02
* Now works on FreeBSD
* Added service resolution toggle ("R")
* Added on-line help ("h")
* More fixes to rate display
* Improved interface selection (excludes lo:* and vmnet*)
* Added bandwidth-in-bytes option.
0.8 17/10/02
* Added support for displaying port numbers
* Minor fixes to rate display
* Minor fix to netmask handling (specifying /32 was broken)
* Updated RPM spec file
Iain Lea <iain@bricbrac.de>
* Added pause functionality (P)
* Changed behaviour of source/dest traffic aggregation
0.7 02/10/02
* Fixed missing sll.h file.
0.6 28/08/02
* Fixed segfault bug affecting some systems
* Added support for Linux cooked sockets
Michael Bergbauer <michael@noname.franken.de>
0.5 26/08/02
* Added support for monitoring PPP interfaces
* Converted longs to double longs in various places to avoid overflow problems
* Minor bug fixes (usage messages, exit on error)
* Improved selection of default interface when none specified
0.4 16/04/02
* No code changes
* Added RPM spec file
Riku Meskanen <mesrik@cc.jyu.fi>
* Fixes to "make install"
Steve Baker <sjb@ambrielconsulting.com>
0.3 13/04/02
* Fixed segfault bug.
* Added src/dest aggregation.
0.2 02/04/02
* Added -n option to analyse traffic flows across a network boundary.
* Added cumulative traffic totals.
* Graphs now optional.
* UI more responsive to key presses.
* Auto-sizing bar graph scale.
0.1 29/3/02
* First release.
Installation instructions for iftop
$Id: INSTALL,v 1.3 2002/11/04 12:54:16 chris Exp $
iftop is now autoconf/automake-enabled. You should be able to build it on
common platforms by typing `./configure && make'.
There is one gotcha, however, which is that some systems, such as FreeBSD,
lack a working implementation of the gethostbyaddr_r(3) C library function. On
such systems, you may want to use the --with-resolver=ares configure option to
build a version of iftop which uses the ARES asynchronous DNS library for name
resolution. An alternative is to use --with-resolver=netdb_1thread, which will
make iftop run only one name resolution thread. This is not recommended.
On some systems (notably Red Hat Linux) the libpcap header files are installed
under /usr/include/pcap; on these systems, you should manually specify this
when running configure, like this:
$ CPPFLAGS=-I/usr/include/pcap ./configure
For historical interest, the old iftop makefile is included in Makefile.OLD.
#
# Makefile:
# Makefile for iftop.
#
# $Id: Makefile.OLD,v 1.2 2007/03/03 16:01:45 pdw Exp $
#
VERSION = 0.11pre1
# C compiler to use.
#CC = gcc
# Give the location of pcap.h here:
CFLAGS += -I/usr/include/pcap -g
# CFLAGS += -I/usr/pkg/include
# CFLAGS += -pg -a
# Give the location of libpcap here if it's not in one of the standard
# directories:
# LDFLAGS += -L/usr/local/lib
# LDFLAGS += -pg -a
# Do you want to use curses or ncurses? Probably ncurses, unless curses
# is ncurses on your machine.
# CURSES = -lncurses
#CURSES = -lcurses
#
# Name resolution. Sensible systems have gethostbyaddr_r, which is reentrant
# and can be called from several threads of a multithreaded program. Other
# systems don't, or their implementations don't work ([cough] FreeBSD). For
# these you can use gethostbyaddr (not recommended, since then only one thread
# can resolve a name at once), libresolv (not recommended and may not work
# depending on which header files you have), or ares, an asynchronous DNS
# resolution library from
# ftp://athena-dist.mit.edu/pub/ATHENA/ares/
# For systems without a working gethostbyaddr_r, this is recommended.
#
# Leave exactly one of these uncommented, or comment all of them out if you
# don't care about name resolution at all.
#
CFLAGS += -DUSE_GETHOSTBYADDR_R
#CFLAGS += -DUSE_GETHOSTBYADDR
#CFLAGS += -DUSE_LIBRESOLV
#CFLAGS += -DUSE_ARES
#
# On some machines, gethostbyaddr_r returns int; on others, struct hostent*.
# Comment out this line if you are using one of the latter.
#
#CFLAGS += -DGETHOSTBYADD_R_RETURNS_INT
#
# Uncomment if you are using libresolv.
#
#LDLIBS += -lresolv # or /usr/lib/libresolv.a on Linux?
#
# Uncomment if you are using ares.
#
#LDLIBS += -lares
# ... and uncomment these if your libares is in an unusual place.
#CFLAGS += -I/software/include
#LDFLAGS += -L/software/lib
#
# Solaris needs a library to make sockets go and lacks inet_aton.
#
#LDLIBS += -lsocket -lnsl
CFLAGS += -DFAKE_INET_ATON
# PREFIX specifies the base directory for the installation.
PREFIX = /usr/local
#PREFIX = /software
# BINDIR is where the binary lives relative to PREFIX (no leading /).
BINDIR = sbin
# MANDIR is where the manual page goes.
MANDIR = man
#MANDIR = share/man # FHS-ish
# You shouldn't need to change anything below this point.
CFLAGS += -g -Wall "-DIFTOP_VERSION=\"$(VERSION)\""
LDFLAGS += -g #-pthread
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
IFTOP_OBJS = $(IFTOP_SRCS:.c=.o)
IFTOPDUMP_OBJS = $(IFTOPDUMP_SRCS:.c=.o)
iftop: $(IFTOP_OBJS) Makefile
$(CC) $(LDFLAGS) -o $@ $(IFTOP_OBJS) $(LDLIBS)
iftop-dump: $(IFTOPDUMP_OBJS) Makefile
$(CC) $(LDFLAGS) -o $@ $(IFTOPDUMP_OBJS) $(LDLIBS)
#integers.h: integers
# ./integers
install: iftop
install -D iftop $(PREFIX)/$(BINDIR)/iftop
install -D iftop.8 $(PREFIX)/$(MANDIR)/man8/iftop.8
uninstall:
rm -f $(PREFIX)/$(BINDIR)/iftop $(PREFIX)/$(MANDIR)/man8/iftop.8
%.o: %.c Makefile
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f *~ *.o core iftop iftop.spec
tarball: depend $(SRCS) $(HDRS) $(TXTS) $(SPECFILE)
mkdir iftop-$(VERSION)
set -e ; for i in Makefile depend $(SRCS) $(HDRS) $(TXTS) $(SPECFILE) ; do cp $$i iftop-$(VERSION)/$$i ; done
tar cvf - iftop-$(VERSION) | gzip --best > iftop-$(VERSION).tar.gz
rm -rf iftop-$(VERSION)
tags :
etags *.c *.h
depend: $(SRCS)
$(CPP) $(CFLAGS) -MM $(SRCS) > depend
nodepend:
rm -f depend
iftop.spec: iftop.spec.in Makefile
sed 's/__VERSION__/$(VERSION)/' < iftop.spec.in > iftop.spec
include depend
#
# Makefile.am:
# Automake file for iftop.
#
# I don't understand this stuff, so I just stole it from the tpop3d
# distribution. That means that, really, Mark Longair should take credit for
# it.
# -- Chris Lightfoot
#
# $Id: Makefile.am,v 1.11 2010/11/27 17:19:25 pdw Exp $
#
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 \
sorted_list.c threadprof.c ui.c util.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 \
threadprof.h token.h ui.h dlcommon.h stringmap.h \
vector.h cfgfile.h ppp.h
man_MANS = iftop.8
SUBDIRS = config
iftop.cat: iftop.8
(echo -e ".pl 1100i" ; cat iftop.8 ; echo ".pl \n(nlu+10") | groff -Tascii -man > iftop.cat
iftop.spec: iftop.spec.in configure.in
sed 's/__VERSION__/$(VERSION)/' < iftop.spec.in > iftop.spec
## These need to be distributed along with configure:
EXTRA_DIST = bootstrap README ChangeLog AUTHORS COPYING INSTALL TODO \
Makefile.OLD $(man_MANS) iftop.cat iftop.spec
MAINTERCLEANFILES = Makefile.in aclocal.m4 configure configuration.h.in \
stamp-h.in iftop.spec
ACLOCAL = aclocal -I @ac_aux_dir@
This diff is collapsed.
Hm, automake insists on there being a NEWS file in place.
So, here's one, for the time being.
\ No newline at end of file
README for iftop
$Id: README,v 1.8 2003/06/06 22:42:34 pdw Exp $
Read the INSTALL file, manual page and source code for more information.
iftop must be run as root.
KNOWN ISSUES
RedHat 7.2:
There is a bug in the version of ncurses distibuted with RedHat 7.2 that
will cause iftop to segfault. The RPM in RedHat's Rawhide distribution
fixes this.
Slackware 8.1:
You may need to upgrade your libpcap (by updating the tcpdump package)
in order to compile iftop.
FreeBSD 4.7:
This version of FreeBSD lacks a proper gethostbyaddr_r function. You should
choose an alternative name resolution technique using the --with-resolver=...
option to configure.
Solaris:
On Solaris, iftop has to run in promiscuous mode in order to capture
outgoing packets. iftop autoconfigures to run in promiscuous mode on
Solaris, but will filter out non-broadcast packets which are not
addressed to or from localhost. On Solaris, the -p option merely
disables that filter.
If you have some other sort of system that behaves like Solaris in
needing promiscuous mode, you can pass --enable-default-promiscuous to
configure to enable this behavior.
Cf. http://www.tcpdump.org/lists/workers/2002/02/msg00010.html
The version of curses distributed with Solaris may not be sufficient for
iftop's needs. You will probably need ncurses or similar.
Things to do for iftop
$Id: TODO,v 1.27 2011/10/03 18:17:35 pdw Exp $
* Revert old FreeBSD patch, install new one
* Re-fix import order for Mac OS X
* Add configurable offset for DLT_RAW
* IP types other than v4?
* Write config file
* Show several and peaks? Colours?
* Single keypress firewalling of troublesome connections, a la top(1)'s K
to kill?
* Configurable refresh rates.
* Specify max link, then show %age capacity.
* Count obscured connections.
* Startup warnings cause pause.
* Re-merge spec file
This diff is collapsed.
/* hash table */
#include <stdio.h>
#include <stdlib.h>
#include "addr_hash.h"
#include "hash.h"
#include "iftop.h"
#define hash_table_size 256
int compare(void* a, void* b) {
addr_pair* aa = (addr_pair*)a;
addr_pair* bb = (addr_pair*)b;
if (aa->af != bb->af)
return 0;
if (aa->af == AF_INET6) {
return (IN6_ARE_ADDR_EQUAL(&aa->src6, &bb->src6)
&& aa->src_port == bb->src_port
&& IN6_ARE_ADDR_EQUAL(&aa->dst6, &bb->dst6)
&& aa->dst_port == bb->dst_port
&& aa->protocol == bb->protocol);
}
/* AF_INET or unknown. */
return (aa->src.s_addr == bb->src.s_addr
&& aa->src_port == bb->src_port
&& aa->dst.s_addr == bb->dst.s_addr
&& aa->dst_port == bb->dst_port
&& aa->protocol == bb->protocol);
}
static int __inline__ hash_uint32(uint32_t n) {
return ((n & 0x000000FF)
+ ((n & 0x0000FF00) >> 8)
+ ((n & 0x00FF0000) >> 16)
+ ((n & 0xFF000000) >> 24));
}
int hash(void* key) {
int hash;
addr_pair* ap = (addr_pair*)key;
if (ap->af == AF_INET6) {
uint32_t* addr6 = (uint32_t*)ap->src6.s6_addr;
hash = ( hash_uint32(addr6[0])
+ hash_uint32(addr6[1])
+ hash_uint32(addr6[2])
+ hash_uint32(addr6[3])
+ ap->src_port) % 0xFF;
addr6 = (uint32_t*)ap->dst6.s6_addr;
hash = ( hash + hash_uint32(addr6[0])
+ hash_uint32(addr6[1])
+ hash_uint32(addr6[2])
+ hash_uint32(addr6[3])
+ ap->dst_port) % 0xFF;
} else {
in_addr_t addr = ap->src.s_addr;
hash = ( hash_uint32(addr)
+ ap->src_port) % 0xFF;
addr = ap->dst.s_addr;
hash = ( hash + hash_uint32(addr)
+ ap->dst_port) % 0xFF;
}
return hash;
}
void* copy_key(void* orig) {
addr_pair* copy;
copy = xmalloc(sizeof *copy);
*copy = *(addr_pair*)orig;
return copy;
}
void delete_key(void* key) {
free(key);
}
/*
* Allocate and return a hash
*/
hash_type* addr_hash_create() {
hash_type* hash_table;
hash_table = xcalloc(hash_table_size, sizeof *hash_table);
hash_table->size = hash_table_size;
hash_table->compare = &compare;
hash_table->hash = &hash;
hash_table->delete_key = &delete_key;
hash_table->copy_key = &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 {
int af;
unsigned short int protocol;
unsigned short int src_port;
union {
struct in_addr src;
struct in6_addr src6;
};
unsigned short int dst_port;
union {
struct in_addr dst;
struct in6_addr dst6;
};
} addr_pair;
typedef addr_pair key_type; /* index into hash table */
hash_type* addr_hash_create(void);
#endif /* __ADDR_HASH_H_ */
This diff is collapsed.
/*
* addrs_ioctl.c:
*
* Provides the get_addrs_ioctl() function for use on systems that
* support a simple socket ioctl for acquiring low-level ethernet
* information about interfaces.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#if defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ \
|| ( defined __GNUC__ && ! defined __linux__ )
#include <sys/param.h>
#include <sys/sysctl.h>
#include <net/if_dl.h>
#endif
#ifdef USE_GETIFADDRS
#include <ifaddrs.h>
#endif
#include "iftop.h"
/*
* This function identifies the IP address and ethernet address for the requested
* interface
*
* This function returns -1 on catastrophic failure, or a bitwise OR of the
* following values:
*
* 1 - Was able to get the ethernet address
* 2 - Was able to get the IP address
*
* This function should return 3 if all information was found
*/
int
get_addrs_ioctl(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr)
{
int s;
struct ifreq ifr = {};
int got_hw_addr = 0;
int got_ip_addr = 0;
int got_ip6_addr = 0;
#ifdef USE_GETIFADDRS
struct ifaddrs *ifa, *ifas;
#endif
/* -- */
s = socket(AF_INET, SOCK_DGRAM, 0); /* any sort of IP socket will do */
if (s == -1) {
perror("socket");
return -1;
}
fprintf(stderr,"interface: %s\n", interface);
memset(if_hw_addr, 0, 6);
strncpy(ifr.ifr_name, interface, IFNAMSIZ);
#ifdef SIOCGIFHWADDR
if (ioctl(s, SIOCGIFH