libtins - C++ 网络抓包和操作库
BSD
跨平台
C/C++
软件简介
libtins 是一个高级支持多平台的 C++ 网络抓包和操作库。开发者可以利用 libtins 在应用实现对网络数据包的分析和操作。
示例代码:
#include <iostream>
#include <tins/tins.h>
using namespace Tins;
bool handler(const PDU &pdu) {
const IP &ip = pdu.rfind_pdu<IP>(); // Find the IP layer
const TCP &tcp = pdu.rfind_pdu<TCP>(); // Find the TCP layer
std::cout << ip.src_addr() << ':' << tcp.sport() << " -> "
<< ip.dst_addr() << ':' << tcp.dport() << std::endl;
return true;
}
int main() {
Sniffer("eth0").sniff_loop(handler);
}