_internet_on: try IPv4, if not acceptable — try IPv6 #4151
Merged
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.
Hello!
Thank you for this great project!
I use IPv6-only workstation with Gentoo GNU/Linux. To connect to IPv4-only resources, I use public services NAT64 + DNS64.
All the software works fine, except PlatformIO:
I found function
_internet_on()
uses IPv4-only codes = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
. The next command,s.connect((host, 80))
, raises an error "[Errno 101] Network is unreachable" in my OS.Then I found official documentation https://docs.python.org/3/library/socket.html, there are examples "… The next two examples are identical to the above two, but support both IPv4 and IPv6. …". I found these examples a bit complicated to integrate into PlatformIO (but you can create your own, better solution, based on official Python examples).
I created a patch, which works fine: if IPv4 is not available, try IPv6. Here is an example:
P.S.: maybe it is better to try first IPv6, and then IPv4, so IPv4 users will have good error message. But right now, as I understand, PlatformIO doesn't show error message, so this is doesn't matter.