Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use pcap library for receiving ipv6 packets?

I am trying to convert hping3 to hping6. hping3 uses Pcap library to receive IPv4 packets. But I need to receive IPv6 packets.

like image 585
Adi Avatar asked Jan 19 '23 13:01

Adi


2 Answers

That is possible. libpcap is able to catch anything on the wire.

like image 79
Jille Timmermans Avatar answered Jan 22 '23 03:01

Jille Timmermans


Example using 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;
  }
}
like image 28
Flexo Avatar answered Jan 22 '23 04:01

Flexo