mfontanini / libtins

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

register_allocator new protocol #370

Open taegyo opened 4 years ago

taegyo commented 4 years ago

i attemp to add new protocol for capture goose packet. (tutorial part. 7) but not recoginize pdu. / Windows 10 , 64bit

test code. i used dummypdu template class on tutorial.

int main() { Allocators::register_allocator<EthernetII, DummyPDU>(0x88b8);

Packet packet;
NetworkInterface iface = NetworkInterface::default_interface();
Sniffer sniffer(iface.name());
while (1)
{
    packet = sniffer.next_packet();
    if (packet)
    {
        if (packet.pdu()->find_pdu<DummyPDU>())
        {
            const DummyPDU &dummy = packet.pdu()->rfind_pdu<DummyPDU>(); // non-const works as well
            std::string payload(dummy.get_buffer().begin(), dummy.get_buffer().end());
            std::cout << "Payload: " << payload << std::endl;
        }

    }
}

}