2022-04-13 18:01:39 +08:00
|
|
|
/*
|
|
|
|
* $smu-mark$
|
|
|
|
* $name: statistics.c$
|
|
|
|
* $author: Salvatore Sanfilippo <antirez@invece.org>$
|
|
|
|
* $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
|
|
|
|
* $license: This software is under GPL version 2 of license$
|
|
|
|
* $date: Fri Nov 5 11:55:50 MET 1999$
|
|
|
|
* $rev: 8$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "hping2.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
void print_statistics(int signal_id)
|
|
|
|
{
|
|
|
|
unsigned int lossrate;
|
2024-06-21 07:49:53 +08:00
|
|
|
uint32_t losspack=0;
|
2022-04-13 18:01:39 +08:00
|
|
|
#if (defined OSTYPE_LINUX) && (!defined FORCE_LIBPCAP)
|
|
|
|
close_sockpacket(sockpacket);
|
|
|
|
#else
|
|
|
|
close_pcap();
|
|
|
|
#endif /* OSTYPE_LINUX && !FORCE_LIBPCAP */
|
|
|
|
|
2024-06-21 07:49:53 +08:00
|
|
|
if (recv_pkt > 0){
|
2024-06-21 19:06:53 +08:00
|
|
|
losspack=(recv_pkt!=sent_pkt)?(recv_pkt/sent_pkt):0;
|
2024-06-21 07:49:53 +08:00
|
|
|
lossrate = 100 - ((recv_pkt*100)/sent_pkt);
|
|
|
|
}else{
|
|
|
|
losspack=!sent_pkt?0:sent_pkt;
|
|
|
|
lossrate=!sent_pkt?0:100;
|
|
|
|
}
|
2022-04-13 18:01:39 +08:00
|
|
|
|
2024-06-21 07:49:53 +08:00
|
|
|
fprintf(stderr, "\n--- %s 统计 ---\n", targetname);
|
2024-06-21 19:06:53 +08:00
|
|
|
fprintf(stderr, "发送: %d|收到: %d|%d%% 丢包率|已丢弃 %d\n", sent_pkt, recv_pkt, lossrate,losspack);
|
2022-04-13 18:01:39 +08:00
|
|
|
if (out_of_sequence_pkt)
|
2024-06-21 07:49:53 +08:00
|
|
|
fprintf(stderr, "已收到 %d 个乱序数据包\n",
|
2022-04-13 18:01:39 +08:00
|
|
|
out_of_sequence_pkt);
|
2024-06-21 07:49:53 +08:00
|
|
|
fprintf(stderr, "往返时间:\n最小:%.1f 毫秒\n平均: %.1f 毫秒\n最大:%.1f 毫秒\n",
|
2022-04-13 18:01:39 +08:00
|
|
|
rtt_min, rtt_avg, rtt_max);
|
|
|
|
|
|
|
|
/* manage exit code */
|
|
|
|
if (opt_tcpexitcode)
|
|
|
|
{
|
|
|
|
exit(tcp_exitcode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (recv_pkt)
|
|
|
|
exit(0);
|
|
|
|
else
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
};
|