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

IPV6 support on tcp_client.h #2784

Closed
Simon-Janos opened this issue Jun 28, 2023 · 6 comments
Closed

IPV6 support on tcp_client.h #2784

Simon-Janos opened this issue Jun 28, 2023 · 6 comments

Comments

@Simon-Janos
Copy link
Contributor

Hi,

I have noticed in connect() of tcp_client.h (and of tcp_client-windows.h as well) that it is tied to IPv4, could it be changed AF_UNSPEC for ipv6 support?
hints.ai_family = AF_INET; // IPv4

https://github.com/gabime/spdlog/blob/v1.x/include/spdlog/details/tcp_client.h#L61
https://github.com/gabime/spdlog/blob/v1.x/include/spdlog/details/tcp_client-windows.h#L86

Sincerely,
Janis

@tt4g
Copy link
Contributor

tt4g commented Jun 28, 2023

That structure is a hint, and AF_INET specifies IPv4, so if you pass a hostname to getaddrinfo(), IPv4 will be returned.
However, it is only a hint. If you pass an IPv6 string to the host argument, it should connect to IPv6.

See: https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo

@Simon-Janos
Copy link
Contributor Author

So on my ipv6 rocky8/redhat environments I get "::getaddrinfo failed: Name or service not known" error. Which clearly does exist and sure enough no problem on ipv4. If I try with the service ip address (IPv6) I got "address family not supported" whiles it does work with a proper ipv4 address.

@tt4g
Copy link
Contributor

tt4g commented Jun 28, 2023

Are you saying that passing an IPv6 string will not work? If so, it may have to be AF_INET6 or AF_UNSPEC to work.

@Simon-Janos
Copy link
Contributor Author

So on some linux/c version - at least - they are incompatible. AF_UNSPEC is a better approach or at least we are better making it configurable.

@gabime
Copy link
Owner

gabime commented Jun 30, 2023

@Simon-Janos PR is welcome.

@gabime
Copy link
Owner

gabime commented Jul 2, 2023

Implemented in #2790

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

3 participants