Skip invalid nameserver entries from resolv.conf and ignore IPv6 zone IDs
#187
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.
This changeset improves parsing of the
/etc/resolv.conffile by skipping invalid nameserver entries and also ignoring any IPv6 zone IDs (scope IDs). This is now more in line with how glibc also completely ignores invalid entries and also only provides somewhat limited support for IPv6 zone IDs.Prior to these changes, having a completely valid
/etc/resolv.confwith anameserver ::0%lo0entry would throw anInvalidArgumentExceptionbecause both theUdpTransportExecutorandTcpTransportExecutorconsider this to be an invalid IP address. To make matters worse, this also happens if this is only a secondary DNS server address that's not even in active use, so it will not even try to primary DNS server in this case.After applying these changes, it will now use
::0(without the zone ID / scope ID). This isn't exactly perfect, but it's a major improvement over the previous situation. Altogether, this is a rather rare situation and using routable IPv6 is usually preferable.If you're curious, PHP provides only very limited support for IPv6 addresses with scope IDs. Once this situation improves, we could potentially add full support for scope IDs.
Supersedes / closes #181 (thanks @remicollet for the original suggestion!)
Refs #75 and #76 for similar logic when parsing
/etc/hosts