'ARP sniffer and packet interception

i want to sniff arp replays to be more specific i want to intercept arp packet and retrieve ip addresses using libtins im not quite sure with the filter i put "arp" and how do i intercepet every arp packet and retrieve data from it

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

using std::cout;
using std::endl;

using namespace Tins;


bool callback(const PDU& pdu) {
    // The packet probably looks like this:
    //
    // EthernetII / ARP
    //
    // So we retrieve the ARP layer

    EthernetII eth = pdu.rfind_pdu<EthernetII>();
    ARP arp = pdu.rfind_pdu<ARP>();
    
    // Retrieve ip from arp level
    if((arp.opcode())==ARP::REPLY){
//I think this is the probleme
        for (const auto& arp : arp.target_ip_addr()) {
            cout << arp.target_ip_addr() << std::endl;
        }
    }
    return true;
}

int main(int argc, char* argv[]) {
    
    // Sniff on the provided interface in promiscuos mode
    SnifferConfiguration config;
    config.set_promisc_mode(true);
    // Only capture arp 
    config.set_filter("arp");
    Sniffer sniffer("eth0", config);
    
    // Start the capture
    sniffer.sniff_loop(callback);
}

I dont know if it's logically correct if yes some kind of error appears :

$ arpSniff.cpp: In function ‘bool callback(const Tins::PDU&)’:
arpSniff.cpp:22:47: error: ‘begin’ was not declared in this scope
   for (const auto& query : arp.target_ip_addr()) {
                                               ^
arpSniff.cpp:22:47: note: suggested alternative:
In file included from /usr/include/c++/8/vector:66,
                 from /usr/local/include/tins/dns.h:34,
                 from /usr/local/include/tins/tins.h:33,
                 from arpSniff.cpp:1:
/usr/include/c++/8/bits/range_access.h:105:37: note:   ‘std::begin’
   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&);
                                     ^~~~~
arpSniff.cpp:22:47: error: ‘end’ was not declared in this scope
   for (const auto& query : arp.target_ip_addr()) {
                                               ^
arpSniff.cpp:22:47: note: suggested alternative:
In file included from /usr/include/c++/8/vector:66,
                 from /usr/local/include/tins/dns.h:34,
                 from /usr/local/include/tins/tins.h:33,
                 from arpSniff.cpp:1:
/usr/include/c++/8/bits/range_access.h:107:37: note:   ‘std::end’
   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source