source: tools/tracereport/flow_report.c @ d7e8e67

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d7e8e67 was a8f2692, checked in by Perry Lorier <perry@…>, 12 years ago

Tidy up a bazillion tiny warnings

  • 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"
[466aed6]9#include "report.h"
[d3ff1fb]10
11static uint64_t flow_count=0;
12
13struct fivetuple_t {
14        uint32_t ipa;
15        uint32_t ipb;
16        uint16_t porta;
17        uint16_t portb;
18        uint8_t prot;
19};
20
[49ce177]21static int fivetuplecmp(struct fivetuple_t a, struct fivetuple_t b)
[d3ff1fb]22{
[49ce177]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;
[d3ff1fb]28}
29
[a8f2692]30static int flowset_cmp(const splay *a, const splay *b);
[49ce177]31SET_CREATE(flowset,struct fivetuple_t,fivetuplecmp)
32
[d3ff1fb]33void flow_per_packet(struct libtrace_packet_t *packet)
34{
35        struct libtrace_ip *ip = trace_get_ip(packet);
[49ce177]36        struct fivetuple_t ft;
[d3ff1fb]37        if (!ip)
38                return;
[49ce177]39        ft.ipa=ip->ip_src.s_addr;
40        ft.ipb=ip->ip_dst.s_addr;
41        ft.porta=trace_get_source_port(packet);
42        ft.portb=trace_get_destination_port(packet);
43
44        if (!SET_CONTAINS(flowset,ft)) {
45                SET_INSERT(flowset,ft);
46                flow_count++;
[d3ff1fb]47        }
48}
49
50void flow_report(void)
51{
[bd4bec9]52        FILE *out = fopen("flows.rpt", "w");
[e991529]53        if (!out) {
54                perror("fopen");
55                return;
56        }
57        fprintf(out, "Flows: %" PRIu64 "\n",flow_count);
58        fclose(out);
[d3ff1fb]59}
Note: See TracBrowser for help on using the repository browser.