how do I write code to support IPv4 & IPv6?

Sep 2, 2010 at 12:31 PM


Any advice regarding how to write code once but that supports IPv4 or IPv6, or at least minimize code duplication?

For example I currently have:

IpV4Datagram ip = packet.Ethernet.IpV4;
IPAddress sourceip = IPAddress.Parse(ip.Source.ToString());

Q1 - As I want to do comparisons later in the code on IP addresses, however how could I write this in the way that supports IPv4 and IPv6?

Q2 - Also I note in VS2010 for myself when I type "packet.Ethernet." the intellisense gives me the option for "packet.Ethernet.IpV4", however I don't see an option for "packet.Ethernet.IpV6" show up???





Sep 2, 2010 at 12:37 PM

IPv6 is not supported in Pcap.Net yet.

It is one of the future features and you can vote for it in the Issue Tracker.

Sep 2, 2010 at 12:57 PM

oh, thanks for clarifying - any ideas how much traffic these days is IPv6?    Also, re trying to get a handle on the impact of not yet supporting IPv6, would this impact traffic coming from or going to an IPv6 address?  That is, when I capture a packet, then want to access the IPvXDatagram, what is the determining factor in fact for whether it is a IPv4 or IPv6 packet (I'm noting now I don't quite understand).   For example if I'm packet sniffing on a PC that has an IPv4 address however there is browser traffic to/from web sites that might be both IPv4 and IPv6 addresses then which traffic would turn up in as IPv6? i.e. out of:

- outgoing from local IPv4 PC to remote IPv6
- incoming from remote IPv6 to local IPv4 PC 


Sep 2, 2010 at 2:55 PM

First of all, I'm no expert on IPv6.

Every Ethernet packet contains the information about its next layer in the Ethernet Type field. It tells you whether its an IPv4 packet, IPv6 packet, ARP packet or other.

IPv4 networks have IPv4 packets and IPv6 network have IPv6 packets. Of course your LAN (Etherent) can handle both IPv4 and IPv6, but usually each network has one kind of network protocol...

Routers that connect different networks can (and should) translate IPv4 packets to IPv6 packets (and their addresses).


Have you tried sending packets from your local IPv4 network (or host) to an IPv6 address?

Sep 2, 2010 at 4:13 PM

Haven't tried this - I might try this with Wireshark and have a look

In terms of understanding the impact of not having IPv6 available I wonder whether the answer might be this then:  If you local network is IPv4 then you catch all packets irrespective of whether they come to/from a remote IPv6 network (as your local network is IPv4), and if your local network is IPv6 then you won't catch any packets as IPv6 isn't implemented in yet.     Would this be correct do you think?

Sep 2, 2010 at 8:28 PM

Yes. The packets in your network are in your network's protocol.