mfontanini / libtins

High-level, multiplatform C++ network packet sniffing and crafting library.
http://libtins.github.io/
BSD 2-Clause "Simplified" License
1.89k stars 373 forks source link

Multicast packet ( specifically fieldbus) is not parsed #512

Open ranifisch92 opened 10 months ago

ranifisch92 commented 10 months ago

Hi,

I try to parse multicast(fieldbus) packets( see attached zipped pcap file, containing single packet).

Environment: Ubuntu 18.04.6

Below is the code I wrote to reproduce the issue:

#include <iostream>
#include <tins/tins.h>

int main(int args, char * argv[])
{
    int count = 0;
    try {
        Tins::FileSniffer reader("/path/to/pcap");

        while (Tins::Packet packet = reader.next_packet()) {
            std::cout << "Packet length: " << packet.pdu()->size() << " bytes" << std::endl;
            count += 1;
        }
    } catch (const std::exception &ex) {
        std::cerr << "Error: " << ex.what() << std::endl;
        return 1;
    }

    std::cout << "Total packets: " << count << std::endl;

    return 0;
}

The expected output is: Total packets: 1 The actual output is : Total packets: 0

I have dug a little into the library's code, and I think the problem originates from this line: data->pdu = safe_alloc<EthernetII( (const uint8_t*)bytes, h->caplen); ( sniff_loop_eth_handler function, in sniffer.cpp file) this line of code sets the data->pdu to NULL, instead of setting non-NULL value

Let me know if there is additional information needed,

Tnx.

mcast_fieldbus_packet.zip