The first two patches are fixes, the third one is cleanup and the last one is enhancenment. The last one also cleans up the mess with set_barptr().
Please, apply.
v2: use enum in call to update_proto_counter() v1: initial version
Vitezslav Samel (4): serv.c: updateportent(): count packets even if dport is the same as sport serv.c: writeutslog(): fix the printed rate in non-KBITS mode serv.c: use struct proto_counter to count packets and bytes serv.c: use struct rate to compute traffic flow rate
src/serv.c | 289 +++++++++++++++++++++++++----------------------------------- 1 files changed, 119 insertions(+), 170 deletions(-)
We must count packets even if destination port is the same as source port otherwise we won't have traffic (eg. UDP/123 <--> UDP/123) counters accurate.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/serv.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/serv.c b/src/serv.c index 6777460..7d1470a 100644 --- a/src/serv.c +++ b/src/serv.c @@ -395,11 +395,9 @@ static void updateportent(struct portlist *list, unsigned int protocol, if (dport_listent == NULL) return;
- if (dport_listent != sport_listent) { - dport_listent->count++; - dport_listent->bcount += br; - dport_listent->spans.spanbr += br; - } + dport_listent->count++; + dport_listent->bcount += br; + dport_listent->spans.spanbr += br;
dport_listent->ibcount += br; dport_listent->spans.spanbr_in += br;
inrate should be calculated from ptmp->ibcount and totalrate should be calculated from ptmp->bcount.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/serv.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/serv.c b/src/serv.c index 7d1470a..502c944 100644 --- a/src/serv.c +++ b/src/serv.c @@ -119,13 +119,13 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, (float) (now - ptmp->proto_starttime); } else { inrate = - (float) (ptmp->obcount / 1024) / + (float) (ptmp->ibcount / 1024) / (float) (now - ptmp->proto_starttime); outrate = (float) (ptmp->obcount / 1024) / (float) (now - ptmp->proto_starttime); totalrate = - (float) (ptmp->obcount / 1024) / + (float) (ptmp->bcount / 1024) / (float) (now - ptmp->proto_starttime); } }
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/serv.c | 139 +++++++++++++++++++++++++++--------------------------------- 1 files changed, 63 insertions(+), 76 deletions(-)
diff --git a/src/serv.c b/src/serv.c index 502c944..593ed0d 100644 --- a/src/serv.c +++ b/src/serv.c @@ -33,6 +33,7 @@ serv.c - TCP/UDP port statistics module #include "logvars.h" #include "error.h" #include "bar.h" +#include "counters.h"
#define SCROLLUP 0 #define SCROLLDOWN 1 @@ -51,15 +52,10 @@ struct portlistent { unsigned int protocol; char servname[11]; unsigned int idx; - unsigned long long count; - unsigned long long bcount; - unsigned long long icount; - unsigned long long ibcount; - unsigned long long ocount; - unsigned long long obcount; + struct proto_counter serv_count; + struct proto_counter span; time_t starttime; time_t proto_starttime; - struct serv_spans spans; struct portlistent *prev_entry; struct portlistent *next_entry; }; @@ -109,23 +105,23 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, else { if (units == KBITS) { inrate = - (float) (ptmp->ibcount * 8 / 1000) / + (float) (ptmp->serv_count.proto_in.pc_bytes * 8 / 1000) / (float) (now - ptmp->proto_starttime); outrate = - (float) (ptmp->obcount * 8 / 1000) / + (float) (ptmp->serv_count.proto_out.pc_bytes * 8 / 1000) / (float) (now - ptmp->proto_starttime); totalrate = - (float) (ptmp->bcount * 8 / 1000) / + (float) (ptmp->serv_count.proto_total.pc_bytes * 8 / 1000) / (float) (now - ptmp->proto_starttime); } else { inrate = - (float) (ptmp->ibcount / 1024) / + (float) (ptmp->serv_count.proto_in.pc_bytes / 1024) / (float) (now - ptmp->proto_starttime); outrate = - (float) (ptmp->obcount / 1024) / + (float) (ptmp->serv_count.proto_out.pc_bytes / 1024) / (float) (now - ptmp->proto_starttime); totalrate = - (float) (ptmp->bcount / 1024) / + (float) (ptmp->serv_count.proto_total.pc_bytes / 1024) / (float) (now - ptmp->proto_starttime); } } @@ -135,20 +131,23 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, else fprintf(fd, "UDP/%s: ", ptmp->servname);
- fprintf(fd, "%llu packets, %llu bytes total", ptmp->count, - ptmp->bcount); + fprintf(fd, "%llu packets, %llu bytes total", + ptmp->serv_count.proto_total.pc_packets, + ptmp->serv_count.proto_total.pc_bytes);
if (totalrate >= 0.0) fprintf(fd, ", %.2f %s", totalrate, dispmode(units));
- fprintf(fd, "; %llu packets, %llu bytes incoming", ptmp->icount, - ptmp->ibcount); + fprintf(fd, "; %llu packets, %llu bytes incoming", + ptmp->serv_count.proto_in.pc_packets, + ptmp->serv_count.proto_in.pc_bytes);
if (inrate >= 0.0) fprintf(fd, ", %.2f %s", inrate, dispmode(units));
- fprintf(fd, "; %llu packets, %llu bytes outgoing", ptmp->ocount, - ptmp->obcount); + fprintf(fd, "; %llu packets, %llu bytes outgoing", + ptmp->serv_count.proto_out.pc_packets, + ptmp->serv_count.proto_out.pc_bytes);
if (outrate >= 0.0) fprintf(fd, ", %.2f %s", outrate, dispmode(units)); @@ -232,9 +231,7 @@ static struct portlistent *addtoportlist(struct portlist *list,
servlook(servnames, htons(port), protocol, ptemp->servname, 10);
- ptemp->count = ptemp->bcount = 0; - ptemp->icount = ptemp->ibcount = 0; - ptemp->ocount = ptemp->obcount = 0; + memset(&ptemp->serv_count, 0, sizeof(ptemp->serv_count));
list->count++; ptemp->idx = list->count; @@ -328,17 +325,17 @@ static void printportent(struct portlist *list, struct portlistent *entry, wprintw(list->win, "/%s ", entry->servname); wattrset(list->win, highattr); wmove(list->win, target_row, 17 * screen_scale); - printlargenum(entry->count, list->win); + printlargenum(entry->serv_count.proto_total.pc_packets, list->win); wmove(list->win, target_row, 27 * screen_scale); - printlargenum(entry->bcount, list->win); + printlargenum(entry->serv_count.proto_total.pc_bytes, list->win); wmove(list->win, target_row, 37 * screen_scale); - printlargenum(entry->icount, list->win); + printlargenum(entry->serv_count.proto_in.pc_packets, list->win); wmove(list->win, target_row, 47 * screen_scale); - printlargenum(entry->ibcount, list->win); + printlargenum(entry->serv_count.proto_in.pc_bytes, list->win); wmove(list->win, target_row, 57 * screen_scale); - printlargenum(entry->ocount, list->win); + printlargenum(entry->serv_count.proto_out.pc_packets, list->win); wmove(list->win, target_row, 67 * screen_scale); - printlargenum(entry->obcount, list->win); + printlargenum(entry->serv_count.proto_out.pc_bytes, list->win); }
static void destroyportlist(struct portlist *list) @@ -365,6 +362,10 @@ static void updateportent(struct portlist *list, unsigned int protocol, { struct portlistent *sport_listent = NULL; struct portlistent *dport_listent = NULL; + enum { + PORT_INCOMING = 0, + PORT_OUTGOING + };
if (goodport(sport, ports)) { sport_listent = inportlist(list, protocol, sport); @@ -376,13 +377,8 @@ static void updateportent(struct portlist *list, unsigned int protocol, if (sport_listent == NULL) return;
- sport_listent->count++; - sport_listent->bcount += br; - sport_listent->spans.spanbr += br; - - sport_listent->obcount += br; - sport_listent->spans.spanbr_out += br; - sport_listent->ocount++; + update_proto_counter(&sport_listent->serv_count, PORT_OUTGOING, br); + update_proto_counter(&sport_listent->span, PORT_OUTGOING, br); }
if (goodport(dport, ports)) { @@ -395,20 +391,13 @@ static void updateportent(struct portlist *list, unsigned int protocol, if (dport_listent == NULL) return;
- dport_listent->count++; - dport_listent->bcount += br; - dport_listent->spans.spanbr += br; - - dport_listent->ibcount += br; - dport_listent->spans.spanbr_in += br; - dport_listent->icount++; - } - if (sport_listent != NULL || dport_listent != NULL) { - if (sport_listent != NULL) - printportent(list, sport_listent, idx); - if (dport_listent != NULL && dport_listent != sport_listent) - printportent(list, dport_listent, idx); + update_proto_counter(&dport_listent->serv_count, PORT_INCOMING, br); + update_proto_counter(&dport_listent->span, PORT_INCOMING, br); } + if (sport_listent != NULL) + printportent(list, sport_listent, idx); + if (dport_listent != NULL && dport_listent != sport_listent) + printportent(list, dport_listent, idx); }
/* @@ -468,22 +457,22 @@ static unsigned long long qp_getkey(struct portlistent *entry, int ch) result = entry->port; break; case 'B': - result = entry->bcount; + result = entry->serv_count.proto_total.pc_bytes; break; case 'O': - result = entry->ibcount; + result = entry->serv_count.proto_in.pc_bytes; break; case 'M': - result = entry->obcount; + result = entry->serv_count.proto_out.pc_bytes; break; case 'P': - result = entry->count; + result = entry->serv_count.proto_total.pc_packets; break; case 'T': - result = entry->icount; + result = entry->serv_count.proto_in.pc_packets; break; case 'F': - result = entry->ocount; + result = entry->serv_count.proto_out.pc_packets; break; }
@@ -746,26 +735,24 @@ static void update_serv_rates(struct portlist *list, WINDOW * win, int actmode,
if (actmode == KBITS) { inrate = - (float) (list->barptr->spans.spanbr_in * 8 / 1000) / + (float) (list->barptr->span.proto_in.pc_bytes * 8 / 1000) / (float) (now - list->barptr->starttime); outrate = - (float) (list->barptr->spans.spanbr_out * 8 / 1000) / + (float) (list->barptr->span.proto_out.pc_bytes * 8 / 1000) / (float) (now - list->barptr->starttime); totalrate = - (float) (list->barptr->spans.spanbr * 8 / 1000) / + (float) (list->barptr->span.proto_total.pc_bytes * 8 / 1000) / (float) (now - list->barptr->starttime); } else { inrate = - (float) (list->barptr->spans.spanbr_in / 1024) / + (float) (list->barptr->span.proto_in.pc_bytes / 1024) / (float) (now - list->barptr->starttime); outrate = - (float) (list->barptr->spans.spanbr_out / 1024) / + (float) (list->barptr->span.proto_out.pc_bytes / 1024) / (float) (now - list->barptr->starttime); totalrate = - (float) (list->barptr->spans.spanbr / 1024) / (float) (now - - list-> - barptr-> - starttime); + (float) (list->barptr->span.proto_total.pc_bytes / 1024) / + (float) (now - list->barptr->starttime); }
wattrset(win, IPSTATLABELATTR); @@ -777,7 +764,7 @@ static void update_serv_rates(struct portlist *list, WINDOW * win, int actmode, mvwprintw(win, 0, 46, "%10.2f", outrate); mvwprintw(win, 0, 61, "%10.2f", totalrate);
- memset(&(list->barptr->spans), 0, sizeof(struct serv_spans)); + memset(&list->barptr->span, 0, sizeof(list->barptr->span)); list->barptr->starttime = time(NULL); *cleared = 0; } @@ -982,8 +969,8 @@ void servmon(char *ifname, const struct OPTIONS *options, set_barptr((void *) &(list.barptr), list.barptr->prev_entry, &(list.barptr->prev_entry->starttime), - &(list.barptr->prev_entry->spans), - sizeof(struct serv_spans), + &list.barptr->prev_entry->span, + sizeof(list.barptr->prev_entry->span), statwin, &statcleared, statx); printportent(&list, serv_tmp, idx);
@@ -1003,8 +990,8 @@ void servmon(char *ifname, const struct OPTIONS *options, set_barptr((void *) &(list.barptr), list.barptr->next_entry, &(list.barptr->next_entry->starttime), - &(list.barptr->next_entry->spans), - sizeof(struct serv_spans), + &list.barptr->next_entry->span, + sizeof(list.barptr->next_entry->span), statwin, &statcleared, statx); printportent(&list,serv_tmp, idx);
@@ -1025,8 +1012,8 @@ void servmon(char *ifname, const struct OPTIONS *options, set_barptr((void *) &(list.barptr), list.lastvisible, &(list.lastvisible->starttime), - &(list.lastvisible->spans), - sizeof(struct serv_spans), + &list.lastvisible->span, + sizeof(list.lastvisible->span), statwin, &statcleared, statx); list.baridx = list.lastvisible->idx - idx + 1;
@@ -1042,8 +1029,8 @@ void servmon(char *ifname, const struct OPTIONS *options, set_barptr((void *) &(list.barptr), list.firstvisible, &(list.firstvisible->starttime), - &(list.firstvisible->spans), - sizeof(struct serv_spans), + &list.firstvisible->span, + sizeof(list.firstvisible->span), statwin, &statcleared, statx); list.baridx = 1;
@@ -1079,8 +1066,8 @@ void servmon(char *ifname, const struct OPTIONS *options, list.firstvisible, &(list.firstvisible-> starttime), - &(list.firstvisible->spans), - sizeof(struct serv_spans), + &list.firstvisible->span, + sizeof(list.firstvisible->span), statwin, &statcleared, statx); list.baridx = 1; @@ -1133,8 +1120,8 @@ void servmon(char *ifname, const struct OPTIONS *options, if ((list.barptr == NULL) && (list.head != NULL)) { set_barptr((void *) &(list.barptr), list.head, &(list.head->starttime), - &(list.head->spans), - sizeof(struct serv_spans), statwin, + &list.head->span, + sizeof(list.head->span), statwin, &statcleared, statx); list.baridx = 1; }
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/serv.c | 200 +++++++++++++++++++++++++----------------------------------- 1 files changed, 82 insertions(+), 118 deletions(-)
diff --git a/src/serv.c b/src/serv.c index 593ed0d..73dc3b7 100644 --- a/src/serv.c +++ b/src/serv.c @@ -32,8 +32,8 @@ serv.c - TCP/UDP port statistics module #include "packet.h" #include "logvars.h" #include "error.h" -#include "bar.h" #include "counters.h" +#include "rate.h"
#define SCROLLUP 0 #define SCROLLDOWN 1 @@ -54,8 +54,14 @@ struct portlistent { unsigned int idx; struct proto_counter serv_count; struct proto_counter span; - time_t starttime; - time_t proto_starttime; + + struct timeval starttime; + struct timeval proto_starttime; + + struct rate rate; + struct rate rate_in; + struct rate rate_out; + struct portlistent *prev_entry; struct portlistent *next_entry; }; @@ -92,39 +98,17 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, { char atime[TIME_TARGET_MAX]; struct portlistent *ptmp = list; - float inrate, outrate, totalrate; - time_t now = time(NULL); + struct timeval now; + + gettimeofday(&now, NULL);
genatime(time(NULL), atime);
fprintf(fd, "\n*** TCP/UDP traffic log, generated %s\n\n", atime);
while (ptmp != NULL) { - if (now - ptmp->proto_starttime < 5) - inrate = outrate = totalrate = -1.0; - else { - if (units == KBITS) { - inrate = - (float) (ptmp->serv_count.proto_in.pc_bytes * 8 / 1000) / - (float) (now - ptmp->proto_starttime); - outrate = - (float) (ptmp->serv_count.proto_out.pc_bytes * 8 / 1000) / - (float) (now - ptmp->proto_starttime); - totalrate = - (float) (ptmp->serv_count.proto_total.pc_bytes * 8 / 1000) / - (float) (now - ptmp->proto_starttime); - } else { - inrate = - (float) (ptmp->serv_count.proto_in.pc_bytes / 1024) / - (float) (now - ptmp->proto_starttime); - outrate = - (float) (ptmp->serv_count.proto_out.pc_bytes / 1024) / - (float) (now - ptmp->proto_starttime); - totalrate = - (float) (ptmp->serv_count.proto_total.pc_bytes / 1024) / - (float) (now - ptmp->proto_starttime); - } - } + unsigned long secs = timeval_diff_msec(&now, &ptmp->proto_starttime) / 1000UL; + char bps_string[64];
if (ptmp->protocol == IPPROTO_TCP) fprintf(fd, "TCP/%s: ", ptmp->servname); @@ -135,22 +119,25 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, ptmp->serv_count.proto_total.pc_packets, ptmp->serv_count.proto_total.pc_bytes);
- if (totalrate >= 0.0) - fprintf(fd, ", %.2f %s", totalrate, dispmode(units)); + rate_print(ptmp->serv_count.proto_total.pc_bytes / secs, units, + bps_string, sizeof(bps_string)); + fprintf(fd, ", %s", bps_string);
fprintf(fd, "; %llu packets, %llu bytes incoming", ptmp->serv_count.proto_in.pc_packets, ptmp->serv_count.proto_in.pc_bytes);
- if (inrate >= 0.0) - fprintf(fd, ", %.2f %s", inrate, dispmode(units)); + rate_print(ptmp->serv_count.proto_in.pc_bytes / secs, units, + bps_string, sizeof(bps_string)); + fprintf(fd, ", %s", bps_string);
fprintf(fd, "; %llu packets, %llu bytes outgoing", ptmp->serv_count.proto_out.pc_packets, ptmp->serv_count.proto_out.pc_bytes);
- if (outrate >= 0.0) - fprintf(fd, ", %.2f %s", outrate, dispmode(units)); + rate_print(ptmp->serv_count.proto_out.pc_bytes / secs, units, + bps_string, sizeof(bps_string)); + fprintf(fd, ", %s", bps_string);
fprintf(fd, "\n\n"); ptmp = ptmp->next_entry; @@ -224,6 +211,9 @@ static struct portlistent *addtoportlist(struct portlist *list,
ptemp->protocol = protocol; ptemp->port = port; /* This is used in checks later. */ + rate_init(&ptemp->rate, 5); + rate_init(&ptemp->rate_in, 5); + rate_init(&ptemp->rate_out, 5);
/* * Obtain appropriate service name @@ -236,7 +226,7 @@ static struct portlistent *addtoportlist(struct portlist *list, list->count++; ptemp->idx = list->count;
- ptemp->proto_starttime = time(NULL); + gettimeofday(&ptemp->proto_starttime, NULL);
if (list->count <= LINES - 5) list->lastvisible = ptemp; @@ -347,6 +337,9 @@ static void destroyportlist(struct portlist *list) ctmp = list->head->next_entry;
while (ptmp != NULL) { + rate_destroy(&ptmp->rate_out); + rate_destroy(&ptmp->rate_in); + rate_destroy(&ptmp->rate); free(ptmp); ptmp = ctmp;
@@ -727,46 +720,35 @@ static void show_portsort_keywin(WINDOW ** win, PANEL ** panel) doupdate(); }
-static void update_serv_rates(struct portlist *list, WINDOW * win, int actmode, - int *cleared) +static void print_serv_rates(struct portlistent *ple, WINDOW *win, int actmode) { - float inrate, outrate, totalrate; - time_t now = time(NULL); - - if (actmode == KBITS) { - inrate = - (float) (list->barptr->span.proto_in.pc_bytes * 8 / 1000) / - (float) (now - list->barptr->starttime); - outrate = - (float) (list->barptr->span.proto_out.pc_bytes * 8 / 1000) / - (float) (now - list->barptr->starttime); - totalrate = - (float) (list->barptr->span.proto_total.pc_bytes * 8 / 1000) / - (float) (now - list->barptr->starttime); - } else { - inrate = - (float) (list->barptr->span.proto_in.pc_bytes / 1024) / - (float) (now - list->barptr->starttime); - outrate = - (float) (list->barptr->span.proto_out.pc_bytes / 1024) / - (float) (now - list->barptr->starttime); - totalrate = - (float) (list->barptr->span.proto_total.pc_bytes / 1024) / - (float) (now - list->barptr->starttime); - } + char buf[64];
wattrset(win, IPSTATLABELATTR); - mvwprintw(win, 0, 1, - "Protocol data rates (%s): in out total", - dispmode(actmode)); + mvwprintw(win, 0, 1, "Protocol data rates:"); + mvwprintw(win, 0, 36, "total"); + mvwprintw(win, 0, 57, "in"); + mvwprintw(win, 0, 76, "out"); + wattrset(win, IPSTATATTR); - mvwprintw(win, 0, 31, "%10.2f", inrate); - mvwprintw(win, 0, 46, "%10.2f", outrate); - mvwprintw(win, 0, 61, "%10.2f", totalrate); + rate_print(rate_get_average(&ple->rate), actmode, buf, sizeof(buf)); + mvwprintw(win, 0, 21, "%s", buf); + rate_print(rate_get_average(&ple->rate_in), actmode, buf, sizeof(buf)); + mvwprintw(win, 0, 42, "%s", buf); + rate_print(rate_get_average(&ple->rate_out), actmode, buf, sizeof(buf)); + mvwprintw(win, 0, 61, "%s", buf); +}
- memset(&list->barptr->span, 0, sizeof(list->barptr->span)); - list->barptr->starttime = time(NULL); - *cleared = 0; +static void update_serv_rates(struct portlist *list, unsigned long msecs) +{ + /* update rates of all portlistents */ + for (struct portlistent *ple = list->head; ple != NULL; ple = ple->next_entry) { + rate_add_rate(&ple->rate, ple->span.proto_total.pc_bytes, msecs); + rate_add_rate(&ple->rate_in, ple->span.proto_in.pc_bytes, msecs); + rate_add_rate(&ple->rate_out, ple->span.proto_out.pc_bytes, msecs); + + memset(&ple->span, 0, sizeof(ple->span)); + } }
/* @@ -787,6 +769,7 @@ void servmon(char *ifname, const struct OPTIONS *options, unsigned int dport = 0;
struct timeval tv; + struct timeval tv_rate; time_t starttime, startlog, timeint; time_t now; unsigned long long unow; @@ -799,7 +782,6 @@ void servmon(char *ifname, const struct OPTIONS *options,
struct portlist list; struct portlistent *serv_tmp; - int statcleared = 0;
FILE *logfile = NULL;
@@ -813,8 +795,6 @@ void servmon(char *ifname, const struct OPTIONS *options,
char sp_buf[10];
- const int statx = 1; - int fd;
struct porttab *ports; @@ -889,6 +869,7 @@ void servmon(char *ifname, const struct OPTIONS *options,
exitloop = 0; gettimeofday(&tv, NULL); + tv_rate = tv; starttime = startlog = timeint = tv.tv_sec;
wattrset(statwin, IPSTATATTR); @@ -927,12 +908,17 @@ void servmon(char *ifname, const struct OPTIONS *options, } }
- if (list.barptr != NULL) { - if ((now - list.barptr->starttime) >= 5) { - update_serv_rates(&list, statwin, - options->actmode, - &statcleared); - } + unsigned long rate_msecs = timeval_diff_msec(&tv, &tv_rate); + if (rate_msecs >= 1000) { + /* update all portlistent rates ... */ + update_serv_rates(&list, rate_msecs); + + /* ... and print the current one */ + if (list.barptr != NULL) + print_serv_rates(list.barptr, statwin, + options->actmode); + + tv_rate = tv; }
if (((options->updrate != 0) @@ -966,12 +952,7 @@ void servmon(char *ifname, const struct OPTIONS *options, break;
serv_tmp = list.barptr; - set_barptr((void *) &(list.barptr), - list.barptr->prev_entry, - &(list.barptr->prev_entry->starttime), - &list.barptr->prev_entry->span, - sizeof(list.barptr->prev_entry->span), - statwin, &statcleared, statx); + list.barptr = list.barptr->prev_entry; printportent(&list, serv_tmp, idx);
if (list.baridx == 1) @@ -980,6 +961,8 @@ void servmon(char *ifname, const struct OPTIONS *options, list.baridx--;
printportent(&list, list.barptr, idx); + + print_serv_rates(list.barptr, statwin, options->actmode); break; case KEY_DOWN: if (!list.barptr @@ -987,12 +970,7 @@ void servmon(char *ifname, const struct OPTIONS *options, break;
serv_tmp = list.barptr; - set_barptr((void *) &(list.barptr), - list.barptr->next_entry, - &(list.barptr->next_entry->starttime), - &list.barptr->next_entry->span, - sizeof(list.barptr->next_entry->span), - statwin, &statcleared, statx); + list.barptr = list.barptr->next_entry; printportent(&list,serv_tmp, idx);
if (list.baridx == list.imaxy) @@ -1001,6 +979,8 @@ void servmon(char *ifname, const struct OPTIONS *options, list.baridx++;
printportent(&list, list.barptr, idx); + + print_serv_rates(list.barptr, statwin, options->actmode); break; case KEY_PPAGE: case '-': @@ -1009,15 +989,12 @@ void servmon(char *ifname, const struct OPTIONS *options,
pageservwin(&list, SCROLLDOWN, &idx);
- set_barptr((void *) &(list.barptr), - list.lastvisible, - &(list.lastvisible->starttime), - &list.lastvisible->span, - sizeof(list.lastvisible->span), - statwin, &statcleared, statx); + list.barptr = list.lastvisible; list.baridx = list.lastvisible->idx - idx + 1;
refresh_serv_screen(&list, idx); + + print_serv_rates(list.barptr, statwin, options->actmode); break; case KEY_NPAGE: case ' ': @@ -1026,16 +1003,12 @@ void servmon(char *ifname, const struct OPTIONS *options,
pageservwin(&list, SCROLLUP, &idx);
- set_barptr((void *) &(list.barptr), - list.firstvisible, - &(list.firstvisible->starttime), - &list.firstvisible->span, - sizeof(list.firstvisible->span), - statwin, &statcleared, statx); + list.barptr = list.firstvisible; list.baridx = 1;
refresh_serv_screen(&list, idx);
+ print_serv_rates(list.barptr, statwin, options->actmode); break; case 12: case 'l': @@ -1062,15 +1035,9 @@ void servmon(char *ifname, const struct OPTIONS *options, sortportents(&list, &idx, ch); keymode = 0; if (list.barptr != NULL) { - set_barptr((void *) &(list.barptr), - list.firstvisible, - &(list.firstvisible-> - starttime), - &list.firstvisible->span, - sizeof(list.firstvisible->span), - statwin, &statcleared, - statx); + list.barptr = list.firstvisible; list.baridx = 1; + print_serv_rates(list.barptr, statwin, options->actmode); } refresh_serv_screen(&list, idx); update_panels(); @@ -1118,12 +1085,9 @@ void servmon(char *ifname, const struct OPTIONS *options, continue; } if ((list.barptr == NULL) && (list.head != NULL)) { - set_barptr((void *) &(list.barptr), list.head, - &(list.head->starttime), - &list.head->span, - sizeof(list.head->span), statwin, - &statcleared, statx); + list.barptr = list.head; list.baridx = 1; + print_serv_rates(list.barptr, statwin, options->actmode); } }
Vitezslav Samel vitezslav@samel.cz writes:
The first two patches are fixes, the third one is cleanup and the last one is enhancenment. The last one also cleans up the mess with set_barptr().
Please, apply.
v2: use enum in call to update_proto_counter() v1: initial version
Vitezslav Samel (4): serv.c: updateportent(): count packets even if dport is the same as sport serv.c: writeutslog(): fix the printed rate in non-KBITS mode serv.c: use struct proto_counter to count packets and bytes serv.c: use struct rate to compute traffic flow rate
src/serv.c | 289 +++++++++++++++++++++++++----------------------------------- 1 files changed, 119 insertions(+), 170 deletions(-)
applied. thanks
iptraf-ng@lists.fedorahosted.org