From 5427b568de89bcca1bc5a6dcd2a5cf724704a1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=A8=81?= Date: Tue, 4 Dec 2018 02:37:01 +0800 Subject: [PATCH] =?UTF-8?q?Update=20tcpdump.c=EF=BC=9A835=20=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E5=88=B0=E5=86=85=E5=B1=82=E4=B8=BAIPv6=E6=97=B6?= =?UTF-8?q?=E5=A4=B4=E9=83=A8=E5=9C=B0=E5=9D=80=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E7=AC=94=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tcpdump.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tcpdump.c b/tcpdump.c index 7e3e046..ae20036 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -855,11 +855,14 @@ static int MESA_dump_seek_to_inner(char *pkt_buf, int pktlen) if((char *)ip6hdr_greedy == first_ip_layer){ bpf_match_pkt_len = pktlen; /* 最内层和第一层IP一样, 说明是非常标准的ethernet->IPv6包, 且无隧道, 无需memmove操作 */ }else{ - memmove(pkt_buf + sizeof(struct mesa_ethernet_hdr), - ip6hdr_greedy, - pktlen - ((char *)ip6hdr_greedy - pkt_buf)); - bpf_match_pkt_len = pktlen - ((char *)ip4hdr_greedy - pkt_buf) + sizeof(struct mesa_ethernet_hdr); - ehdr->ether_type = htons(ETHERTYPE_IPv6); /* 第一层可能不是IPV6, 比如MPLS, VLAN等,需要改成IP,以便bpf过滤器能正确执行 */ + if(pktlen - ((char *)ip6hdr_greedy - pkt_buf) > 0) + { + memmove(pkt_buf + sizeof(struct mesa_ethernet_hdr), + ip6hdr_greedy, + pktlen - ((char *)ip6hdr_greedy - pkt_buf)); + bpf_match_pkt_len = pktlen - ((char *)ip6hdr_greedy - pkt_buf) + sizeof(struct mesa_ethernet_hdr); + ehdr->ether_type = htons(ETHERTYPE_IPv6); /* 第一层可能不是IPV6, 比如MPLS, VLAN等,需要改成IP,以便bpf过滤器能正确执行 */ + } } if(bpf_match_pkt_len <= 0){