#include <iostream>
#include <tins/tins.h>
using namespace Tins;
using namespace std;
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("eth0").sniff_loop(callback);
}
I have the default code libtins
gives you, but for some reason Sniffer
is undefined. I have included all libs in my linker.
Also it gives me the following error when I built:
-- Build started: Project: Packet Sniffing, Configuration: Debug x64 ------
1>Packet Sniffing.cpp
1>C:\Users\usr\Documents\Code\C++ Projects\static\libtins\include\tins\macros.h(37,10): fatal error C1083: Cannot open include file: 'tins/config.h': No such file or directory
1>Done building project "Packet Sniffing.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have checked and there is no file called config.h
however there is one called config.h.in
. When I removed .in
it gave me another error:
1>------ Build started: Project: Packet Sniffing, Configuration: Debug x64 ------
1>Packet Sniffing.cpp
1>C:\Users\usr\Documents\Code\C++ Projects\static\libtins\include\tins\config.h(5,1): fatal error C1021: invalid preprocessor command 'cmakedefine'
1>Done building project "Packet Sniffing.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The only instruction I didn't understand on their website is when they say
You also need to add this macro definition to your project:
TINS_STATIC
I don't exactly know what this means so this might also be the issue.
Thanks in advance!