[Iftop-users] measuring bandwith ?

raptor raptor at tvskat.net
Sun, 2 May 2004 17:24:27 +0300


hi,

I'm tring to use libpcap to measure bandwith..
the reason I need this is to launch this small program that will measure
the bandwith usage (tcpdump filter based).. it will not be ncurses based,,

My problem is how to set this program to capture the traffic for 10 seconds
for example ... and most importanly how u calculate that 1 second is passed,
so that u calc "kbps"...

Could u explain...(i'm not a C programmer but have idea what is all about)

Second question I've used pcap sniffer.c example from tcpdump.org, and
modified so that i calculate the packet sizes in two different ways i.e :

	total_len2 += ntohs(ip->ip_len);
	total_len += header->len;

into got_packet() callback function... I see that iftop uses the first one, is it more
correct...

tia..

PS. One second question is what if I put several filters in text files and loop over them
i.e.  read the first filter, setfilter(), mesure for 10 sec, then read the second filter...etc.etc..
will there be some calculation error 'cause I'm switching filters i.e. will I have to wait some 
time before start measuting say  :
 1. setfilter() 
 2. wait 1 sec
 3. measure 10 sec
 4. goto 1