source: tools/tracereport/flow_report.c @ f3576f5

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since f3576f5 was bd4bec9, checked in by Shane Alcock <salcock@…>, 15 years ago

tcpsegment, protocol and tos reports all now write to files.
Changed the output filenames to be *.rpt rather than *.out

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[d3ff1fb]1#include <netdb.h>
2#include <inttypes.h>
[e3b0188]3#include <lt_inttypes.h>
[d3ff1fb]4#include <stdio.h>
5#include <stdlib.h>
6#include "libtrace.h"
7#include "tracereport.h"
[49ce177]8#include "contain.h"
[d3ff1fb]9
10static uint64_t flow_count=0;
11
12struct fivetuple_t {
13        uint32_t ipa;
14        uint32_t ipb;
15        uint16_t porta;
16        uint16_t portb;
17        uint8_t prot;
18};
19
[49ce177]20static int fivetuplecmp(struct fivetuple_t a, struct fivetuple_t b)
[d3ff1fb]21{
[49ce177]22        if (a.porta != b.porta) return a.porta-b.porta;
23        if (a.portb != b.portb) return a.portb-b.portb;
24        if (a.ipa != b.ipa) return a.ipa-b.ipa;
25        if (a.ipb != b.ipb) return a.ipb-b.ipb;
26        return a.prot - b.prot;
[d3ff1fb]27}
28
[49ce177]29SET_CREATE(flowset,struct fivetuple_t,fivetuplecmp)
30
[d3ff1fb]31void flow_per_packet(struct libtrace_packet_t *packet)
32{
33        struct libtrace_ip *ip = trace_get_ip(packet);
[49ce177]34        struct fivetuple_t ft;
[d3ff1fb]35        if (!ip)
36                return;
[49ce177]37        ft.ipa=ip->ip_src.s_addr;
38        ft.ipb=ip->ip_dst.s_addr;
39        ft.porta=trace_get_source_port(packet);
40        ft.portb=trace_get_destination_port(packet);
41
42        if (!SET_CONTAINS(flowset,ft)) {
43                SET_INSERT(flowset,ft);
44                flow_count++;
[d3ff1fb]45        }
46}
47
48void flow_report(void)
49{
[bd4bec9]50        FILE *out = fopen("flows.rpt", "w");
[e991529]51        if (!out) {
52                perror("fopen");
53                return;
54        }
55        fprintf(out, "Flows: %" PRIu64 "\n",flow_count);
56        fclose(out);
[d3ff1fb]57}
Note: See TracBrowser for help on using the repository browser.