1 /*
2 * $smu-mark$
3 * $name: statistics.c$
4 * $author: Salvatore Sanfilippo <antirez@invece.org>$
5 * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
6 * $license: This software is under GPL version 2 of license$
7 * $date: Fri Nov 5 11:55:50 MET 1999$
8 * $rev: 8$
9 */
10
11 /* $Id: statistics.c,v 1.3 2004/04/09 23:38:56 antirez Exp $ */
12
13 #include <stdlib.h>
14 #include <stdio.h>
15
16 #include "hping2.h"
17 #include "globals.h"
18
print_statistics(int signal_id)19 void print_statistics(int signal_id)
20 {
21 unsigned int lossrate;
22
23 close_pcap();
24 if (recv_pkt > 0)
25 lossrate = 100 - ((recv_pkt*100)/sent_pkt);
26 else
27 if (!sent_pkt)
28 lossrate = 0;
29 else
30 lossrate = 100;
31
32 fprintf(stderr, "\n--- %s hping statistic ---\n", targetname);
33 fprintf(stderr, "%d packets tramitted, %d packets received, "
34 "%d%% packet loss\n", sent_pkt, recv_pkt, lossrate);
35 if (out_of_sequence_pkt)
36 fprintf(stderr, "%d out of sequence packets received\n",
37 out_of_sequence_pkt);
38 fprintf(stderr, "round-trip min/avg/max = %.1f/%.1f/%.1f ms\n",
39 rtt_min, rtt_avg, rtt_max);
40
41 /* manage exit code */
42 if (opt_tcpexitcode)
43 {
44 exit(tcp_exitcode);
45 }
46 else
47 {
48 if (recv_pkt)
49 exit(0);
50 else
51 exit(1);
52 }
53 };
54