|
Last change
on this file since 847 was
847,
checked in by perry, 7 years ago
|
|
Don't segfault if there is no direction information
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
|
File size:
949 bytes
|
| Line | |
|---|
| 1 | #include <netdb.h> |
|---|
| 2 | #include <inttypes.h> |
|---|
| 3 | #include <lt_inttypes.h> |
|---|
| 4 | #include <stdio.h> |
|---|
| 5 | #include "libtrace.h" |
|---|
| 6 | #include "tracereport.h" |
|---|
| 7 | |
|---|
| 8 | static uint64_t dir_bytes[8]; |
|---|
| 9 | static uint64_t dir_packets[8]; |
|---|
| 10 | |
|---|
| 11 | void dir_per_packet(struct libtrace_packet_t *packet) |
|---|
| 12 | { |
|---|
| 13 | if (trace_get_direction(packet)==-1) |
|---|
| 14 | return; |
|---|
| 15 | dir_bytes[trace_get_direction(packet)]+=trace_get_wire_length(packet); |
|---|
| 16 | ++dir_packets[trace_get_direction(packet)]; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | void dir_report(void) |
|---|
| 20 | { |
|---|
| 21 | int i; |
|---|
| 22 | printf("# Direction\n"); |
|---|
| 23 | printf("%-20s \t%12s\t%12s\n","Direction","bytes","packets"); |
|---|
| 24 | for(i=0;i<8;++i) { |
|---|
| 25 | if (!dir_packets[i]) |
|---|
| 26 | continue; |
|---|
| 27 | switch(i) { |
|---|
| 28 | case 0: printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n", |
|---|
| 29 | "in",dir_bytes[i],dir_packets[i]); |
|---|
| 30 | break; |
|---|
| 31 | case 1: printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n", |
|---|
| 32 | "out",dir_bytes[i],dir_packets[i]); |
|---|
| 33 | break; |
|---|
| 34 | default: printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n", |
|---|
| 35 | i,dir_bytes[i],dir_packets[i]); |
|---|
| 36 | break; |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.