如何使用pcap_sendpacket发送ARP回复

问题描述 投票:0回答:1

我正在尝试使用pcap库进行数据包嗅探。到目前为止,我已经能够从本地网络流量中捕获IP和ARP数据包。现在,我想将ARP请求发送到默认网关服务器。我不确定,但是我想我必须使用pcap_sendpacket函数。我没有得到如何构建arp请求的信息,因为当我检查arphdr中定义的net/if_arp.h结构时,它是这样的:

struct arphdr
  {
    unsigned short int ar_hrd;      /* Format of hardware address.  */
    unsigned short int ar_pro;      /* Format of protocol address.  */
    unsigned char ar_hln;       /* Length of hardware address.  */
    unsigned char ar_pln;       /* Length of protocol address.  */
    unsigned short int ar_op;       /* ARP opcode (command).  */
#if 0
    /* Ethernet looks like this : This bit is variable sized
       however...  */
    unsigned char __ar_sha[ETH_ALEN];   /* Sender hardware address.  */
    unsigned char __ar_sip[4];      /* Sender IP address.  */
    unsigned char __ar_tha[ETH_ALEN];   /* Target hardware address.  */
    unsigned char __ar_tip[4];      /* Target IP address.  */
#endif
  };

可以看出,硬件地址区位于#if 0..#endif块中,这意味着已被有效注释掉。我不明白为什么要那样做。为了发送ARP请求,我必须填写这些字段。有人可以对如何使用pcap_sendpacket发送一个ARP请求并在arphdr中填充这些字段吗?

提出任何建议。
c networking pcap libpcap arp
1个回答
0
投票

我最近写了一些可以帮助您的代码:https://github.com/venetwork/venet

© www.soinside.com 2019 - 2024. All rights reserved.