4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since 548c76b was
f3576f5,
checked in by Shane Alcock <salcock@…>, 15 years ago
|
misc and port reports now write to files - all reports now do so
Changed almost all the %llu format strings to use PRIu64 which should reduce the warnings on 64 bit machines
|
-
Property mode set to
100644
|
File size:
2.0 KB
|
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 | #include "report.h" |
---|
8 | |
---|
9 | static stat_t prot_stat[3][256] = {{{0,0}}} ; |
---|
10 | static bool suppress[3] = {true,true,true}; |
---|
11 | |
---|
12 | void protocol_per_packet(struct libtrace_packet_t *packet) |
---|
13 | { |
---|
14 | uint8_t proto; |
---|
15 | libtrace_direction_t dir = trace_get_direction(packet); |
---|
16 | |
---|
17 | if (trace_get_transport(packet,&proto,NULL)==NULL) |
---|
18 | return; |
---|
19 | |
---|
20 | if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING) |
---|
21 | dir = TRACE_DIR_OTHER; |
---|
22 | |
---|
23 | prot_stat[dir][proto].count++; |
---|
24 | prot_stat[dir][proto].bytes+=trace_get_wire_length(packet); |
---|
25 | suppress[dir] = false; |
---|
26 | } |
---|
27 | |
---|
28 | void protocol_report(void) |
---|
29 | { |
---|
30 | int i,j; |
---|
31 | FILE *out = fopen("protocol.rpt", "w"); |
---|
32 | if (!out) { |
---|
33 | perror("fopen"); |
---|
34 | return; |
---|
35 | } |
---|
36 | fprintf(out, "%-16s\t%10s\t%16s %16s\n", |
---|
37 | "PROTOCOL", |
---|
38 | "DIRECTION", |
---|
39 | "BYTES", |
---|
40 | "PACKETS"); |
---|
41 | |
---|
42 | setprotoent(1); |
---|
43 | for(i=0;i<256;++i) { |
---|
44 | struct protoent *prot; |
---|
45 | if (prot_stat[0][i].count==0 && |
---|
46 | prot_stat[1][i].count==0 && prot_stat[2][i].count==0) |
---|
47 | continue; |
---|
48 | prot = getprotobynumber(i); |
---|
49 | if (prot) { |
---|
50 | fprintf(out, "%16s",prot->p_name); |
---|
51 | } |
---|
52 | else { |
---|
53 | fprintf(out, "%16i:",i); |
---|
54 | } |
---|
55 | for (j=0; j < 3; j++) { |
---|
56 | if (j != 0) { |
---|
57 | fprintf(out, "%16s", " "); |
---|
58 | } |
---|
59 | switch (j) { |
---|
60 | case 0: |
---|
61 | fprintf(out, "\t%10s", "Outbound"); |
---|
62 | break; |
---|
63 | case 1: |
---|
64 | fprintf(out, "\t%10s", "Inbound"); |
---|
65 | break; |
---|
66 | case 2: |
---|
67 | fprintf(out, "\t%10s", "Unknown"); |
---|
68 | break; |
---|
69 | } |
---|
70 | |
---|
71 | fprintf(out, "\t%16" PRIu64 " %16" PRIu64 "\n", |
---|
72 | prot_stat[j][i].bytes, |
---|
73 | prot_stat[j][i].count); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | setprotoent(0); |
---|
78 | fclose(out); |
---|
79 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.