File: drops_report.c

package info (click to toggle)
libtrace3 3.0.22-0.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,452 kB
  • sloc: ansic: 24,574; sh: 11,372; cpp: 1,811; makefile: 460; yacc: 96; lex: 50
file content (67 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <inttypes.h>
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include "libtrace.h"
#include "tracereport.h"
#include "report.h"

static uint64_t received_packets = 0;
static uint64_t filtered_packets = 0;
static uint64_t dropped_packets = 0;
static uint64_t accepted_packets = 0;

static bool has_received=false;
static bool has_filtered=false;
static bool has_dropped=false;
static bool has_accepted=false;

void drops_per_trace(libtrace_t *trace)
{
	uint64_t packets;

	packets = trace_get_received_packets(trace);
	if (packets != UINT64_MAX) {
		received_packets+=packets;
		has_received=true;
	}

	packets = trace_get_filtered_packets(trace);
	if (packets != UINT64_MAX) {
		filtered_packets+=packets;
		has_filtered=true;
	}

	packets = trace_get_dropped_packets(trace);
	if (packets != UINT64_MAX) {
		dropped_packets+=packets;
		has_dropped=true;
	}

	packets = trace_get_accepted_packets(trace);
	if (packets != UINT64_MAX) {
		accepted_packets+=packets;
		has_accepted=true;
	}
}


void drops_report(void)
{
	FILE *out = fopen("drop.rpt", "w");
	if (!out) {
		perror("fopen");
		return;
	}
	if (has_received)
		fprintf(out, "Received Packets: %" PRIu64 "\n", received_packets);
	if (has_filtered)
		fprintf(out, "Filtered Packets: %" PRIu64 "\n", filtered_packets);
	if (has_dropped)
		fprintf(out, "Dropped Packets: %" PRIu64 "\n", dropped_packets);

	if (has_accepted)
		fprintf(out, "Accepted Packets: %" PRIu64 "\n", accepted_packets);
	fclose(out);
}