From cdbf52aaab53d5f65b08a04476ebee3333dfb485 Mon Sep 17 00:00:00 2001 From: Damir Zainullin Date: Wed, 29 Jan 2025 00:09:24 +0100 Subject: [PATCH] Fix parsing of packets when --with-pcap is enabled --- input/parser.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/input/parser.cpp b/input/parser.cpp index 61b696cb..598420be 100644 --- a/input/parser.cpp +++ b/input/parser.cpp @@ -682,26 +682,29 @@ void parse_packet(parser_opt_t *opt, ParserStats& stats, struct timeval ts, cons uint32_t l3_hdr_offset = 0; uint32_t l4_hdr_offset = 0; - try { - #ifdef WITH_PCAP + try + { +#ifdef WITH_PCAP if (opt->datalink == DLT_EN10MB) { data_offset = parse_eth_hdr(data, caplen, pkt); } else if (opt->datalink == DLT_LINUX_SLL) { - data_offset = parse_sll(data, caplen, pkt); - # ifdef DLT_LINUX_SLL2 + data_offset = parse_sll(data, caplen, pkt); +# ifdef DLT_LINUX_SLL2 } else if (opt->datalink == DLT_LINUX_SLL2) { - data_offset = parse_sll2(data, caplen, pkt); - # endif /* DLT_LINUX_SLL2 */ + data_offset = parse_sll2(data, caplen, pkt); +# endif /* DLT_LINUX_SLL2 */ } else if (opt->datalink == DLT_RAW) { - if ((data[0] & 0xF0) == 0x40) { - pkt->ethertype = ETH_P_IP; - } else if ((data[0] & 0xF0) == 0x60) { - pkt->ethertype = ETH_P_IPV6; - } + if ((data[0] & 0xF0) == 0x40) { + pkt->ethertype = ETH_P_IP; + } else if ((data[0] & 0xF0) == 0x60) { + pkt->ethertype = ETH_P_IPV6; + } + } else { +#endif /* WITH_PCAP */ + data_offset = parse_eth_hdr(data, caplen, pkt); +#ifdef WITH_PCAP } - #else - data_offset = parse_eth_hdr(data, caplen, pkt); - #endif /* WITH_PCAP */ +#endif /* WITH_PCAP */ if (pkt->ethertype == ETH_P_TRILL) { data_offset += parse_trill(data + data_offset, caplen - data_offset, pkt);