implement IPv6 scoped addresses (RFC4007) #15263
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In order to translate interface names in such scoped addresses the
required
LibC
binding toif_nametoindex()
has been added.This method obviously only works for interfaces (devices) that are
actually present on the system.
The binding for the reverse operation
if_indextoname()
has also beenadded, although its usage is a bit more cumbersome due to
LibC::Char*
buffer handling. The necessary buffer length has been placed into the
constant
LibC::IF_NAMESIZE
, which appears to be16u8
on unix-likesystems and
257u16
on windows.This could potentially be reworked via a preprocessor block at
compile-time as indicated by some folks over on discord, I currently do
not know how to achieve that though.
Scoped identifiers are only valid for link-local (
fe80::
) addresses, e.g.fe80::1%eth0
References:
TODO (to be resolved during the PR discussion):
IF_NAMESIZE
(No clue how do that, haven't found any event of this constant ever changing in the past, might not be worth the trouble?)ArgumentError
orSocket::Error
Socket::Address
spec#scope_id
looks up interface name by index
should remain in theSocket::Address
spec, since it only calls theLibC
bindingI'm happy to adjust/rebase if needed based on feedback or other merges into
master
in the mean time.Fixes #15264 .