Adjusted handling of totals. All promisc packets are now added to the incoming
total.
This commit is contained in:
10
iftop.c
10
iftop.c
@@ -113,6 +113,7 @@ static void handle_packet(char* args, const struct pcap_pkthdr* pkthdr,const cha
|
|||||||
struct ip* iptr;
|
struct ip* iptr;
|
||||||
history_type* ht;
|
history_type* ht;
|
||||||
addr_pair ap;
|
addr_pair ap;
|
||||||
|
int promisc = 0;
|
||||||
|
|
||||||
iptr = (struct ip*)(packet + sizeof(struct ether_header)); /* alignment? */
|
iptr = (struct ip*)(packet + sizeof(struct ether_header)); /* alignment? */
|
||||||
|
|
||||||
@@ -125,13 +126,19 @@ static void handle_packet(char* args, const struct pcap_pkthdr* pkthdr,const cha
|
|||||||
ap.src = iptr->ip_dst;
|
ap.src = iptr->ip_dst;
|
||||||
ap.dst = iptr->ip_src;
|
ap.dst = iptr->ip_src;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* This packet is not from or to this interface. Therefore assume
|
||||||
|
* it was picked up in promisc mode.
|
||||||
|
*/
|
||||||
else if(iptr->ip_src.s_addr < iptr->ip_dst.s_addr) {
|
else if(iptr->ip_src.s_addr < iptr->ip_dst.s_addr) {
|
||||||
ap.src = iptr->ip_src;
|
ap.src = iptr->ip_src;
|
||||||
ap.dst = iptr->ip_dst;
|
ap.dst = iptr->ip_dst;
|
||||||
|
promisc = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ap.src = iptr->ip_dst;
|
ap.src = iptr->ip_dst;
|
||||||
ap.dst = iptr->ip_src;
|
ap.dst = iptr->ip_src;
|
||||||
|
promisc = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -140,12 +147,13 @@ static void handle_packet(char* args, const struct pcap_pkthdr* pkthdr,const cha
|
|||||||
|
|
||||||
if(hash_find(history, &ap, (void**)&ht) == HASH_STATUS_KEY_NOT_FOUND) {
|
if(hash_find(history, &ap, (void**)&ht) == HASH_STATUS_KEY_NOT_FOUND) {
|
||||||
ht = history_create();
|
ht = history_create();
|
||||||
|
ht->promisc = promisc;
|
||||||
hash_insert(history, &ap, ht);
|
hash_insert(history, &ap, ht);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update record */
|
/* Update record */
|
||||||
ht->last_write = history_pos;
|
ht->last_write = history_pos;
|
||||||
if(iptr->ip_src.s_addr < iptr->ip_dst.s_addr) {
|
if(iptr->ip_src.s_addr == ap.src.s_addr) {
|
||||||
ht->sent[history_pos] += ntohs(iptr->ip_len);
|
ht->sent[history_pos] += ntohs(iptr->ip_len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
1
iftop.h
1
iftop.h
@@ -14,6 +14,7 @@ typedef struct {
|
|||||||
long recv[HISTORY_LENGTH];
|
long recv[HISTORY_LENGTH];
|
||||||
long sent[HISTORY_LENGTH];
|
long sent[HISTORY_LENGTH];
|
||||||
int last_write;
|
int last_write;
|
||||||
|
int promisc;
|
||||||
} history_type;
|
} history_type;
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
|
|||||||
10
ui.c
10
ui.c
@@ -190,7 +190,15 @@ void ui_print() {
|
|||||||
tsent = trecv = 0;
|
tsent = trecv = 0;
|
||||||
|
|
||||||
trecv += d->recv[ii];
|
trecv += d->recv[ii];
|
||||||
tsent += d->sent[ii];
|
if(d->promisc == 1) {
|
||||||
|
/* If this was picked up by promiscuous mode, it must
|
||||||
|
* have been incoming
|
||||||
|
*/
|
||||||
|
trecv += d->recv[ii];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tsent += d->sent[ii];
|
||||||
|
}
|
||||||
|
|
||||||
for(j = 0; j < HISTORY_DIVISIONS; j++) {
|
for(j = 0; j < HISTORY_DIVISIONS; j++) {
|
||||||
if(i < history_divs[j]) {
|
if(i < history_divs[j]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user