【问题标题】:Can I use pcap library for receiving ipv6 packets?我可以使用 pcap 库来接收 ipv6 数据包吗?
【发布时间】:2011-09-09 13:16:35
【问题描述】:

我正在尝试将 hping3 转换为 hping6。 hping3 使用 Pcap 库来接收 IPv4 数据包。但我需要接收 IPv6 数据包。

【问题讨论】:

  • 您绝对可以使用 libpcap 来捕获 ipv6 数据包(因为 wireshark 和帮派肯定会捕获它们)。从来没有直接使用过 libpcap,我无法为您提供更多帮助,但绝对有可能。

标签: c tcl ipv6 pcap libpcap


【解决方案1】:

这是可能的。 libpcap 能够捕获网络上的任何东西。

【讨论】:

  • +1,这包括不是 IPv4 的东西(比如 ARP,它直接位于以太网帧的顶部)。在 IPv4 PCAP 代码中您将使用 ETHERTYPE_IP 的地方,您只需使用 ETHERTYPE_IPV6 代替,并带有适当的标头结构。
【解决方案2】:

使用ETHERTYPE_IPV6的示例:

static u_int16_t ether_packet(u_char *args, const struct pcap_pkthdr *pkthdr, co
nst u_char *p) {
  struct ether_header *eptr = (struct ether_header*)p;

  assert(pkthdr->caplen <= pkthdr->len);

  assert(pkthdr->caplen >= sizeof(struct ether_header));

  return eptr->ether_type;
}


// This is the callback. assumes ethernet frame.
static void pcap_callback(u_char *args,const struct pcap_pkthdr* pkthdr,const u_
char* p)
{
  const u_int16_t type = ether_packet(args, pkthdr, p);
  switch (ntohs(type)) {
  case ETHERTYPE_IP:
    // handle IPv4 
    break;
  case ETHERTYPE_IPV6:
    // handle v6
    break;
  }
}

【讨论】:

    猜你喜欢
    • 2016-01-27
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 2011-03-22
    • 2015-02-08
    • 1970-01-01
    相关资源
    最近更新 更多