I'm using libtins in C++ project on Linux to create a pcap dump. The pcap dump that I am getting from my code does not appear to be readable by Wireshark, tcp dump, or the example that I used to try and read the code with libtins.
I need my program to produce output which is readable by wireshark, as well as being readable in a way that I can read it via code in my project as well.
Edit:
relevant code:
bool packetHandler(const PDU &pdu) {
const IP &ip = pdu.rfind_pdu<IP>();
return true;
cout << ip.src_addr() << " -> " << ip.dst_addr() << endl;
return true;
}
int main(int argc, char** argv)
{
if(getuid() != 0)
{
printf("You must run this program as root!\n");
exit(1);
}
try
{
std::string pcap_path = "/tmp/test.pcap";
std::string device = "eth0";
printf("Filepath: %s\n", pcap_path.c_str());
PacketWriter writer(pcap_path, DataLinkType<EthernetII>());
std::vector<EthernetII> vec(1000, EthernetII(hwaddr(device)));
writer.write(vec.begin(), vec.end());
writer.write(vec[0]);
} catch(Tins::unknown_link_type e)
{
printf("ERROR:\t%s\n", e.what());
} catch(std::runtime_error e)
{
printf("ERROR:\t%s\n", e.what());
}
}
I have also tried this code to read the pcap but it doesn't output anything:
#include <tins/tins.h>
using namespace Tins;
using namespace std;
bool packetHandler(PDU &pdu)
{
// Find the IP layer
const IP &ip = pdu.rfind_pdu<IP>();
cout << ip.src_addr() << " -> " << ip.dst_addr() << endl;
return true;
}
int main() {
FileSniffer sniffer("/tmp/test.pcap");
sniffer.sniff_loop(packetHandler);
}
edit.. again
As you can see from wireshark I'm getting the incorrect values for each field and data which is all 0s. https://i.stack.imgur.com/KTtq7.png (sry I couldn't embed the image because I don't have 10 reputation points on here). I need to be able to see the IP addresses, data, etc in the correct fields on wireshark but I'm not getting the correct data.