添加重传统计
All checks were successful
Build Test / build (push) Successful in 35s

This commit is contained in:
expvintl
2025-05-25 14:44:29 +08:00
parent 484988d50d
commit 542fe7f8b1
5 changed files with 21 additions and 14 deletions

View File

@ -42,6 +42,7 @@ extern int opt_debug,
sockraw,
sent_pkt,
recv_pkt,
dup_count,
out_of_sequence_pkt,
sending_wait,
opt_rawipmode,

1
main.c
View File

@ -64,6 +64,7 @@ int
sockraw,
sent_pkt = 0,
recv_pkt = 0,
dup_count = 0,
out_of_sequence_pkt = 0,
sending_wait = DEFAULT_SENDINGWAIT, /* see DEFAULT_SENDINGWAIT */
opt_rawipmode = FALSE,

View File

@ -17,7 +17,7 @@
void print_statistics(int signal_id)
{
unsigned int lossrate;
unsigned int lossrate=0;
uint32_t losspack=0;
#if (defined OSTYPE_LINUX) && (!defined FORCE_LIBPCAP)
close_sockpacket(sockpacket);
@ -33,12 +33,15 @@ void print_statistics(int signal_id)
lossrate=!sent_pkt?0:100;
}
fprintf(stderr, "\n--- %s 统计 ---\n", targetname);
fprintf(stderr, "发送: %d|收到: %d|%d%% 丢包率|已丢弃 %d\n", sent_pkt, recv_pkt, lossrate,losspack);
printf("\n--- %s 统计 ---\n", targetname);
printf("发送: %d|收到: %d|%d%% 丢包率|已丢弃 %d\n", sent_pkt, recv_pkt, lossrate,losspack);
if (out_of_sequence_pkt)
fprintf(stderr, "已收到 %d 个乱序数据包\n",
printf("已收到 %d 个乱序数据包\n",
out_of_sequence_pkt);
fprintf(stderr, "往返时间:\n最小:%.1f 毫秒\n平均: %.1f 毫秒\n最大:%.1f 毫秒\n",
if(dup_count>0){
printf("重传了 %d 个数据包\n",dup_count);
}
printf("==往返时间==\n最小:%.1f 毫秒\n平均: %.1f 毫秒\n最大:%.1f 毫秒\n",
rtt_min, rtt_avg, rtt_max);
/* manage exit code */

View File

@ -17,7 +17,7 @@
void show_usage(void)
{
printf(
"usage: hping host [options]\n"
"usage: hping3 host [options]\n"
" -h --help show this help\n"
" -v --version show version\n"
" -c --count packet count\n"

View File

@ -220,12 +220,12 @@ log_ipv4(int status, int sequence)
rel_id = relativize_id(sequence, &ip_id);
else
rel_id = 0;
printf("\033[1;36m长度=%d ip=%s ttl=%d %sid%s%d ", ip_size, inet_ntoa(src),
printf("len=%d ip=%s ttl=%d %sid%s%d ", ip_size, inet_ntoa(src),
ip->ttl,
(ntohs(ip->frag_off) ? "DF " : ""),
(rel_id ? "=+" : "="), ip_id);
if (opt_verbose && !opt_quiet)
printf("tos=%x ip长度=%u\n", ip->tos, htons(ip->tot_len));
printf("tos=%x ip_len=%u\n", ip->tos, htons(ip->tot_len));
}
static void
@ -233,7 +233,7 @@ log_ipv6(int status, int sequence)
{
char tmp[1024];
printf("\033[1;35m长度=%d ip=%s ttl=%d ", ip_size, inet_ntop(opt_af, &src6, tmp, sizeof(tmp)),
printf("len=%d ip=%s ttl=%d ", ip_size, inet_ntop(opt_af, &src6, tmp, sizeof(tmp)),
ip6->hoplimit);
if (opt_verbose && !opt_quiet)
printf("tc=%x flowlabel=%u\n", (ip6->tc1 << 4) | ip6->tc2, (ip6->flowlabel1 << 16) | ip6->flowlabel2);
@ -242,8 +242,10 @@ log_ipv6(int status, int sequence)
static void
log_ip(int status, int sequence)
{
if(status == S_RECV)
printf("DUP! ");
if(status == S_RECV){
printf("[重传]DUP! ");
dup_count++;
}
if(ip->version == 4)
log_ipv4(status, sequence);
else
@ -416,7 +418,7 @@ int recv_icmp6(void *packet, size_t size)
status = rtt(&icmp_seq, 0, &ms_delay);
log_ip(status, icmp_seq);
printf("icmp_seq=%d 往返时间=%.2f 毫秒\n", icmp_seq, ms_delay);
printf("icmp_seq=%d rtt=%.2f ms\n", icmp_seq, ms_delay);
notrace = 1;
return 1;
}
@ -480,7 +482,7 @@ int recv_udp(void *packet, size_t size)
status = rtt(&sequence, ntohs(udp.uh_dport), &ms_delay);
if (!opt_quiet) {
log_ip(status, sequence);
printf("seq=%d 往返时间=%.2f 毫秒\n", sequence, ms_delay);
printf("seq=%d rtt=%.2f ms\n", sequence, ms_delay);
}
if (opt_incdport && !opt_force_incdport)
dst_port++;
@ -545,7 +547,7 @@ int recv_tcp(void *packet, size_t size)
if (flags[0] == '\0') strcat(flags, "none");
log_ip(status, sequence);
printf("源端口=%d 标志=%s seq=%d win=%d 往返时间=%.2f 毫秒\n",
printf("sport=%d flags=%s seq=%d win=%d rtt=%.2f ms\n",
ntohs(tcp.th_sport), flags, sequence,
ntohs(tcp.th_win), ms_delay);