4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since 466aed6 was
466aed6,
checked in by Perry Lorier <perry@…>, 14 years ago
|
Flag functions as static if they're not actually used.
Include report.h too to make sure that functions have the right prototypes
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | #include <netdb.h> |
---|
2 | #include <inttypes.h> |
---|
3 | #include <lt_inttypes.h> |
---|
4 | #include <stdio.h> |
---|
5 | #include <stdlib.h> |
---|
6 | #include "libtrace.h" |
---|
7 | #include "tracereport.h" |
---|
8 | #include "contain.h" |
---|
9 | #include "report.h" |
---|
10 | |
---|
11 | static uint64_t flow_count=0; |
---|
12 | |
---|
13 | struct fivetuple_t { |
---|
14 | uint32_t ipa; |
---|
15 | uint32_t ipb; |
---|
16 | uint16_t porta; |
---|
17 | uint16_t portb; |
---|
18 | uint8_t prot; |
---|
19 | }; |
---|
20 | |
---|
21 | static int fivetuplecmp(struct fivetuple_t a, struct fivetuple_t b) |
---|
22 | { |
---|
23 | if (a.porta != b.porta) return a.porta-b.porta; |
---|
24 | if (a.portb != b.portb) return a.portb-b.portb; |
---|
25 | if (a.ipa != b.ipa) return a.ipa-b.ipa; |
---|
26 | if (a.ipb != b.ipb) return a.ipb-b.ipb; |
---|
27 | return a.prot - b.prot; |
---|
28 | } |
---|
29 | |
---|
30 | SET_CREATE(flowset,struct fivetuple_t,fivetuplecmp) |
---|
31 | |
---|
32 | void flow_per_packet(struct libtrace_packet_t *packet) |
---|
33 | { |
---|
34 | struct libtrace_ip *ip = trace_get_ip(packet); |
---|
35 | struct fivetuple_t ft; |
---|
36 | if (!ip) |
---|
37 | return; |
---|
38 | ft.ipa=ip->ip_src.s_addr; |
---|
39 | ft.ipb=ip->ip_dst.s_addr; |
---|
40 | ft.porta=trace_get_source_port(packet); |
---|
41 | ft.portb=trace_get_destination_port(packet); |
---|
42 | |
---|
43 | if (!SET_CONTAINS(flowset,ft)) { |
---|
44 | SET_INSERT(flowset,ft); |
---|
45 | flow_count++; |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | void flow_report(void) |
---|
50 | { |
---|
51 | FILE *out = fopen("flows.rpt", "w"); |
---|
52 | if (!out) { |
---|
53 | perror("fopen"); |
---|
54 | return; |
---|
55 | } |
---|
56 | fprintf(out, "Flows: %" PRIu64 "\n",flow_count); |
---|
57 | fclose(out); |
---|
58 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.