Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce IPv6AddressStringParameters.Builder::allowIPv4Mapped(boolean allow) #75

Closed
igor-tsiglyar opened this issue Oct 19, 2021 · 4 comments

Comments

@igor-tsiglyar
Copy link

Hi @seancfoley!

Thanks a lot for the hard work on this library. I am suggesting the new option IPv6AddressStringParameters.Builder::allowIPv4Mapped(boolean allow) to be added that would allow us to declaratively forbid IPv4-mapped IPv6 addresses in a form of ::ffff:c0a8:0a14 which is the same as ::ffff:192.168.10.20 that can already be handled with allowMixed(false).

Best Regards,
Igor

@seancfoley
Copy link
Owner

OK, that's an interesting proposal, will consider it.

Right now, if you allow IPv6, then you can do:

IPAddress addr = new IPAddressString("::ffff:c0a8:0a14").toAddress();
if(addr.isIPv6() && addr.toIPv6().isIPv4Mapped()) {
	// throw exception or otherwise
}

@igor-tsiglyar
Copy link
Author

@seancfoley Sure thank you!

@seancfoley
Copy link
Owner

seancfoley commented Mar 21, 2022

I've given this some thought. The underlying issue is that in order to know whether an address is IPv4-mapped, you first have to parse it, and then compare the initial six segment values with ::ffff. Because of that, it doesn't make sense to make "IPv4-mapped" a validation option; the validation is already over by the time you can check.

That being said, it is possible to do the check prior to converting to an IPAddress object (as in the code shown above). This can be done using the IPAddressString.prefixEquals method. So I am adding the method isIPv4Mapped to IPAddressString which will do just that, allowing the check for IPv4-mapped to be done entirely with an IPAddressString instance.

This is being added to the next release.

@seancfoley
Copy link
Owner

The method IPAddressString.isIPv4Mapped has been added to the latest version 5.3.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants