seladb / PcapPlusPlus

PcapPlusPlus is a multiplatform C++ library for capturing, parsing and crafting of network packets. It is designed to be efficient, powerful and easy to use. It provides C++ wrappers for the most popular packet processing engines such as libpcap, Npcap, WinPcap, DPDK, AF_XDP and PF_RING.
https://pcapplusplus.github.io/
The Unlicense
2.68k stars 651 forks source link

why there is no matchSubnet() for ipv6 address #444

Closed DinoStray closed 4 years ago

DinoStray commented 4 years ago

For ipv4 address, I can use matchSubnet() checks whether the address matches a subnet.
But for ipv6, how can I do this?

I also asked this question in :

https://stackoverflow.com/questions/62129703/for-lib-pcapplusplus-why-there-is-no-matchsubnet-for-ipv6-address

seladb commented 4 years ago

That's a good point, this feature doesn't currently exist, probably because no one has asked for it 😄

Would you consider adding it?

seladb commented 4 years ago

@DinoStray please let me know if you'd consider implementing this feature

DinoStray commented 4 years ago

@DinoStray please let me know if you'd consider implementing this feature

Sorry, I go out for a weekend trip. OK, pleasure with that.
But first of all, maybe I should learn more about ipv6

seladb commented 4 years ago

Thanks, I really appreciate your help!

You can read about IPv6 subnet mask here: https://tools.ietf.org/id/draft-lubashev-ipv6-addr-mask-01.html https://docs.netgate.com/pfsense/en/latest/book/network/ipv6-subnets.html

seladb commented 4 years ago

hi @DinoStray , any progress on that?

DinoStray commented 4 years ago

Sorry it took me some time to understand some concepts.

For IPv4, we need subnet mask.

so the method should be:

bool matchSubnet(const IPv4Address& subnet, const IPv4Address& subnetMask) const;

But for IPv6, we only need prefix length.

so the method should be:

bool matchSubnet(const IPv6Address& subnet, uint8_t prefixLength) const;

Am I right? @seladb

seladb commented 4 years ago

Yes, that's correct. The prefixLength tells how many bytes to use in the mask

DinoStray commented 4 years ago

I committed a PR for this issue

seladb commented 4 years ago

Thanks! please take a look at my PR comments

DinoStray commented 4 years ago

I committed a new PR following your comments.