Help with Tutorials and Compiling

368 views
Skip to first unread message

Matthew Orahood

unread,
Oct 10, 2013, 3:20:19 PM10/10/13
to lib...@googlegroups.com
Matias, I just wanted to say good work and this library is exactly what I am looking for. Keep it up.

All, I recently started learning C++. I have experience with Python and wireless packet sniffing/injecting with Scapy. I wanted to give C++ a shot and I found libtins.

I am running into some issues when I attempt to compile some of these tutorials. I cannot get the following code to compile when i use g++ cprobe.cpp -o cprobe

#include <tins/tins.h>


using namespace Tins;


bool doo(PDU&) {
   
return false;
}


struct foo {
   
void bar() {
       
Sniffer sniffer("wlan1", 1000, true);
       
/* Uses the helper function to create a proxy object that
         * will call this->handle. If you're using boost or C++11,
         * you could use boost::bind or std::bind, that will also
         * work.
         */

        sniffer
.sniff_loop(make_sniffer_handler(this, &foo::handle));
       
// Also valid
        sniffer
.sniff_loop(doo);
   
}
   
   
bool handle(PDU&) {
       
// Don't process anything
       
return false;
   
}
};


int main() {
    foo f
;
    f
.bar();
}

I get the following error returned to me... 

 g++ cprobe.cpp -o cprobe
/tmp/ccwVIHs7.o: In function `Tins::SnifferIterator::advance()':
cprobe.cpp:(.text._ZN4Tins15SnifferIterator7advanceEv[_ZN4Tins15SnifferIterator7advanceEv]+0x1f): undefined reference to `Tins::BaseSniffer::next_packet()'
/tmp/ccwVIHs7.o: In function `foo::bar()':
cprobe.cpp:(.text._ZN3foo3barEv[_ZN3foo3barEv]+0x72): undefined reference to `Tins::Sniffer::Sniffer(std::string const&, unsigned int, bool, std::string const&)'
/tmp/ccwVIHs7.o: In function `void Tins::BaseSniffer::sniff_loop<Tins::HandlerProxy<foo> >(Tins::HandlerProxy<foo>, unsigned int)':
cprobe.cpp:(.text._ZN4Tins11BaseSniffer10sniff_loopINS_12HandlerProxyI3fooEEEEvT_j[_ZN4Tins11BaseSniffer10sniff_loopINS_12HandlerProxyI3fooEEEEvT_j]+0x1f): undefined reference to `Tins::BaseSniffer::begin()'
cprobe.cpp:(.text._ZN4Tins11BaseSniffer10sniff_loopINS_12HandlerProxyI3fooEEEEvT_j[_ZN4Tins11BaseSniffer10sniff_loopINS_12HandlerProxyI3fooEEEEvT_j]+0x8d): undefined reference to `Tins::BaseSniffer::end()'
/tmp/ccwVIHs7.o: In function `void Tins::BaseSniffer::sniff_loop<bool (*)(Tins::PDU&)>(bool (*)(Tins::PDU&), unsigned int)':
cprobe.cpp:(.text._ZN4Tins11BaseSniffer10sniff_loopIPFbRNS_3PDUEEEEvT_j[_ZN4Tins11BaseSniffer10sniff_loopIPFbRNS_3PDUEEEEvT_j]+0x23): undefined reference to `Tins::BaseSniffer::begin()'
cprobe.cpp:(.text._ZN4Tins11BaseSniffer10sniff_loopIPFbRNS_3PDUEEEEvT_j[_ZN4Tins11BaseSniffer10sniff_loopIPFbRNS_3PDUEEEEvT_j]+0x91): undefined reference to `Tins::BaseSniffer::end()'
/tmp/ccwVIHs7.o: In function `Tins::Sniffer::~Sniffer()':
cprobe.cpp:(.text._ZN4Tins7SnifferD2Ev[_ZN4Tins7SnifferD5Ev]+0x1f): undefined reference to `Tins::BaseSniffer::~BaseSniffer()'
/tmp/ccwVIHs7.o:(.rodata._ZTIN4Tins7SnifferE[_ZTIN4Tins7SnifferE]+0x10): undefined reference to `typeinfo for Tins::BaseSniffer'
collect2: error: ld returned 1 exit status

Does anyone have any suggestions?

Bruno Nery

unread,
Oct 10, 2013, 3:49:08 PM10/10/13
to Matthew Orahood, lib...@googlegroups.com
You have to link it to libtins. E.g.:

g++ cprobe.cpp -o cprobe -ltins

(not sure if it is tins, but look for it under /usr/lib/ or
/usr/local/lib -- if it is indeed tins, it will be libtins.so).
--
Bruno Nery
> --
> You received this message because you are subscribed to the Google Groups
> "libtins" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to libtins+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Matias Fontanini

unread,
Oct 10, 2013, 4:42:49 PM10/10/13
to lib...@googlegroups.com
Hi Matthew,

Bruno's advice is right, just link your application with libtins using
the "-ltins" parameter when compiling. Post again if you encounter any
other problem!

Cheers,
Matias
Reply all
Reply to author
Forward
0 new messages