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

Improves IPv6 addresses formatting #416

Merged
merged 2 commits into from
Nov 19, 2024

Conversation

denizzzka
Copy link
Contributor

@denizzzka denizzzka commented Nov 16, 2024

We have lack of support IPv6 addresses formatting, and especially, IPv4 addresses encapsulated into IPv6

This code is never called and IPv4 addresses on IPv6 interfaces logged as 0:0:0:0:0:ffff:bca2:ee5 instead of ::ffff:188.162.14.229

I made own implementation because inet_ntop from glibc internally does redundand buffer copying, uses stringz, errno and not handles rare ::2 address case

@denizzzka denizzzka marked this pull request as ready for review November 16, 2024 06:54
@denizzzka denizzzka marked this pull request as draft November 19, 2024 04:23
@denizzzka denizzzka marked this pull request as ready for review November 19, 2024 04:32
@denizzzka denizzzka force-pushed the adds_improve_IPv6_toString branch from b83af85 to 5a738b1 Compare November 19, 2024 05:18
@denizzzka
Copy link
Contributor Author

::0.0.0.x case actually doesn't handled in *nix/Linux, Windows and Postgres due to old bind9 error. In fact, this become a de-facto standard and if this fix, then some comparisons in user code can be unexpectedly breaked

Thus I also removed support for ::0.0.0.x addresses

@s-ludwig
Copy link
Member

Sounds like the HTTP server code should really operate on the binary representation of the IPv6 address and then just format the last four bytes as IPv4 for robustness.

But having the special formatting built-in here definitely makes things nicer in other places, too. Can you maybe just also add a simple unit test to resolveHost with use_dns set to false? Just to ensure this is working in both directions for all platforms.

@denizzzka
Copy link
Contributor Author

denizzzka commented Nov 19, 2024

Can you maybe just also add a simple unit test to resolveHost with use_dns set to false?

Test that is currently implemented already uses use_dns = false. Added resolveHost call with use_dns = true

@denizzzka
Copy link
Contributor Author

denizzzka commented Nov 19, 2024

Sounds like the HTTP server code should really operate on the binary representation of the IPv6 address and then just format the last four bytes as IPv4 for robustness.

Same IPv6 address can be represented by various ways. So we can't rely on any specific format. And there seems to be no such places in Vibe.d

But having the special formatting built-in here definitely makes things nicer in other places, too.

@denizzzka denizzzka marked this pull request as draft November 19, 2024 12:36
@denizzzka denizzzka force-pushed the adds_improve_IPv6_toString branch from b816393 to 8bac4f2 Compare November 19, 2024 12:38
@denizzzka denizzzka marked this pull request as ready for review November 19, 2024 12:38
@s-ludwig
Copy link
Member

Test that is currently implemented already uses use_dns = false. Added resolveHost call with use_dns = true

Sorry, I've missed that the toString tests actually also test the inverse direction.

Same IPv6 address can be represented by various ways. So we can't rely on any specific format. And there seems to be no such places in Vibe.d

The binary representation is the same (NetworkAddress.sockAddrInet6.sin6_addr), but this is something for a separate PR - the changes for toString are looking good!

@s-ludwig s-ludwig merged commit ed8ce9d into vibe-d:master Nov 19, 2024
13 checks passed
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

Successfully merging this pull request may close these issues.

2 participants