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

Update getaddrinfo options to support IPv6 hostname resolution #1578

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

cwardcode
Copy link

@cwardcode cwardcode commented Feb 19, 2025

Updated the hints struct to pass the AI_ADDRCONFIG flag to the ai_flags property, addressing issue #1396.

Description:

This ensures hostnames are translated to the correct IP address based on the system’s network configuration, improving compatibility across different environments.

According to the getaddrinfo(3) manual:

     ai_flags       The ai_flags field to which the hints parameter points shall be set to zero or be the bitwise-inclusive OR of one or more of the values AI_ADDRCONFIG, AI_ALL, AI_CANONNAME, AI_NUMERICHOST, AI_NUMERICSERV, AI_PASSIVE, AI_V4MAPPED,
                    AI_V4MAPPED_CFG, and AI_DEFAULT.

                    AI_ADDRCONFIG   If the AI_ADDRCONFIG bit is set, IPv4 addresses shall be returned only if an IPv4 address is configured on the local system, and IPv6 addresses shall be returned only if an IPv6 address is configured on the local
                                    system.

Cross-Platform Considerations:

This change has been tested on Linux, where it allows seamless connections to dual-stack endpoint brokers regardless of whether the device is configured for IPv4, IPv6, or both. While behavior may vary slightly across operating systems, AI_ADDRCONFIG is widely supported, including macOS and Linux variants. On Windows, AI_ADDRCONFIG is also respected on Windows Vista and later.

Testing & Verification:

  • Verified via the Linux platform
  • Successfully connected to a dual-stack endpoint from an IPv6-only device.
  • Confirmed proper resolution and connectivity when only IPv4 is available.
  • Verified no regressions, with all existing tests passing.

This update enhances network flexibility while maintaining full backward compatibility.

@cward-extron cward-extron mentioned this pull request Feb 19, 2025
@icraggs icraggs added this to the 1.3.15 milestone Feb 20, 2025
@icraggs
Copy link
Contributor

icraggs commented Feb 20, 2025

How much difference will this make? Does it help you?

@cwardcode
Copy link
Author

cwardcode commented Feb 20, 2025

Yes actually. With this change I can now connect to AWS’s IoT endpoint in an IPv6-only environment, whereas without the AI_ADDRCONFIG, I cannot.

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