4

首先,感谢您的耐心等待。这个问题可能只是由于我缺乏了解,因为我是 PDU 的初学者,...

我正在尝试使用libtins重新组装一些 TCP 流以测量一些指标。问题是,当我希望创建一个新流时,libtins 没有检测到任何新流。

这是我配置我的嗅探器的方式:

int main()
{
    SnifferConfiguration config;
    config.set_promisc_mode(true);
    config.set_filter("tcp");

    // Create our follower
    Tins::TCPIP::StreamFollower follower;

    // Set the callback for new streams. Note that this is a std::function, so you
    // could use std::bind and use a member function for this
    follower.new_stream_callback(&on_new_stream);

    // Now set up the termination callback. This will be called whenever a stream is
    // stopped being followed for some of the reasons explained above
    follower.stream_termination_callback(&on_stream_terminated);

    Sniffer sniffer("en0", config);

    // And start sniffing, forwarding all packets to our follower
    sniffer.sniff_loop([&](PDU &pdu) {
        std::cout << "Received packet:" << pdu.size() << std::endl;
        follower.process_packet(pdu);
        return true;
    });
}

这是我的新流回调

// New stream is seen
void on_new_stream(Stream &stream)
{
    std::cout << "New Stream: "
              << "client:" << stream.client_port() << " to " << stream.server_addr_v4().to_string() << ":" << stream.server_port() << std::endl;

    stream.client_data_callback(&on_client_data);
    stream.server_data_callback(&on_server_data);
}

通过在禁用缓存的情况下加载 Google 主页,控制台将记录大量具有各自大小的“收到的数据包”,但不会记录与创建新流相关的任何内容。

没有流开始

我通过保持程序运行并通过许多不同的网站进行测试,有时我会得到与流相关的日志记录,所以我猜所有的代码都不正确?

我的代码有什么问题吗?有没有更简单的方法来重新组装我的 TCP 流的大小?

非常感谢。

4

0 回答 0