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){