source: tools/tracereport/flow_report.c @ a7282fb

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

Fix lots of little warnings

  • Property mode set to 100644
File size: 1.1 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
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
21static 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
30SET_CREATE(flowset,struct fivetuple_t,fivetuplecmp)
31
32void 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
49void flow_report(void)
50{
51        printf("# Flows:\n");
52        printf("Flows: %" PRIu64 "\n",flow_count);
53}
Note: See TracBrowser for help on using the repository browser.