CBL-Mariner/SPECS-EXTENDED/iftop/iftop-1.0-git20181003.patch

827 строки
29 KiB
Diff

--- iftop-1.0pre4/addrs_dlpi.c 2003-10-15 00:33:45.000000000 +0200
+++ iftop-1.0pre4/addrs_dlpi.c.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -50,7 +50,7 @@
*/
int
-get_addrs_dlpi(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr)
+get_addrs_dlpi(char *interface, u_int8_t if_hw_addr[], struct in_addr *if_ip_addr)
{
int got_hw_addr = 0;
int got_ip_addr = 0;
--- iftop-1.0pre4/addrs_ioctl.c 2014-01-05 19:46:37.000000000 +0100
+++ iftop-1.0pre4/addrs_ioctl.c.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -45,7 +45,7 @@
*/
int
-get_addrs_ioctl(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr)
+get_addrs_ioctl(char *interface, u_int8_t if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr)
{
int s;
struct ifreq ifr = {};
--- iftop-1.0pre4/addrs_ioctl.h 2014-01-05 20:15:09.000000000 +0100
+++ iftop-1.0pre4/addrs_ioctl.h.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -7,6 +7,6 @@
#define __ADDRS_IOCTL_H_
int
-get_addrs_ioctl(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr);
+get_addrs_ioctl(char *interface, u_int8_t if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr);
#endif /* __ADDRS_IOCTL_H_ */
--- iftop-1.0pre4/cfgfile.c 2014-01-05 19:47:07.000000000 +0100
+++ iftop-1.0pre4/cfgfile.c.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -30,7 +30,8 @@
"promiscuous",
"hide-source",
"hide-destination",
- "use-bytes",
+ "use-bytes",
+ "bandwidth-unit",
"sort",
"line-display",
"show-totals",
--- iftop-1.0pre4/ChangeLog 2014-01-19 21:32:50.000000000 +0100
+++ iftop-1.0pre4/ChangeLog.git20181003 2019-07-28 01:42:14.021500079 +0200
@@ -1,11 +1,26 @@
Change log for iftop
-$Id: ChangeLog,v 1.42 2014/01/19 20:32:50 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
+* Choose first running interface, rather than first "up" interface (Redhat #1403025)
+ Robert Scheck <robert@fedoraproject.org>
+
+* Support for unlimited number of lines of output for text mode
+ Roman Hoog Antink <rha@open.ch>
+
+* Fix handling of short packets
+ Frédéric Perrin <fperrin@brocade.com>
+
+* Fix MAC address display
+ Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
+
+* Clean up libpcap on exit
+ Brian Russell <brian.russell@brocade.com>
+
* Remove blinking cursor from UI
Gerrit Renker <renker@ualberta.ca>
--- iftop-1.0pre4/iftop.8 2014-01-05 18:22:39.000000000 +0100
+++ iftop-1.0pre4/iftop.8.git20181003 2019-07-28 01:42:14.024500101 +0200
@@ -3,7 +3,7 @@
.\" iftop.8:
.\" Manual page for iftop.
.\"
-.\" $Id: iftop.8,v 1.31 2014/01/05 17:22:39 pdw Exp $
+.\" $Id$
.\"
.SH NAME
@@ -11,7 +11,7 @@
.SH SYNOPSIS
\fBiftop\fP \fB-h\fP |
-[\fB-nNpblBP\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-F\fP \fInet\fP/\fImask\fP]
+[\fB-nNpblP\fP] [\fB-u\fP \fIunit\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-F\fP \fInet\fP/\fImask\fP]
[\fB-G\fP \fInet6\fP/\fImask6\fP]
.SH DESCRIPTION
\fBiftop\fP listens to network traffic on a named \fIinterface\fP, or on the
@@ -75,8 +75,11 @@
\fB-m\fP \fIlimit\fP
Set the upper limit for the bandwidth scale. Specified as a number with a 'K', 'M' or 'G' suffix.
.TP
+\fB-u\fP \fIbits\fP|\fIbytes\fP|\fIpackets\fP
+Display bandwidth rates in the given unit (per second).
+.TP
\fB-B\fP
-Display bandwidth rates in bytes/sec rather than bits/sec.
+Synonym for \fB-u\fP \fIbits\fP.
.TP
\fB-i\fP \fIinterface\fP
Listen to packets on \fIinterface\fP.
@@ -236,8 +239,11 @@
\fBhide-destination:\fP \fI(yes|no)\fP
Hides destination host names.
.TP
+\fBbandwidth-unit:\fP \fI(bits|bytes|packets)\fP
+Use the specified unit for bandwidth display. The default is bits.
+.TP
\fBuse-bytes:\fP \fI(yes|no)\fP
-Use bytes for bandwidth display, rather than bits.
+\fBuse-bytes: yes\fP is a synonym of \fBbandwidth-unit: packets\fP.
.TP
\fBsort:\fP \fI(2s|10s|40s|source|destination)\fP
Sets which column is used to sort the display.
@@ -315,7 +321,7 @@
Paul Warren <pdw@ex-parrot.com>
.SH VERSION
-$Id: iftop.8,v 1.31 2014/01/05 17:22:39 pdw Exp $
+$Id$
.SH COPYING
This program is free software; you can redistribute it and/or modify
--- iftop-1.0pre4/iftop.c 2014-01-19 21:21:19.000000000 +0100
+++ iftop-1.0pre4/iftop.c.git20181003 2019-07-28 01:42:14.024500101 +0200
@@ -55,7 +55,7 @@
/* ethernet address of interface. */
int have_hw_addr = 0;
-char if_hw_addr[6];
+u_int8_t if_hw_addr[6];
/* IP address of interface */
int have_ip_addr = 0;
@@ -146,7 +146,7 @@
if(t - last_timestamp >= RESOLUTION) {
analyse_data();
if (options.no_curses) {
- if (!options.timed_output || (options.timed_output && t - first_timestamp >= options.timed_output)) {
+ if (!options.timed_output || (t - first_timestamp >= options.timed_output)) {
tui_print();
if (options.timed_output) {
finish(SIGINT);
@@ -249,16 +249,16 @@
}
}
-static void handle_ip_packet(struct ip* iptr, int hw_dir)
+static void handle_ip_packet(struct ip* iptr, int hw_dir, int pld_len)
{
int direction = 0; /* incoming */
+ int len;
history_type* ht;
union {
history_type **ht_pp;
void **void_pp;
} u_ht = { &ht };
addr_pair ap;
- unsigned int len = 0;
struct in6_addr scribdst; /* Scratch pad. */
struct in6_addr scribsrc; /* Scratch pad. */
/* Reinterpret packet type. */
@@ -268,7 +268,21 @@
tick(0);
- if( (IP_V(iptr) ==4 && options.netfilter == 0)
+ /*
+ * Sanity check: drop obviously short packets.
+ * pld_len comes from pcaphdr->len - sizeof(struct l2_header).
+ *
+ * It is assumed that the snaplen (currently hard-coded to 1000) is
+ * big enough to always capture the IP header past the L2 encap, and
+ * that pcap never truncates the packet to less than snaplen; in
+ * other words, that pcaphdr->caplen = MIN(pcaphdr->len, snaplen).
+ */
+ if (pld_len < sizeof (struct ip))
+ return;
+ if (IP_V(iptr) == 6 && pld_len < sizeof (struct ip6_hdr))
+ return;
+
+ if( (IP_V(iptr) == 4 && options.netfilter == 0)
|| (IP_V(iptr) == 6 && options.netfilter6 == 0) ) {
/*
* Net filter is off, so assign direction based on MAC address
@@ -424,21 +438,22 @@
break;
}
-
if(hash_find(history, &ap, u_ht.void_pp) == HASH_STATUS_KEY_NOT_FOUND) {
ht = history_create();
hash_insert(history, &ap, ht);
}
/* Do accounting. */
- switch (IP_V(iptr)) {
- case 4:
- len = ntohs(iptr->ip_len);
- break;
- case 6:
- len = ntohs(ip6tr->ip6_plen) + 40;
+ switch (options.bandwidth_unit) {
+ case OPTION_BW_BITS:
+ case OPTION_BW_BYTES:
+ len = pld_len;
+ break;
+ case OPTION_BW_PKTS:
+ len = 1;
+ break;
default:
- break;
+ return;
}
/* Update record */
@@ -468,7 +483,7 @@
static void handle_raw_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
- handle_ip_packet((struct ip*)packet, -1);
+ handle_ip_packet((struct ip*)packet, -1, pkthdr->len);
}
#ifdef DLT_PFLOG
@@ -482,18 +497,19 @@
hdrlen = BPF_WORDALIGN(hdr->length);
length -= hdrlen;
packet += hdrlen;
- handle_ip_packet((struct ip*)packet, -1);
+ handle_ip_packet((struct ip*)packet, -1, length);
}
#endif
static void handle_null_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
- handle_ip_packet((struct ip*)(packet + 4), -1);
+ handle_ip_packet((struct ip*)(packet + 4), -1, pkthdr->len);
}
-static void handle_llc_packet(const struct llc* llc, int dir) {
-
- struct ip* ip = (struct ip*)((void*)llc + sizeof(struct llc));
+static void handle_llc_packet(const struct llc* llc, int dir, int llclen) {
+ int hdrlen = sizeof(struct llc);
+ int pldlen = llclen - hdrlen;
+ struct ip* ip = (struct ip*)((void*)llc + hdrlen);
/* Taken from tcpdump/print-llc.c */
if(llc->ssap == LLCSAP_SNAP && llc->dsap == LLCSAP_SNAP
@@ -505,11 +521,11 @@
switch(orgcode) {
case OUI_ENCAP_ETHER:
case OUI_CISCO_90:
- handle_ip_packet(ip, dir);
+ handle_ip_packet(ip, dir, pldlen);
break;
case OUI_APPLETALK:
if(et == ETHERTYPE_ATALK) {
- handle_ip_packet(ip, dir);
+ handle_ip_packet(ip, dir, pldlen);
}
break;
default:;
@@ -521,34 +537,36 @@
static void handle_tokenring_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
struct token_header *trp;
+ int hdrlen = 0;
int dir = -1;
trp = (struct token_header *)packet;
if(IS_SOURCE_ROUTED(trp)) {
- packet += RIF_LENGTH(trp);
+ hdrlen += RIF_LENGTH(trp);
}
- packet += TOKEN_HDRLEN;
+ hdrlen += TOKEN_HDRLEN;
+ packet += hdrlen;
if(memcmp(trp->token_shost, if_hw_addr, 6) == 0 ) {
/* packet leaving this i/f */
dir = 1;
- }
- else if(memcmp(trp->token_dhost, if_hw_addr, 6) == 0 || memcmp("\xFF\xFF\xFF\xFF\xFF\xFF", trp->token_dhost, 6) == 0) {
+ }
+ else if(memcmp(trp->token_dhost, if_hw_addr, 6) == 0 || memcmp("\xFF\xFF\xFF\xFF\xFF\xFF", trp->token_dhost, 6) == 0) {
/* packet entering this i/f */
dir = 0;
}
/* Only know how to deal with LLC encapsulated packets */
if(FRAME_TYPE(trp) == TOKEN_FC_LLC) {
- handle_llc_packet((struct llc*)packet, dir);
+ handle_llc_packet((struct llc*)packet, dir, pkthdr->len - hdrlen);
}
}
static void handle_ppp_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
- register u_int length = pkthdr->len;
- register u_int caplen = pkthdr->caplen;
- u_int proto;
+ register u_int length = pkthdr->len;
+ register u_int caplen = pkthdr->caplen;
+ u_int proto;
if (caplen < 2)
return;
@@ -558,14 +576,14 @@
return;
packet += 2;
- length -= 2;
+ length -= 2;
proto = EXTRACT_16BITS(packet);
packet += 2;
length -= 2;
if(proto == PPP_IP || proto == ETHERTYPE_IP || proto == ETHERTYPE_IPV6) {
- handle_ip_packet((struct ip*)packet, -1);
+ handle_ip_packet((struct ip*)packet, -1, length);
}
}
}
@@ -588,24 +606,25 @@
dir=1;
break;
}
- handle_ip_packet((struct ip*)(packet+SLL_HDR_LEN), dir);
+ handle_ip_packet((struct ip*)(packet+SLL_HDR_LEN), dir,
+ thdr->len - SLL_HDR_LEN);
}
#endif /* DLT_LINUX_SLL */
static void handle_eth_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
struct ether_header *eptr;
- int ether_type;
- const unsigned char *payload;
+ int ether_type, hdrlen;
+
eptr = (struct ether_header*)packet;
ether_type = ntohs(eptr->ether_type);
- payload = packet + sizeof(struct ether_header);
+ hdrlen = sizeof(struct ether_header);
if(ether_type == ETHERTYPE_8021Q) {
struct vlan_8021q_header* vptr;
- vptr = (struct vlan_8021q_header*)payload;
+ vptr = (struct vlan_8021q_header*) (packet + hdrlen);
ether_type = ntohs(vptr->ether_type);
- payload += sizeof(struct vlan_8021q_header);
+ hdrlen += sizeof(struct vlan_8021q_header);
}
if(ether_type == ETHERTYPE_IP || ether_type == ETHERTYPE_IPV6) {
@@ -629,8 +648,8 @@
}
/* Distinguishing ip_hdr and ip6_hdr will be done later. */
- iptr = (struct ip*)(payload); /* alignment? */
- handle_ip_packet(iptr, dir);
+ iptr = (struct ip*) (packet + hdrlen); /* alignment? */
+ handle_ip_packet(iptr, dir, pkthdr->len - hdrlen);
}
}
@@ -643,7 +662,8 @@
{
/* 802.11 MAC header is = 34 bytes (not sure if that's universally true) */
/* We could try harder to figure out hardware direction from the MAC header */
- handle_ip_packet((struct ip*)(packet + ((struct radiotap_header *)packet)->it_len + 34),-1);
+ int hdrlen = ((struct radiotap_header *)packet)->it_len + 34;
+ handle_ip_packet((struct ip*)(packet + hdrlen), -1, pkthdr->len - hdrlen);
}
@@ -839,6 +859,8 @@
}
pthread_cancel(thread);
+ pthread_join(thread, NULL);
+ pcap_close(pd);
ui_finish();
--- iftop-1.0pre4/options.c 2014-01-19 21:16:43.000000000 +0100
+++ iftop-1.0pre4/options.c.git20181003 2019-07-28 01:42:14.025500109 +0200
@@ -30,7 +30,7 @@
options_t options;
-char optstr[] = "+i:f:nNF:G:lhpbBPm:c:s:tL:o:";
+char optstr[] = "+i:f:nNF:G:lhpbBu:Pm:c:s:tL:o:";
/* Global options. */
@@ -75,6 +75,13 @@
{ NULL, -1 }
};
+config_enumeration_type bandwidth_unit_enumeration[] = {
+ { "bits", OPTION_BW_BITS },
+ { "bytes", OPTION_BW_BYTES },
+ { "packets", OPTION_BW_PKTS },
+ { NULL, -1 }
+};
+
static int is_bad_interface_name(char *i) {
char **p;
for (p = bad_interface_names; *p; ++p)
@@ -103,7 +110,7 @@
while(nameindex[j].if_index != 0) {
if (strcmp(nameindex[j].if_name, "lo") != 0 && !is_bad_interface_name(nameindex[j].if_name)) {
strncpy(ifr.ifr_name, nameindex[j].if_name, sizeof(ifr.ifr_name));
- if ((s == -1) || (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) || (ifr.ifr_flags & IFF_UP)) {
+ if ((s == -1) || (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) || (ifr.ifr_flags & IFF_RUNNING)) {
i = xstrdup(nameindex[j].if_name);
break;
}
@@ -145,7 +152,7 @@
options.aggregate_dest = 0;
options.paused = 0;
options.showhelp = 0;
- options.bandwidth_in_bytes = 0;
+ options.bandwidth_unit = OPTION_BW_BITS;
options.sort = OPTION_SORT_DIV2;
options.screenfilter = NULL;
options.freezeorder = 0;
@@ -188,7 +195,8 @@
" -p run in promiscuous mode (show traffic between other\n"
" hosts on the same network segment)\n"
" -b don't display a bar graph of traffic\n"
-" -B Display bandwidth in bytes\n"
+" -B display bandwidth in bytes\n"
+" -a display bandwidth in packets\n"
" -i interface listen on named interface\n"
" -f filter code use filter code to select packets to count\n"
" (default: none, but only IP packets are counted)\n"
@@ -271,9 +279,13 @@
break;
case 'B':
- config_set_string("use-bytes", "true");
+ config_set_string("bandwidth-unit", "bytes");
break;
+ case 'u':
+ config_set_string("bandwidth-unit", optarg);
+ break;
+
case 's':
config_set_string("timed-output", optarg);
break;
@@ -370,6 +382,23 @@
return 0;
}
+int options_config_get_bw_unit() {
+ int i;
+
+ if (options_config_get_enum("bandwidth-unit", bandwidth_unit_enumeration,
+ (int*)&options.bandwidth_unit))
+ return 1;
+ /* compatibility with use-bytes / -B */
+ if (options_config_get_bool("use-bytes", &i)) {
+ if (i)
+ options.bandwidth_unit = OPTION_BW_BYTES;
+ else
+ options.bandwidth_unit = OPTION_BW_BITS;
+ return 1;
+ }
+ return 0;
+}
+
int options_config_get_bw_rate(char *directive, long long* result) {
char* units;
long long mult = 1;
@@ -544,7 +573,7 @@
options_config_get_promiscuous();
options_config_get_bool("hide-source", &options.aggregate_src);
options_config_get_bool("hide-destination", &options.aggregate_dest);
- options_config_get_bool("use-bytes", &options.bandwidth_in_bytes);
+ options_config_get_bw_unit();
options_config_get_enum("sort", sort_enumeration, (int*)&options.sort);
options_config_get_enum("line-display", linedisplay_enumeration, (int*)&options.linedisplay);
options_config_get_bool("show-totals", &options.show_totals);
--- iftop-1.0pre4/options.h 2014-01-05 20:16:52.000000000 +0100
+++ iftop-1.0pre4/options.h.git20181003 2019-07-28 01:42:14.025500109 +0200
@@ -34,6 +34,12 @@
OPTION_LINEDISPLAY_ONE_LINE_SENT
} option_linedisplay_t;
+typedef enum {
+ OPTION_BW_BITS,
+ OPTION_BW_BYTES,
+ OPTION_BW_PKTS,
+} option_bw_unit_t;
+
/*
* This structure has to be defined in the same order as the config
* directives in cfgfile.c. Clearly this is EBW.
@@ -59,7 +65,7 @@
int timed_output;
int no_curses;
int num_lines;
- int bandwidth_in_bytes;
+ option_bw_unit_t bandwidth_unit;
option_sort_t sort;
int bar_interval;
--- iftop-1.0pre4/resolver.c 2014-01-19 19:52:33.000000000 +0100
+++ iftop-1.0pre4/resolver.c.git20181003 2019-07-28 01:42:14.025500109 +0200
@@ -438,11 +438,11 @@
char **ch_pp;
void **void_pp;
} u_old = { &old };
- if(hash_find(ns_hash, &addr, u_old.void_pp) == HASH_STATUS_OK) {
+ if(hash_find(ns_hash, &addr.as_addr6, u_old.void_pp) == HASH_STATUS_OK) {
hash_delete(ns_hash, &addr);
xfree(old);
}
- hash_insert(ns_hash, &addr, (void*)hostname);
+ hash_insert(ns_hash, &addr.as_addr6, (void*)hostname);
}
}
@@ -488,7 +488,7 @@
pthread_mutex_lock(&resolver_queue_mutex);
- if(hash_find(ns_hash, raddr, u_hostname.void_pp) == HASH_STATUS_OK) {
+ if(hash_find(ns_hash, &raddr->as_addr6, u_hostname.void_pp) == HASH_STATUS_OK) {
/* Found => already resolved, or on the queue, no need to keep
* it around */
free(raddr);
@@ -497,7 +497,7 @@
hostname = xmalloc(INET6_ADDRSTRLEN);
inet_ntop(af, &raddr->addr, hostname, INET6_ADDRSTRLEN);
- hash_insert(ns_hash, raddr, hostname);
+ hash_insert(ns_hash, &raddr->as_addr6, hostname);
if(((head + 1) % RESOLVE_QUEUE_LENGTH) == tail) {
/* queue full */
--- iftop-1.0pre4/tui.c 2014-01-19 21:07:26.000000000 +0100
+++ iftop-1.0pre4/tui.c.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -73,7 +73,7 @@
printf("\n");
/* Traverse the list of all connections */
- while((nn = sorted_list_next_item(&screen_list, nn)) != NULL && l < options.num_lines) {
+ while((nn = sorted_list_next_item(&screen_list, nn)) != NULL && (!options.num_lines || l < options.num_lines)) {
/* Increment the line counter */
l++;
@@ -87,7 +87,7 @@
/* Send rate per connection */
printf("%4d %s%s", l, host1, " =>");
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10);
}
/* Cumulative sent data per connection */
@@ -97,7 +97,7 @@
/* Receive rate per connection */
printf(" %s%s", host2, " <=");
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10);
}
/* Cumulative received data per connection */
@@ -115,21 +115,21 @@
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((((host_pair_line *)&totals)->sent[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(((host_pair_line *)&totals)->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total receive rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send and receive rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
@@ -141,9 +141,9 @@
/* Peak traffic */
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Peak rate (sent/received/total):");
- readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_in_bytes);
- readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_in_bytes);
- readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_unit);
+ readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_unit);
+ readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_unit);
printf("%s %10s %10s %10s\n", labellong, buf0_10, buf1_10, buf2_10);
/* Cumulative totals */
--- iftop-1.0pre4/ui.c 2014-01-19 19:48:30.000000000 +0100
+++ iftop-1.0pre4/ui.c.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -71,7 +71,7 @@
/* Barchart scales. */
static struct {
- int max, interval;
+ long max; int interval;
} scale[] = {
{ 64000, 10 }, /* 64 kbit/s */
{ 128000, 10 },
@@ -79,7 +79,9 @@
{ 1000000, 10 }, /* 1 Mbit/s */
{ 10000000, 10 },
{ 100000000, 100 },
- { 1000000000, 100 } /* 1 Gbit/s */
+ { 1000000000, 100 }, /* 1 Gbit/s */
+ {10000000000, 100 },
+ {100000000000, 100 }
};
static int rateidx = 0, wantbiggerrate;
@@ -105,7 +107,7 @@
}
/* rate in bits */
-static int get_bar_length(const int rate) {
+static int get_bar_length(const long rate) {
float l;
if (rate <= 0)
return 0;
@@ -153,7 +155,7 @@
char s[40], *p;
int x;
/* This 1024 vs 1000 stuff is just plain evil */
- readable_size(i, s, sizeof s, options.log_scale ? 1000 : 1024, options.bandwidth_in_bytes);
+ readable_size(i, s, sizeof s, options.log_scale ? 1000 : 1024, options.bandwidth_unit);
p = s + strspn(s, " ");
x = get_bar_length(i * 8);
mvaddch(*y + 1, x, ACS_BTEE);
@@ -177,13 +179,13 @@
}
}
-void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, int bytes) {
+void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, option_bw_unit_t unit) {
char buf[10];
float n = 0;
switch(linedisplay) {
case OPTION_LINEDISPLAY_TWO_LINE:
- draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, bytes);
- draw_line_total(sent, recv, y+1, x, OPTION_LINEDISPLAY_ONE_LINE_RECV, bytes);
+ draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, unit);
+ draw_line_total(sent, recv, y+1, x, OPTION_LINEDISPLAY_ONE_LINE_RECV, unit);
break;
case OPTION_LINEDISPLAY_ONE_LINE_SENT:
n = sent;
@@ -196,7 +198,7 @@
break;
}
if(linedisplay != OPTION_LINEDISPLAY_TWO_LINE) {
- readable_size(n, buf, 10, 1024, bytes);
+ readable_size(n, buf, 10, 1024, unit);
mvaddstr(y, x, buf);
}
}
@@ -214,7 +216,7 @@
int x = (COLS - 8 * HISTORY_DIVISIONS);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- draw_line_total(line->sent[j], line->recv[j], y, x, linedisplay, options.bandwidth_in_bytes);
+ draw_line_total(line->sent[j], line->recv[j], y, x, linedisplay, options.bandwidth_unit);
x += 8;
}
@@ -247,7 +249,7 @@
draw_line_totals(y, totals, OPTION_LINEDISPLAY_TWO_LINE);
y += 2;
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((totals->sent[j] + totals->recv[j]) , buf, 10, 1024, options.bandwidth_in_bytes);
+ readable_size((totals->sent[j] + totals->recv[j]) , buf, 10, 1024, options.bandwidth_unit);
mvaddstr(y, x, buf);
x += 8;
}
@@ -262,6 +264,7 @@
static char *line;
static int lcols;
int y = 0;
+ option_bw_unit_t cumunit;
if (dontshowdisplay)
return;
@@ -375,25 +378,31 @@
/* Cummulative totals */
mvaddstr(y, 16, "cum: ");
- readable_size(history_totals.total_sent, line, 10, 1024, 1);
+ /* Previous versions of iftop always displayed totals in bytes, even when
+ use-bytes = false. Stay compatible when the default unit hasn't been
+ changed. */
+ cumunit = options.bandwidth_unit;
+ if (cumunit == OPTION_BW_BITS)
+ cumunit = OPTION_BW_BYTES;
+ readable_size(history_totals.total_sent, line, 10, 1024, cumunit);
mvaddstr(y, 22, line);
- readable_size(history_totals.total_recv, line, 10, 1024, 1);
+ readable_size(history_totals.total_recv, line, 10, 1024, cumunit);
mvaddstr(y+1, 22, line);
- readable_size(history_totals.total_recv + history_totals.total_sent, line, 10, 1024, 1);
+ readable_size(history_totals.total_recv + history_totals.total_sent, line, 10, 1024, cumunit);
mvaddstr(y+2, 22, line);
/* peak traffic */
mvaddstr(y, 32, "peak: ");
- readable_size(peaksent / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peaksent / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y, 39, line);
- readable_size(peakrecv / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peakrecv / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y+1, 39, line);
- readable_size(peaktotal / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peaktotal / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y+2, 39, line);
mvaddstr(y, COLS - 8 * HISTORY_DIVISIONS - 8, "rates:");
--- iftop-1.0pre4/ui_common.c 2014-01-05 19:40:46.000000000 +0100
+++ iftop-1.0pre4/ui_common.c.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -21,8 +21,11 @@
int history_divs[HISTORY_DIVISIONS] = {1, 5, 20};
#define UNIT_DIVISIONS 4
-char* unit_bits[UNIT_DIVISIONS] = { "b", "Kb", "Mb", "Gb"};
-char* unit_bytes[UNIT_DIVISIONS] = { "B", "KB", "MB", "GB"};
+char* unit_disp[][UNIT_DIVISIONS] = {
+ [OPTION_BW_BITS] = { "b", "Kb", "Mb", "Gb"},
+ [OPTION_BW_BYTES] = { "B", "KB", "MB", "GB"},
+ [OPTION_BW_PKTS] = { "p", "Kp", "Mp", "GB"},
+};
extern hash_type* history;
extern int history_pos;
@@ -121,29 +124,34 @@
/*
* Format a data size in human-readable format
*/
-void readable_size(float n, char* buf, int bsize, int ksize, int bytes) {
+void readable_size(float n, char* buf, int bsize, int ksize,
+ option_bw_unit_t unit) {
int i = 0;
float size = 1;
/* Convert to bits? */
- if(bytes == 0) {
+ if (unit == OPTION_BW_BITS) {
n *= 8;
}
+ /* Force power of ten for pps */
+ if (unit == OPTION_BW_PKTS)
+ ksize = 1000;
+
while(1) {
if(n < size * 1000 || i >= UNIT_DIVISIONS - 1) {
- snprintf(buf, bsize, " %4.0f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
+ snprintf(buf, bsize, " %4.0f%s", n / size, unit_disp[unit][i]);
break;
}
i++;
size *= ksize;
if(n < size * 10) {
- snprintf(buf, bsize, " %4.2f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
+ snprintf(buf, bsize, " %4.2f%s", n / size, unit_disp[unit][i]);
break;
}
else if(n < size * 100) {
- snprintf(buf, bsize, " %4.1f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
+ snprintf(buf, bsize, " %4.1f%s", n / size, unit_disp[unit][i]);
break;
}
}
@@ -263,9 +271,6 @@
} u_screen_line = { &screen_line };
addr_pair ap;
int i;
- int tsent, trecv;
- tsent = trecv = 0;
-
ap = *(addr_pair*)n->key;
--- iftop-1.0pre4/ui_common.h 2014-01-01 15:17:08.000000000 +0100
+++ iftop-1.0pre4/ui_common.h.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -43,6 +43,6 @@
void analyse_data(void);
void screen_list_init(void);
void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port, unsigned int protocol, int L, int unspecified_as_star);
-void readable_size(float, char*, int, int, int);
+void readable_size(float, char*, int, int, option_bw_unit_t);
#endif /* __UI_COMMON_H_ */