Skip to content

Commit 3a7d52d

Browse files
authored
Merge pull request #256 from CESNET/pcap-compilation-parse-layer
Parser - Fix packet parsing issue when --with-pcap is enabled
2 parents fee9b26 + a8c08f7 commit 3a7d52d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

input/parser.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,25 +683,29 @@ void parse_packet(parser_opt_t *opt, ParserStats& stats, struct timeval ts, cons
683683
uint32_t l3_hdr_offset = 0;
684684
uint32_t l4_hdr_offset = 0;
685685
try {
686-
#ifdef WITH_PCAP
687-
if (opt->datalink == DLT_EN10MB) {
686+
#ifdef WITH_PCAP
687+
if (!opt->datalink || opt->datalink == DLT_EN10MB) {
688688
data_offset = parse_eth_hdr(data, caplen, pkt);
689689
} else if (opt->datalink == DLT_LINUX_SLL) {
690690
data_offset = parse_sll(data, caplen, pkt);
691-
# ifdef DLT_LINUX_SLL2
691+
# ifdef DLT_LINUX_SLL2
692692
} else if (opt->datalink == DLT_LINUX_SLL2) {
693693
data_offset = parse_sll2(data, caplen, pkt);
694-
# endif /* DLT_LINUX_SLL2 */
694+
# endif /* DLT_LINUX_SLL2 */
695695
} else if (opt->datalink == DLT_RAW) {
696696
if ((data[0] & 0xF0) == 0x40) {
697697
pkt->ethertype = ETH_P_IP;
698698
} else if ((data[0] & 0xF0) == 0x60) {
699699
pkt->ethertype = ETH_P_IPV6;
700700
}
701+
} else {
702+
stats.unknown_packets++;
703+
DEBUG_MSG("Unknown datalink type %u\n", opt->datalink);
704+
return;
701705
}
702-
#else
706+
#else
703707
data_offset = parse_eth_hdr(data, caplen, pkt);
704-
#endif /* WITH_PCAP */
708+
#endif /* WITH_PCAP */
705709

706710
if (pkt->ethertype == ETH_P_TRILL) {
707711
data_offset += parse_trill(data + data_offset, caplen - data_offset, pkt);

0 commit comments

Comments
 (0)