Skip to content

add interface_id in ScopedIpV4#439

Merged
keepsimple1 merged 2 commits intomainfrom
scoped-ipv4
Mar 14, 2026
Merged

add interface_id in ScopedIpV4#439
keepsimple1 merged 2 commits intomainfrom
scoped-ipv4

Conversation

@keepsimple1
Copy link
Copy Markdown
Owner

Help fixing issue #437

Problem

Currently for IPv4 there is no way to find out on which interface the service address(es) are found, while IPv6 doesn't have this problem.

Solution

Added interface_id() to ScopedIpV4 to match ScopedIpV6 that returns the interface on which a service address is found.

@hgomersall
Copy link
Copy Markdown
Contributor

It looks like this would certainly allow a workaround. I think probably by iterating over the interfaces from if_addrs and comparing each with the returned InterfaceId. That said, is there a reason the address can't be added to the interface ID directly from if_addrs to avoid the extra layer?

@keepsimple1
Copy link
Copy Markdown
Owner Author

That said, is there a reason the address can't be added to the interface ID directly from if_addrs to avoid the extra layer?

I didn't want to do that as it feels like against the design purpose of struct InterfaceId, but I think we could add a convenient method to do the legwork for the users. Please see the updated diff for get_addrs() method of InterfaceId. Would that work for you?

@keepsimple1 keepsimple1 merged commit 43bd8f3 into main Mar 14, 2026
3 checks passed
@keepsimple1 keepsimple1 deleted the scoped-ipv4 branch March 14, 2026 03:30
@hgomersall
Copy link
Copy Markdown
Contributor

Well done, thanks for this!

keepsimple1 added a commit that referenced this pull request Mar 25, 2026
ScopedIpV4 previously had a single interface_id (added in #439). This meant the same IPv4 address discovered via different interfaces would appear as two distinct entries in ResolvedService.addresses. This can cause confusion about how many IPv4 addresses actually discovered.

Unlike IPv6 link-local addresses where the scope ID is part of the address identity, for IPv4 the interface is discovery metadata.

Changes

ScopedIpV4 to hold Vec<InterfaceId> instead of a single interface_id.
Implements Eq/Hash manually based on addr only, so the same IPv4 address deduplicates correctly in HashSet.
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