On Mon, Mar 12, 2012 at 09:19:04AM +0100, Nikola Pajkovsky wrote:
Vitezslav Samel <vitezslav(a)samel.cz> writes:
> Make use of structures and helper functions to clean up this function.
>
> Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
> ---
> src/ifstats.c | 328 +++++++++++++++++---------------------------------------
> src/ifstats.h | 80 ++++----------
> src/log.c | 110 ++++++++++++--------
> 3 files changed, 187 insertions(+), 331 deletions(-)
>
> + ts->total.total.packets,
> + ts->total.total.bytes);
This looks pretty bad. Total in total? The code will became hard to
grep. I suggest to change the name of items in struct.
counter looks to me too generic. it's packet counter. better name could
be *pkt_counter* and all the items should be prefixed with pc_ like
struct pkt_counter
DONE.
unsigned long long pc_packets;
DONE. Greppable but ugly to my eyes.
> +struct counter {
> + unsigned long long packets;
uint64_t?
No. One big problem: what will be in printf format?
%lu (on x86_64) or %llu (on x86_32) ???
> + unsigned long long bytes;
> +};
prefix it with e.g. with *pr_*
DONE (I used proto_ prefix).
> +struct proto_counter {
> + struct counter total;
> + struct counter in;
> + struct counter out;
> +};
and e.g. *i_*
Not done. This makes it a lot more uglier only to make it greppable.
> +struct ifcounts {
> + struct proto_counter total;
> + struct counter bcast;
> + struct counter bad;
> + struct proto_counter ipv4;
> + struct proto_counter ipv6;
> + struct proto_counter nonip;
> +
> + struct proto_counter tcp;
> + struct proto_counter udp;
> + struct proto_counter icmp;
> + struct proto_counter other;
> };
If attached patch suits you, I'll make it a git commit and send it to
you in proper format.
Cheers,
Vita
diff --git a/src/ifstats.c b/src/ifstats.c
index 0a4431b..fab4a81 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -50,7 +50,7 @@ void writegstatlog(struct iftab *table, int unit, unsigned long nsecs,
void writedstatlog(char *ifname, int unit, float activity, float pps,
float peakactivity, float peakpps, float peakactivity_in,
float peakpps_in, float peakactivity_out, float peakpps_out,
- struct iftotals *ts, unsigned long nsecs, FILE * logfile);
+ struct ifcounts *ts, unsigned long nsecs, FILE * logfile);
/*
* USR1 log-rotation signal handlers
@@ -630,7 +630,7 @@ void ifstats(const struct OPTIONS *options, struct filterstate
*ofilter,
}
-void printdetlabels(WINDOW * win, struct iftotals *totals)
+void printdetlabels(WINDOW * win)
{
wattrset(win, BOXATTR);
mvwprintw(win, 2, 14,
@@ -677,55 +677,61 @@ void printstatrow(WINDOW * win, int row, unsigned long long total,
printlargenum(btotal_out, win);
}
-void printdetails(struct iftotals *totals, WINDOW * win)
+void printstatrow_proto(WINDOW *win, int row, struct proto_counter *proto_counter)
{
- wattrset(win, HIGHATTR);
+ printstatrow(win, row,
+ proto_counter->proto_total.pc_packets,
+ proto_counter->proto_total.pc_bytes,
+ proto_counter->proto_in.pc_packets,
+ proto_counter->proto_in.pc_bytes,
+ proto_counter->proto_out.pc_packets,
+ proto_counter->proto_out.pc_bytes);
+}
+void printdetails(struct ifcounts *ifcounts, WINDOW * win)
+{
+ wattrset(win, HIGHATTR);
/* Print totals on the IP protocols */
-
- printstatrow(win, 4, totals->total, totals->bytestotal,
- totals->total_in, totals->bytestotal_in, totals->total_out,
- totals->bytestotal_out);
-
- printstatrow(win, 5, totals->iptotal, totals->ipbtotal,
- totals->iptotal_in, totals->ipbtotal_in,
- totals->iptotal_out, totals->ipbtotal_out);
-
- printstatrow(win, 6, totals->ip6total, totals->ip6btotal,
- totals->ip6total_in, totals->ip6btotal_in,
- totals->ip6total_out, totals->ip6btotal_out);
-
- printstatrow(win, 7, totals->tcptotal, totals->tcpbtotal,
- totals->tcptotal_in, totals->tcpbtotal_in,
- totals->tcptotal_out, totals->tcpbtotal_out);
-
- printstatrow(win, 8, totals->udptotal, totals->udpbtotal,
- totals->udptotal_in, totals->udpbtotal_in,
- totals->udptotal_out, totals->udpbtotal_out);
-
- printstatrow(win, 9, totals->icmptotal, totals->icmpbtotal,
- totals->icmptotal_in, totals->icmpbtotal_in,
- totals->icmptotal_out, totals->icmpbtotal_out);
-
- printstatrow(win, 10, totals->othtotal, totals->othbtotal,
- totals->othtotal_in, totals->othbtotal_in,
- totals->othtotal_out, totals->othbtotal_out);
+ printstatrow_proto(win, 4, &ifcounts->total);
+ printstatrow_proto(win, 5, &ifcounts->ipv4);
+ printstatrow_proto(win, 6, &ifcounts->ipv6);
+ printstatrow_proto(win, 7, &ifcounts->tcp);
+ printstatrow_proto(win, 8, &ifcounts->udp);
+ printstatrow_proto(win, 9, &ifcounts->icmp);
+ printstatrow_proto(win, 10, &ifcounts->other);
/* Print non-IP totals */
- printstatrow(win, 11, totals->noniptotal, totals->nonipbtotal,
- totals->noniptotal_in, totals->nonipbtotal_in,
- totals->noniptotal_out, totals->nonipbtotal_out);
+ printstatrow_proto(win, 11, &ifcounts->nonip);
/* Broadcast totals */
wmove(win, 14, 67);
- printlargenum(totals->bcast, win);
+ printlargenum(ifcounts->bcast.pc_packets, win);
wmove(win, 15, 67);
- printlargenum(totals->bcastbytes, win);
+ printlargenum(ifcounts->bcast.pc_bytes, win);
/* Bad packet count */
- mvwprintw(win, 19, 68, "%8lu", totals->badtotal);
+ mvwprintw(win, 19, 68, "%8lu", ifcounts->bad.pc_packets);
+}
+
+void update_counter(struct pkt_counter *count, int bytes)
+{
+ if (count) {
+ count->pc_packets++;
+ count->pc_bytes += bytes;
+ }
+}
+
+void update_proto_counter(struct proto_counter *proto_counter, int outgoing, int bytes)
+{
+ if (proto_counter) {
+ update_counter(&proto_counter->proto_total, bytes);
+ if (outgoing)
+ update_counter(&proto_counter->proto_out, bytes);
+ else
+ update_counter(&proto_counter->proto_in, bytes);
+ }
}
@@ -758,7 +764,7 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
unsigned int iplen = 0;
- struct iftotals totals;
+ struct ifcounts ifcounts;
int ch;
@@ -770,12 +776,7 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
unsigned long rate_interval;
unsigned long long unow;
- float spanbr = 0;
- float spanpkt = 0;
- float spanbr_in = 0;
- float spanbr_out = 0;
- float spanpkt_in = 0;
- float spanpkt_out = 0;
+ struct proto_counter span;
float activity = 0;
float activity_in = 0;
@@ -841,7 +842,7 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
update_panels();
doupdate();
- memset(&totals, 0, sizeof(struct iftotals));
+ memset(&ifcounts, 0, sizeof(struct ifcounts));
if (logging) {
if (strcmp(current_logfile, "") == 0) {
@@ -866,12 +867,12 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
writelog(logging, logfile,
"******** Detailed interface statistics started ********");
- printdetlabels(statwin, &totals);
- printdetails(&totals, statwin);
+ printdetlabels(statwin);
+ printdetails(&ifcounts, statwin);
update_panels();
doupdate();
- spanbr = 0;
+ memset(&span, 0, sizeof(span));
gettimeofday(&tv, NULL);
starttime = startlog = statbegin = tv.tv_sec;
@@ -898,34 +899,31 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
printelapsedtime(statbegin, now, LINES - 3, 1, statwin);
if (options->actmode == KBITS) {
activity =
- (float) (spanbr * 8 / 1000) /
+ (float) (span.proto_total.pc_bytes * 8 / 1000) /
(float) rate_interval;
activity_in =
- (float) (spanbr_in * 8 / 1000) /
+ (float) (span.proto_in.pc_bytes * 8 / 1000) /
(float) rate_interval;
activity_out =
- (float) (spanbr_out * 8 / 1000) /
+ (float) (span.proto_out.pc_bytes * 8 / 1000) /
(float) rate_interval;
} else {
activity =
- (float) (spanbr / 1024) /
+ (float) (span.proto_total.pc_bytes / 1024) /
(float) rate_interval;
activity_in =
- (float) (spanbr_in / 1024) /
+ (float) (span.proto_in.pc_bytes / 1024) /
(float) rate_interval;
activity_out =
- (float) (spanbr_out / 1024) /
+ (float) (span.proto_out.pc_bytes / 1024) /
(float) rate_interval;
}
- pps = (float) (spanpkt) / (float) (now - starttime);
- pps_in =
- (float) (spanpkt_in) / (float) (now - starttime);
- pps_out =
- (float) (spanpkt_out) / (float) (now - starttime);
+ pps = (float) (span.proto_total.pc_packets) / (float) rate_interval;
+ pps_in = (float) (span.proto_in.pc_packets) / (float) rate_interval;
+ pps_out = (float) (span.proto_out.pc_packets) / (float) rate_interval;
- spanbr = spanbr_in = spanbr_out = 0;
- spanpkt = spanpkt_in = spanpkt_out = 0;
+ memset(&span, 0, sizeof(span));
starttime = now;
wattrset(statwin, HIGHATTR);
@@ -962,7 +960,7 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
writedstatlog(iface, options->actmode, activity, pps,
peakactivity, peakpps, peakactivity_in,
peakpps_in, peakactivity_out, peakpps_out,
- &totals,
+ &ifcounts,
time((time_t *) NULL) - statbegin,
logfile);
@@ -973,7 +971,7 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
&& (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))
|| ((options->updrate != 0)
&& (now - updtime >= options->updrate))) {
- printdetails(&totals, statwin);
+ printdetails(&ifcounts, statwin);
update_panels();
doupdate();
updtime_usec = unow;
@@ -1007,6 +1005,9 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
break;
}
if (br > 0) {
+ int outgoing;
+ short ipproto;
+
framelen = br;
pkt_result =
processpacket(buf, &packet, (unsigned int *) &br,
@@ -1040,184 +1041,55 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
continue;
}
- totals.total++;
- totals.bytestotal += framelen;
-
- if (fromaddr.sll_pkttype == PACKET_OUTGOING) {
- totals.total_out++;
- totals.bytestotal_out += framelen;
- spanbr_out += framelen;
- spanpkt_out++;
- } else {
- totals.total_in++;
- totals.bytestotal_in += framelen;
- spanbr_in += framelen;
- spanpkt_in++;
- }
-
+ outgoing = (fromaddr.sll_pkttype == PACKET_OUTGOING);
+ update_proto_counter(&ifcounts.total, outgoing, framelen);
if (fromaddr.sll_pkttype == PACKET_BROADCAST) {
- totals.bcast++;
- totals.bcastbytes += framelen;
+ update_counter(&ifcounts.bcast, framelen);
}
- spanbr += framelen;
- spanpkt++;
+ update_proto_counter(&span, outgoing, framelen);
- if (fromaddr.sll_protocol == ETH_P_IP) {
+ /* account network layer protocol */
+ switch(fromaddr.sll_protocol) {
+ case ETH_P_IP:
if (pkt_result == CHECKSUM_ERROR) {
- totals.badtotal++;
+ update_counter(&ifcounts.bad, framelen);
continue;
}
ipacket = (struct iphdr *) packet;
- iphlen = ipacket->ihl * 4;
iplen = ntohs(ipacket->tot_len);
+ ipproto = ipacket->protocol;
- totals.iptotal++;
- totals.ipbtotal += iplen;
-
- if (fromaddr.sll_pkttype == PACKET_OUTGOING) {
- totals.iptotal_out++;
- totals.ipbtotal_out += iplen;
- } else {
- totals.iptotal_in++;
- totals.ipbtotal_in += iplen;
- }
-
- switch (ipacket->protocol) {
- case IPPROTO_TCP:
- totals.tcptotal++;
- totals.tcpbtotal += iplen;
-
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.tcptotal_out++;
- totals.tcpbtotal_out += iplen;
- } else {
- totals.tcptotal_in++;
- totals.tcpbtotal_in += iplen;
- }
- break;
- case IPPROTO_UDP:
- totals.udptotal++;
- totals.udpbtotal += iplen;
-
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.udptotal_out++;
- totals.udpbtotal_out += iplen;
- } else {
- totals.udptotal_in++;
- totals.udpbtotal_in += iplen;
- }
- break;
- case IPPROTO_ICMP:
- totals.icmptotal++;
- totals.icmpbtotal += iplen;
-
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.icmptotal_out++;
- totals.icmpbtotal_out += iplen;
- } else {
- totals.icmptotal_in++;
- totals.icmpbtotal_in += iplen;
- }
- break;
- default:
- totals.othtotal++;
- totals.othbtotal += iplen;
-
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.othtotal_out++;
- totals.othbtotal_out += iplen;
- } else {
- totals.othtotal_in++;
- totals.othbtotal_in += iplen;
- }
- break;
- }
- } else if (fromaddr.sll_protocol == ETH_P_IPV6) {
-
+ update_proto_counter(&ifcounts.ipv4, outgoing, iplen);
+ break;
+ case ETH_P_IPV6:
ip6packet = (struct ip6_hdr *) packet;
iplen = ntohs(ip6packet->ip6_plen) + 40;
+ ipproto = ip6packet->ip6_nxt;
- totals.ip6total++;
- totals.ip6btotal += iplen;
-
- if (fromaddr.sll_pkttype == PACKET_OUTGOING) {
- totals.ip6total_out++;
- totals.ip6btotal_out += iplen;
- } else {
- totals.ip6total_in++;
- totals.ip6btotal_in += iplen;
- }
+ update_proto_counter(&ifcounts.ipv6, outgoing, iplen);
+ break;
+ default:
+ update_proto_counter(&ifcounts.nonip, outgoing, iplen);
+ continue;
+ }
- switch (ip6packet->ip6_nxt) {
- case IPPROTO_TCP:
- totals.tcptotal++;
- totals.tcpbtotal += iplen;
-
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.tcptotal_out++;
- totals.tcpbtotal_out += iplen;
- } else {
- totals.tcptotal_in++;
- totals.tcpbtotal_in += iplen;
- }
- break;
- case IPPROTO_UDP:
- totals.udptotal++;
- totals.udpbtotal += iplen;
-
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.udptotal_out++;
- totals.udpbtotal_out += iplen;
- } else {
- totals.udptotal_in++;
- totals.udpbtotal_in += iplen;
- }
- break;
- case IPPROTO_ICMPV6:
- totals.icmptotal++;
- totals.icmpbtotal += iplen;
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.icmptotal_out++;
- totals.icmpbtotal_out += iplen;
- } else {
- totals.icmptotal_in++;
- totals.icmpbtotal_in += iplen;
- }
- break;
- default:
- totals.othtotal++;
- totals.othbtotal += iplen;
-
- if (fromaddr.sll_pkttype ==
- PACKET_OUTGOING) {
- totals.othtotal_out++;
- totals.othbtotal_out += iplen;
- } else {
- totals.othtotal_in++;
- totals.othbtotal_in += iplen;
- }
- break;
- }
- } else {
- totals.noniptotal++;
- totals.nonipbtotal += br;
-
- if (fromaddr.sll_pkttype == PACKET_OUTGOING) {
- totals.noniptotal_out++;
- totals.nonipbtotal_out += br;
- } else {
- totals.noniptotal_in++;
- totals.nonipbtotal_in += br;
- }
+ /* account transport layer protocol */
+ switch (ipproto) {
+ case IPPROTO_TCP:
+ update_proto_counter(&ifcounts.tcp, outgoing, iplen);
+ break;
+ case IPPROTO_UDP:
+ update_proto_counter(&ifcounts.udp, outgoing, iplen);
+ break;
+ case IPPROTO_ICMP:
+ case IPPROTO_ICMPV6:
+ update_proto_counter(&ifcounts.icmp, outgoing, iplen);
+ break;
+ default:
+ update_proto_counter(&ifcounts.other, outgoing, iplen);
+ break;
}
}
}
@@ -1237,7 +1109,7 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
writedstatlog(iface, options->actmode, activity, pps,
peakactivity, peakpps, peakactivity_in,
peakpps_in, peakactivity_out, peakpps_out,
- &totals, time((time_t *) NULL) - statbegin,
+ &ifcounts, time((time_t *) NULL) - statbegin,
logfile);
writelog(logging, logfile,
"******** Detailed interface statistics stopped ********");
diff --git a/src/ifstats.h b/src/ifstats.h
index 3c3ff08..781c8df 100644
--- a/src/ifstats.h
+++ b/src/ifstats.h
@@ -35,67 +35,29 @@ struct iftab {
PANEL *statpanel;
};
-struct iftotals {
- unsigned long long total;
- unsigned long long bytestotal;
- unsigned long long total_in;
- unsigned long long total_out;
- unsigned long long bytestotal_out;
- unsigned long long bytestotal_in;
- unsigned long long bcast;
- unsigned long long bcastbytes;
-
- unsigned long long iptotal;
- unsigned long long ipbtotal;
- unsigned long long iptotal_in;
- unsigned long long iptotal_out;
- unsigned long long ipbtotal_in;
- unsigned long long ipbtotal_out;
-
- unsigned long long ip6total;
- unsigned long long ip6btotal;
- unsigned long long ip6total_in;
- unsigned long long ip6total_out;
- unsigned long long ip6btotal_in;
- unsigned long long ip6btotal_out;
-
- unsigned long long noniptotal;
- unsigned long long nonipbtotal;
- unsigned long long noniptotal_in;
- unsigned long long noniptotal_out;
- unsigned long long nonipbtotal_in;
- unsigned long long nonipbtotal_out;
-
- unsigned long long tcptotal;
- unsigned long long tcpbtotal;
- unsigned long long tcptotal_in;
- unsigned long long tcptotal_out;
- unsigned long long tcpbtotal_in;
- unsigned long long tcpbtotal_out;
-
- unsigned long long udptotal;
- unsigned long long udpbtotal;
- unsigned long long udptotal_in;
- unsigned long long udptotal_out;
- unsigned long long udpbtotal_in;
- unsigned long long udpbtotal_out;
-
- unsigned long long icmptotal;
- unsigned long long icmpbtotal;
- unsigned long long icmptotal_in;
- unsigned long long icmptotal_out;
- unsigned long long icmpbtotal_in;
- unsigned long long icmpbtotal_out;
+struct pkt_counter {
+ unsigned long long pc_packets;
+ unsigned long long pc_bytes;
+};
- unsigned long long othtotal;
- unsigned long long othbtotal;
- unsigned long long othtotal_in;
- unsigned long long othtotal_out;
- unsigned long long othbtotal_in;
- unsigned long long othbtotal_out;
+struct proto_counter {
+ struct pkt_counter proto_total;
+ struct pkt_counter proto_in;
+ struct pkt_counter proto_out;
+};
- unsigned long badtotal;
- unsigned int interval;
+struct ifcounts {
+ struct proto_counter total;
+ struct pkt_counter bcast;
+ struct pkt_counter bad;
+ struct proto_counter ipv4;
+ struct proto_counter ipv6;
+ struct proto_counter nonip;
+
+ struct proto_counter tcp;
+ struct proto_counter udp;
+ struct proto_counter icmp;
+ struct proto_counter other;
};
#endif /* IPTRAF_NG_IFSTATS_H */
diff --git a/src/log.c b/src/log.c
index 115bab3..53135e7 100644
--- a/src/log.c
+++ b/src/log.c
@@ -282,7 +282,7 @@ void writegstatlog(struct iftab *table, int unit, unsigned long
nsecs,
void writedstatlog(char *ifname, int unit, float activity, float pps,
float peakactivity, float peakpps, float peakactivity_in,
float peakpps_in, float peakactivity_out, float peakpps_out,
- struct iftotals *ts, unsigned long nsecs, FILE * fd)
+ struct ifcounts *ts, unsigned long nsecs, FILE * fd)
{
char atime[TIME_TARGET_MAX];
char *unitstring = dispmode(unit);
@@ -293,84 +293,106 @@ void writedstatlog(char *ifname, int unit, float activity, float
pps,
"\n*** Detailed statistics for interface %s, generated %s\n\n",
ifname, atime);
- fprintf(fd, "Total: \t%llu packets, %llu bytes\n", ts->total,
- ts->bytestotal);
+ fprintf(fd, "Total: \t%llu packets, %llu bytes\n",
+ ts->total.proto_total.pc_packets,
+ ts->total.proto_total.pc_bytes);
fprintf(fd,
"\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->total_in, ts->bytestotal_in, ts->total_out,
- ts->bytestotal_out);
- fprintf(fd, "IP: \t%llu packets, %llu bytes\n", ts->iptotal,
- ts->ipbtotal);
+ ts->total.proto_in.pc_packets,
+ ts->total.proto_in.pc_bytes,
+ ts->total.proto_out.pc_packets,
+ ts->total.proto_out.pc_bytes);
+ fprintf(fd, "IP: \t%llu packets, %llu bytes\n",
+ ts->ipv4.proto_total.pc_packets,
+ ts->ipv4.proto_total.pc_bytes);
fprintf(fd,
"\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->iptotal_in, ts->ipbtotal_in, ts->iptotal_out,
- ts->ipbtotal_out);
- fprintf(fd, "TCP: %llu packets, %llu bytes\n", ts->tcptotal,
- ts->tcpbtotal);
+ ts->ipv4.proto_in.pc_packets,
+ ts->ipv4.proto_in.pc_bytes,
+ ts->ipv4.proto_out.pc_packets,
+ ts->ipv4.proto_out.pc_bytes);
+ fprintf(fd, "TCP: %llu packets, %llu bytes\n",
+ ts->tcp.proto_total.pc_packets,
+ ts->tcp.proto_total.pc_bytes);
fprintf(fd,
"\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->tcptotal_in, ts->tcpbtotal_in, ts->tcptotal_out,
- ts->tcpbtotal_out);
- fprintf(fd, "UDP: %llu packets, %llu bytes\n", ts->udptotal,
- ts->udpbtotal);
+ ts->tcp.proto_in.pc_packets,
+ ts->tcp.proto_in.pc_bytes,
+ ts->tcp.proto_out.pc_packets,
+ ts->tcp.proto_out.pc_bytes);
+ fprintf(fd, "UDP: %llu packets, %llu bytes\n",
+ ts->udp.proto_total.pc_packets,
+ ts->udp.proto_total.pc_bytes);
fprintf(fd,
"\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->udptotal_in, ts->udpbtotal_in, ts->udptotal_out,
- ts->udpbtotal_out);
- fprintf(fd, "ICMP: %llu packets, %llu bytes\n", ts->icmptotal,
- ts->icmpbtotal);
+ ts->udp.proto_in.pc_packets,
+ ts->udp.proto_in.pc_bytes,
+ ts->udp.proto_out.pc_packets,
+ ts->udp.proto_out.pc_bytes);
+ fprintf(fd, "ICMP: %llu packets, %llu bytes\n",
+ ts->icmp.proto_total.pc_packets,
+ ts->icmp.proto_total.pc_bytes);
fprintf(fd,
"\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->icmptotal_in, ts->icmpbtotal_in, ts->icmptotal_out,
- ts->icmpbtotal_out);
- fprintf(fd, "Other IP: %llu packets, %llu bytes\n", ts->othtotal,
- ts->othbtotal);
+ ts->icmp.proto_in.pc_packets,
+ ts->icmp.proto_in.pc_bytes,
+ ts->icmp.proto_out.pc_packets,
+ ts->icmp.proto_out.pc_bytes);
+ fprintf(fd, "Other IP: %llu packets, %llu bytes\n",
+ ts->other.proto_total.pc_packets,
+ ts->other.proto_total.pc_bytes);
fprintf(fd,
"\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->othtotal_in, ts->othbtotal_in, ts->othtotal_out,
- ts->othbtotal_out);
- fprintf(fd, "Non-IP: %llu packets, %llu bytes\n", ts->noniptotal,
- ts->nonipbtotal);
+ ts->other.proto_in.pc_packets,
+ ts->other.proto_in.pc_bytes,
+ ts->other.proto_out.pc_packets,
+ ts->other.proto_out.pc_bytes);
+ fprintf(fd, "Non-IP: %llu packets, %llu bytes\n",
+ ts->nonip.proto_total.pc_packets,
+ ts->nonip.proto_total.pc_bytes);
fprintf(fd,
"\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->noniptotal_in, ts->nonipbtotal_in, ts->noniptotal_out,
- ts->nonipbtotal_out);
- fprintf(fd, "Broadcast: %llu packets, %llu bytes\n", ts->bcast,
- ts->bcastbytes);
+ ts->nonip.proto_in.pc_packets,
+ ts->nonip.proto_in.pc_bytes,
+ ts->nonip.proto_out.pc_packets,
+ ts->nonip.proto_out.pc_bytes);
+ fprintf(fd, "Broadcast: %llu packets, %llu bytes\n",
+ ts->bcast.pc_packets,
+ ts->bcast.pc_bytes);
if (nsecs > 5) {
fprintf(fd, "\nAverage rates:\n");
if (unit == KBITS) {
fprintf(fd, " Total:\t%.2f kbits/s, %.2f packets/s\n",
- ((float) (ts->bytestotal * 8 / 1000) /
+ ((float) (ts->total.proto_total.pc_bytes * 8 / 1000) /
(float) nsecs),
- ((float) (ts->total) / (float) nsecs));
+ ((float) (ts->total.proto_total.pc_packets) / (float) nsecs));
fprintf(fd,
" Incoming:\t%.2f kbits/s, %.2f packets/s\n",
- (float) (ts->bytestotal_in * 8 / 1000) /
+ (float) (ts->total.proto_in.pc_bytes * 8 / 1000) /
(float) (nsecs),
- (float) (ts->total_in) / (float) (nsecs));
+ (float) (ts->total.proto_in.pc_packets) / (float) (nsecs));
fprintf(fd,
" Outgoing:\t%.2f kbits/s, %.2f packets/s\n",
- (float) (ts->bytestotal_out * 8 / 1000) /
+ (float) (ts->total.proto_out.pc_bytes * 8 / 1000) /
(float) (nsecs),
- (float) (ts->total_out) / (float) (nsecs));
+ (float) (ts->total.proto_out.pc_packets) / (float) (nsecs));
} else {
fprintf(fd, "%.2f kbytes/s, %.2f packets/s\n",
- ((float) (ts->bytestotal / 1024) /
+ ((float) (ts->total.proto_total.pc_bytes / 1024) /
(float) nsecs),
- ((float) (ts->total) / (float) nsecs));
+ ((float) (ts->total.proto_total.pc_packets) / (float) nsecs));
fprintf(fd,
"Incoming:\t%.2f kbytes/s, %.2f packets/s\n",
- (float) (ts->bytestotal_in / 1024) /
+ (float) (ts->total.proto_in.pc_bytes / 1024) /
(float) (nsecs),
- (float) (ts->total_in) / (float) (nsecs));
+ (float) (ts->total.proto_in.pc_packets) / (float) (nsecs));
fprintf(fd,
"Outgoing:\t%.2f kbytes/s, %.2f packets/s\n",
- (float) (ts->bytestotal_out / 1024) /
+ (float) (ts->total.proto_out.pc_bytes / 1024) /
(float) (nsecs),
- (float) (ts->total_out) / (float) (nsecs));
+ (float) (ts->total.proto_out.pc_packets) / (float) (nsecs));
}
fprintf(fd,
@@ -381,7 +403,7 @@ void writedstatlog(char *ifname, int unit, float activity, float pps,
fprintf(fd, "Peak outgoing rate: %.2f %s/s, %.2f packets/s\n\n",
peakactivity_out, unitstring, peakpps_out);
}
- fprintf(fd, "IP checksum errors: %lu\n\n", ts->badtotal);
+ fprintf(fd, "IP checksum errors: %llu\n\n", ts->bad.pc_packets);
fprintf(fd, "Running time: %lu seconds\n", nsecs);
fflush(fd);
}