-1

I want to sniff one ethernet UDP packet coming from my raspberry using the c++ tins library, I can receive the packet and save it to vector but I can't access the payload to print it, which I acculay need to check. I'm so thankful for any help.

int main() {

std::vector<Packet> vt;
Sniffer sniffer("enp0s25");
vt.push_back(sniffer.next_packet());
    
}

1 Answers1

1

looking in the libtins tutorial (http://libtins.github.io/tutorial/sniffing/) about sniffing, I found this function implementation:

bool doo(PDU &some_pdu) {
    // Search for it. If there is no IP PDU in the packet, 
    // the loop goes on
    const IP &ip = some_pdu.rfind_pdu<IP>(); // non-const works as well
    std::cout << "Destination address: " << ip->dst_addr() << std::endl;
    // Just one packet please
    return false;
}

void test() {
    SnifferConfiguration config;
    config.set_promisc_mode(true);
    config.set_filter("ip src 192.168.0.100");
    Sniffer sniffer("eth0", config);
    sniffer.sniff_loop(doo);
}

Note that the doo function in this example only prints the destination address - but you can adjust to your needs.

Please also note the use of sniff_loop with doo as a callback function.

Adam Dov
  • 25
  • 6
  • thanks for your response !, if you can help me more with print the payload, I actually see the libtins tutorial and no methods from the library to print the payload data – Mouadh dahech Jul 18 '21 at 15:10