mfontanini / libtins

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

Linking Issues with g++ Against Precompiled Windows binaries #400

Open TBye101 opened 4 years ago

TBye101 commented 4 years ago

Hi,

I'm having issues linking to libtins and its dependencies using g++ (Mingw) 8.1.0 on Windows against the precompiled windows binaries. What is wrong? I thought that I had linked against all of the required dependencies?

Error:

C:\Users\sneak\AppData\Local\Temp\ccqBjxkI.o: In function `callback(Tins::PDU const&)':
D:\Repos\Hacks\Sniffer/sniffer.cpp:18: undefined reference to `__imp__ZN4TinslsERSoRKNS_11IPv4AddressE'
D:\Repos\Hacks\Sniffer/sniffer.cpp:19: undefined reference to `__imp__ZN4TinslsERSoRKNS_11IPv4AddressE'
C:\Users\sneak\AppData\Local\Temp\ccqBjxkI.o: In function `main':
D:\Repos\Hacks\Sniffer/sniffer.cpp:25: undefined reference to `__imp__ZN4Tins7SnifferC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
C:\Users\sneak\AppData\Local\Temp\ccqBjxkI.o: In function `Tins::IP::src_addr() const':
D:\Repos\Hacks\Sniffer/Libs/libtins/include/tins/ip.h:392: undefined reference to `__imp__ZN4Tins11IPv4AddressC1Ej'
C:\Users\sneak\AppData\Local\Temp\ccqBjxkI.o: In function `Tins::IP::dst_addr() const':
D:\Repos\Hacks\Sniffer/Libs/libtins/include/tins/ip.h:400: undefined reference to `__imp__ZN4Tins11IPv4AddressC1Ej'
C:\Users\sneak\AppData\Local\Temp\ccqBjxkI.o: In function `Tins::SnifferIterator::advance()':
D:\Repos\Hacks\Sniffer/Libs/libtins/include/tins/sniffer.h:515: undefined reference to `__imp__ZN4Tins11BaseSniffer11next_packetEv'
C:\Users\sneak\AppData\Local\Temp\ccqBjxkI.o: In function `void Tins::BaseSniffer::sniff_loop<bool (*)(Tins::PDU const&)>(bool (*)(Tins::PDU const&), unsigned int)':
D:\Repos\Hacks\Sniffer/Libs/libtins/include/tins/sniffer.h:673: undefined reference to `__imp__ZN4Tins11BaseSniffer5beginEv'
D:\Repos\Hacks\Sniffer/Libs/libtins/include/tins/sniffer.h:673: undefined reference to `__imp__ZN4Tins11BaseSniffer3endEv'
C:\Users\sneak\AppData\Local\Temp\ccqBjxkI.o: In function `Tins::Sniffer::~Sniffer()':
D:\Repos\Hacks\Sniffer/Libs/libtins/include/tins/sniffer.h:324: undefined reference to `__imp__ZTVN4Tins7SnifferE'
D:\Repos\Hacks\Sniffer/Libs/libtins/include/tins/sniffer.h:324: undefined reference to `__imp__ZN4Tins11BaseSnifferD2Ev'
collect2.exe: error: ld returned 1 exit status

Build command:

g++ -g -ILibs/libtins/include/tins -ILibs/libtins/include/ -ILibs/WpdPack/Include/ sniffer.cpp -o sniffer -Libs\ltins -Libs\lWs2_32 -Libs\lIphlpapi -Libs\lwpcap

Directory Tree:


├───.vscode
└───Libs
    ├───libtins
    │   ├───include
    │   │   └───tins
    │   │       ├───detail
    │   │       ├───dot11
    │   │       ├───tcp_ip
    │   │       └───utils
    │   └───lib
    └───WpdPack
        ├───docs
        │   └───html
        ├───Examples-pcap
        │   ├───basic_dump
        │   ├───basic_dump_ex
        │   ├───iflist
        │   ├───pcap_filter
        │   ├───pktdump_ex
        │   ├───readfile
        │   ├───readfile_ex
        │   ├───savedump
        │   ├───sendpack
        │   └───UDPdump
        ├───Examples-remote
        │   ├───iflist
        │   ├───misc
        │   ├───PacketDriver
        │   │   ├───GetMacAddress
        │   │   ├───TestPacketCapture
        │   │   └───TestPacketSend
        │   ├───pcap_filter
        │   ├───pcap_fopen
        │   ├───pktdump_ex
        │   ├───sendcap
        │   ├───smp_1
        │   ├───tcptop
        │   ├───UDPdump
        │   └───UserLevelBridge
        ├───Include
        │   └───pcap
        └───Lib
            └───x64

Basic code sample:


#include <iostream>
#include <vector>
#include <string>

#include "tins.h"

using namespace std;
using namespace Tins;

#define TINS_STATIC //Used to tell the compiler that the library libtins is being linked to a static library, rather than a DLL.

bool callback(const PDU &pdu)
{
    // Find the IP layer
    const IP &ip = pdu.rfind_pdu<IP>(); 
    // Find the TCP layer
    const TCP &tcp = pdu.rfind_pdu<TCP>(); 
    cout << ip.src_addr() << ':' << tcp.sport() << " -> " 
         << ip.dst_addr() << ':' << tcp.dport() << endl;
    return true;
}

int main()
{
    Sniffer("eh0").sniff_loop(callback);

    const char* a;
    scanf(a);
}

Thanks