From 5d2b0f66969d2ca801721b0db71baf9818c767fc Mon Sep 17 00:00:00 2001 From: yafang Date: Mon, 5 Jun 2017 21:49:08 +0800 Subject: [PATCH] fix: RT calculation not correct under certain circumstances As we can see, it will capture all the packets match with 'port' as bellow, if (port) sprintf(filter, "tcp port %d", port); pcap_compile(pcap, &bpf, filter, 1, 0) but it doesn't distinguish the src port and dst port. If this 'server' works as 'client' and connect other server with this port, it will generate wrong RT value. This patch is to fix this circumstance. --- src/process-packet.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/process-packet.c b/src/process-packet.c index 177aa24..1762fd8 100644 --- a/src/process-packet.c +++ b/src/process-packet.c @@ -137,14 +137,20 @@ process_ip(pcap_t *dev, const struct ip *ip, struct timeval tv) { lport = dport; rport = sport; - inbound(tv, ip->ip_dst, ip->ip_src, lport, rport); + if (lport == port) + inbound(tv, ip->ip_dst, ip->ip_src, lport, rport); + else + return 1; } else { lport = sport; rport = dport; - - outbound(tv, ip->ip_src, ip->ip_dst, lport, rport); + + if (lport == port) + outbound(tv, ip->ip_src, ip->ip_dst, lport, rport); + else + return 1; }