Skip to content

Add IPv6 support to getifaddrs() on Windows - #1433

Open
izissise wants to merge 1 commit into
jart:masterfrom
izissise:getifaddrs-ip6-win
Open

Add IPv6 support to getifaddrs() on Windows#1433
izissise wants to merge 1 commit into
jart:masterfrom
izissise:getifaddrs-ip6-win

Conversation

@izissise

Copy link
Copy Markdown
Contributor

We now ask both IPv4 and IPv6 addresses to GetAdaptersAddresses

Ipv6 address flags fill up is left as a todo because I'm not sure how to get the same information as of Linux

I've tested on a x86_64 Windows machine and I get the same informations as of ipconfig.exe

We now ask both IPv4 and IPv6 addresses to GetAdaptersAddresses

Ipv6 address flags fill up is left as a todo because
I'm not sure how to get the same information as of Linux

I've tested on a x86_64 Windows machine and I get the same
informations as of ipconfig.exe
@jart

jart commented Jan 19, 2026

Copy link
Copy Markdown
Owner

I'm asking copilot to take a deeper look. With IPv6 and IPv4 addresses, I would assume what you'd probably want to do is get the family of the socket, and filter results so that interfaces consistent with the socket's family are returned. This way you won't have an issue where code that only expects to iterate over ipv4 interfaces will get surprised. Is that how the BSDs do this?

Also review the brace movement at line 234-241. Name clash detection must work for IPv6.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds IPv6 support to the getifaddrs() implementation on Windows by modifying the Windows-specific ioctl handling code. The implementation now queries both IPv4 and IPv6 addresses from GetAdaptersAddresses and stores IPv6-specific information in the host adapter information structure.

Changes:

  • Modified GetAdaptersAddresses calls to use AF_UNSPEC instead of AF_INET to retrieve both IPv4 and IPv6 addresses
  • Extended HostAdapterInfoNode structure with IPv6-specific fields (interface index, scope, prefix length, flags, and IPv6 address)
  • Updated appendHostInfo to handle IPv6 addresses separately with scope detection logic
  • Modified ioctl_siocgifconf_nt to populate IPv6 fields in the ifreq structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libc/calls/ioctl.c
Comment thread libc/calls/ioctl.c
Comment thread libc/calls/ioctl.c
Comment thread libc/calls/ioctl.c
Comment thread libc/calls/ioctl.c
Comment thread libc/calls/ioctl.c
@izissise

Copy link
Copy Markdown
Contributor Author

I'm asking copilot to take a deeper look. With IPv6 and IPv4 addresses, I would assume what you'd probably want to do is get the family of the socket, and filter results so that interfaces consistent with the socket's family are returned. This way you won't have an issue where code that only expects to iterate over ipv4 interfaces will get surprised. Is that how the BSDs do this?

The filtering would be done on the linked-list returned by getifaddrs, one should check that struct sockaddr *ifa_addr; is AF_INET if they want only ipv4 addresses

linux getifaddrs man says this

getifaddrs() first appeared in glibc 2.3, but before glibc 2.3.3, the implementation supported only IPv4 addresses; IPv6 support was added in glibc 2.3.3. Support of address
families other than IPv4 is available only on kernels that support netlink.

BSDs getifaddrs probably always returned ipv6

Also review the brace movement at line 234-241. Name clash detection must work for IPv6.

I think this is the intended behavior, contrary to ipv4, ipv6 ifaces can have multiples addresses on the same iface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants