libtinsC++ 网络抓包和操作库

联合创作 · 2023-09-29 08:55

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);
}
浏览 5
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报