用于C++; 我必须处理C++中的原始IP数据包,因为我使用的是开放的VPN作为一个库,它提供IP数据包。因此,我需要一个库,它可以为我持续响应,并只提供TCP/UDP负载

用于C++; 我必须处理C++中的原始IP数据包,因为我使用的是开放的VPN作为一个库,它提供IP数据包。因此,我需要一个库,它可以为我持续响应,并只提供TCP/UDP负载,c++,tcp,udp,ip,C++,Tcp,Udp,Ip,我已经找到了,但它只用于解析。但是,我仍然需要手动确认每个TCP数据包,并跟踪TCP计数等 是否有一个库可以为我处理IP、TCP和UDP层,并只提供有效负载,以便我可以使用?正如我在评论中提到的,并向您展示一个示例,您从我的评论中了解到,它能够监视数据包。它还能够定制您自己的有效负载,这两种组合允许您使用一个库进行响应、跟踪和监视 还提供了a的示例以及其他示例,例如a。这很容易 创建一个数据包并发送它,可以在一行中完成 EthernetII eth = EthernetII("77:22:33:

我已经找到了,但它只用于解析。但是,我仍然需要手动确认每个TCP数据包,并跟踪TCP计数等


是否有一个库可以为我处理IP、TCP和UDP层,并只提供有效负载,以便我可以使用?

正如我在评论中提到的,并向您展示一个示例,您从我的评论中了解到,它能够监视数据包。它还能够定制您自己的有效负载,这两种组合允许您使用一个库进行响应、跟踪和监视

还提供了a的示例以及其他示例,例如a。这很容易

创建一个数据包并发送它,可以在一行中完成

EthernetII eth = EthernetII("77:22:33:11:ad:ad", info.hw_addr) / 
                 IP("192.168.0.1", info.ip_addr) /
                 TCP(13, 15) /
                 RawPDU("PAYLOAD");
再一次,你可以扩展这个

#include <tins/tins.h>
#include <cassert>
#include <iostream>
#include <string>

using namespace Tins;

int main() {
    // We'll use the default interface(default gateway)
    NetworkInterface iface = NetworkInterface::default_interface();

    /* Retrieve this structure which holds the interface's IP, 
     * broadcast, hardware address and the network mask.
     */
    NetworkInterface::Info info = iface.addresses();

    /* Create an Ethernet II PDU which will be sent to 
     * 77:22:33:11:ad:ad using the default interface's hardware 
     * address as the sender.
     */
    EthernetII eth("77:22:33:11:ad:ad", info.hw_addr);

    /* Create an IP PDU, with 192.168.0.1 as the destination address
     * and the default interface's IP address as the sender.
     */
    eth /= IP("192.168.0.1", info.ip_addr);

    /* Create a TCP PDU using 13 as the destination port, and 15 
     * as the source port.
     */
    eth /= TCP(13, 15);

    /* Create a RawPDU containing the string "I'm a payload!".
     */
    eth /= RawPDU("I'm a payload!");

    // The actual sender
    PacketSender sender;

    // Send the packet through the default interface
    sender.send(eth, iface);
}
#包括
#包括
#包括
#包括
使用名称空间TIN;
int main(){
//我们将使用默认接口(默认网关)
NetworkInterface iface=NetworkInterface::default_interface();
/*检索此保存接口IP的结构,
*广播、硬件地址和网络掩码。
*/
NetworkInterface::Info=iface.addresses();
/*创建一个Ethernet II PDU,该PDU将被发送到
*77:22:33:11:ad:ad使用默认接口的硬件
*作为发件人的地址。
*/
以太内蒂以太书(“77:22:33:11:ad:ad”,info.hw_addr);
/*创建一个IP PDU,目标地址为192.168.0.1
*以及作为发送方的默认接口的IP地址。
*/
eth/=IP(“192.168.0.1”,信息IP地址);
/*使用13作为目标端口和15创建TCP PDU
*作为源端口。
*/
eth/=TCP(13,15);
/*创建一个包含字符串“我是有效负载!”的RawPDU。
*/
eth/=RawPDU(“我是有效载荷!”);
//实际发送者
包裹寄件人;
//通过默认接口发送数据包
发送者。发送(eth,iface);
}

Libtins检查一下,可能有用@Raymond我快速阅读了一下,它看起来像一个解析器/嗅探器,但它看起来不像是自动为我响应TCP/IP或UDP/IP数据包,并只提供有效负载