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

Imported Upstream version 1.0~pre2

Another file that automake insists on.
Written by
Paul Warren,
Chris Lightfoot,
Mangled for Solaris by
Jonathan Abbey,
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.
* Various typos in the UI
Gerben Roest <>
* Documentation fixes
A. Costa <> (via Debian)
* Fix for armeb specific bug
Lennert Buytenhek <> (via Debian)
* Fix frozen order drives line totals crazy.
Max Alekseyev <> (via Debian)
* Fix for crash on arm.
Joey Hess <> (via Debian)
* Fixed behaviour of "-b" option.
Eric Cooper <> (via Debian)
* Support for PFLOG Interfaces
Richard Tóth <>
* Support for IPv6
* Fix for performance issue with address hashing
* Fix for failing link address detection for GNU/kfreebsd
Mats Erik Andersson <>
* Improved behaviour of sort in sent/recv only mode
Damián Viano <>
* FreeBSD compilation fix
* IPv6 reverse resolution
Frédéric Perrin <>
* Improved IPv6 code (removed s6_addr32 dependency)
* Fixed support for DLT_NULL
Scott Bertilson <>
* Typo in usage message
* Workaround for PuTTY issue (
Robert Scheck <>
* 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 <>
* 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 <>
* 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 <>
* Fix for hash table memory handling bug (caused segfaults on Mac OS X)
* Header fixes for Mac OS X
Ken McLeod <>
* Fixes for compile time errors apparent on Mac OS 10.4.3
Georg Schwarz <>
* Improvements to configure to support cross-compilation
* Addition of "NO_SYSTEM" compiler flag to prevent subshell execution
Tim Freeman <>
* Fix to get hardware address on FreeBSD and OpenBSD
Nicolas Bernard <>
* Added 802.1q VLAN support
Jacek Konieczny <>
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 <>
* Fixed behaviour of -n and -N options
Klaus Sperner <>
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 <>
* Updated RPM spec file
Richard Lucassen <>
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 ==
* Configure/compilation fixes for Mac OS X
* MacOS interfaces to avoid by default
Siri Dhyan Singh <>
0.13 11/06/03
* Fixed 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 to not overload prefix in the pcap test section
Jonathan Abbey <>
* 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 <>
* 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 <>
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 <>
* Fixes to "make install"
Steve Baker <>
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
# 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.
# On some machines, gethostbyaddr_r returns int; on others, struct hostent*.
# Comment out this line if you are using one of the latter.
# 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
# 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.
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
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
SPECFILE = iftop.spec
iftop: $(IFTOP_OBJS) Makefile
iftop-dump: $(IFTOPDUMP_OBJS) Makefile
#integers.h: integers
# ./integers
install: iftop
install -D iftop $(PREFIX)/$(BINDIR)/iftop
install -D iftop.8 $(PREFIX)/$(MANDIR)/man8/iftop.8
rm -f $(PREFIX)/$(BINDIR)/iftop $(PREFIX)/$(MANDIR)/man8/iftop.8
%.o: %.c Makefile
$(CC) $(CFLAGS) -c -o $@ $<
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
rm -f depend
iftop.spec: Makefile
sed 's/__VERSION__/$(VERSION)/' < > iftop.spec
include depend
# 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:,v 1.11 2010/11/27 17:19:25 pdw Exp $
sbin_PROGRAMS = iftop
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.8
(echo -e ".pl 1100i" ; cat iftop.8 ; echo ".pl \n(nlu+10") | groff -Tascii -man >
sed 's/__VERSION__/$(VERSION)/' < > iftop.spec
## These need to be distributed along with configure:
Makefile.OLD $(man_MANS) iftop.spec
MAINTERCLEANFILES = aclocal.m4 configure \ 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.
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.
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.
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) {
* 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;
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>
#include <ifaddrs.h>
#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
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;
struct ifaddrs *ifa, *ifas;
/* -- */
s = socket(AF_INET, SOCK_DGRAM, 0); /* any sort of IP socket will do */
if (s == -1) {
return -1;
fprintf(stderr,"interface: %s\n", interface);
memset(if_hw_addr, 0, 6);
strncpy(ifr.ifr_name, interface, IFNAMSIZ);
if (ioctl(s, SIOCGIFH