-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getipaddrs() ignores IPv6 addresses #30604
Comments
I'm spending a bit of time trying to get a PR together to fix this, but before I get too far with a certain approach, how do we want to reconcile this in the API? Would we just widen the output of |
|
Now that I think about this, wouldn't that make this into a (minor) breaking change? Assuming we want to be consistent and apply this logic to |
Returning all IP addresses by default seems better; one could write |
Yes, Do note that the 1-argument version of each function is already taken, so we'd probably want to make a 2-argument function along the same lines. I would prefer that approach. And AFAICT, libuv already returns IPv4 addresses first, although I'm not sure if that's guaranteed in their API. |
I think the design I outlined would also be non-breaking since it would return an IPv4 address in every situation where it did previously. The behavior would only change if there are no IPv4 addresses which would currently be an error. Summarizing:
We may as well guarantee it ourselves since you're never going to have all that many IP addresses. |
I definitely misinterpreted what you were saying; I agree with your summary. I'll update the PR a little later, and also fix the test failures (seems I forgot to test the loopback stuff locally). |
Sounds all good to me. The only additional suggestion I have is that at least the docstring for |
What's the point of preferring IPv4 over IPv6 for ipaddr() if both are available? If it's because of what's done elsewhere* isn't that just legacy since IPv6 did not exist, and Julia can have its own rules? In some faraway future we may all only have IPv6, and at least by then this "i'm getting IPv4" assumption that people might have will be broken (better to surprise people soon?). Why not prefer IPv6 now? Don't we WANT to use that if both are available? If it's because what Julia 1.0 did, isn't Julia 1.1 (or 1.2), rather than Julia 1.0.x, to break such assumptions, and we should just document?
If I'm right, we may also want to have ipaddrs() returrn IPv6 first (and "getipaddr() return getipaddrs()[1]"). |
Why is it bad practice? If you just want some IP address isn’t it fine to call |
Partly because it’s what 1.0 does so we don’t want to break working code. Also because we still live in a world where IPv4 is much more common and is the most likely to “just work”. This overall design is mostly agnostic about which version of IP is used, however, so it does pave the way for switching the default in Julia 2.0 without much disruption. |
I would also agree that in most cases, In general, unless you really don't care about anything other than just getting a "working" IP address (I can't think of any examples where this is the case), using |
Which leads to this question: if someone does need an IP address, what is the right way to pick it? Or should they generally be using a set of IP addresses instead of a single one? |
IMO, a better question to ask, is why would one need a single IP that's registered by their OS, without getting any useful context about it (routes, interface, netmask, etc.)? If you need some arbitrary IP, just hardcode it, that's much less error prone than relying on the OS to provide one (which isn't guaranteed when you exclude loopback). So yes, I think providing a list of all registered IPs is the only API that makes sense, unless we choose to expose a lot more information about network details via Sockets stdlib (which would be cool, but maybe out of scope of a Julia stdlib?). |
Are there any other modern programming-language API's with a function to give you just one single IP address of the local machine? All the ones I know return linked lists or arrays of addresses:
That's for good reasons, as multiple interfaces and multiple-addresses per interface are very common: multi-homed machines, IPv4/IPv6 dual-stack, VPNs, virtual machine interfaces, virtual hosts, service-based addresses, etc. are a fact of life and giving programmers an API that pretends otherwise may lead to naive code that breaks in such situations. (The home PC I am typing this on has currently 7 IPv4 and 3 IPv6 addresses ...) What do you want to know the local IP address(es) for? The only application example for What |
This would only be an argument if IPv6 didn't actually work, while it's been supported by default for years on all platforms. IPv6 is supported in all operating systems Julia supports (and if not configured or no supported IPv4 would be returned), including FreeBSD (and all we likely want to support, iOS and all supported Android back to Lollipop); in all versions of them (back to Windows Vista): https://en.wikipedia.org/wiki/Comparison_of_IPv6_support_in_operating_systems [All except Android also support DHCPv6, and non-support may not matter; neither for ND RDNSS that I'm not familiar with, it seems to be an alternative to DHCHv6.] I googled prefer IPv4 or IPv6 to see what others do and this may or may not apply https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows-for-advanced-users Possibly we would want to check the Registry key to choose what to prefer. There are also some comments there: https://community.spiceworks.com/topic/1986162-prefer-ipv4-over-ipv6 |
The fact that IPv6 works is not a justification for making a breaking change. |
The breaking change we should be making in the future would be the removal of |
Agree with all of that, @jpsamaroo. I think that for now |
I would have expected the new
getipaddrs()
function (#30349) to show on my dual-stack Linux machine both the global scope IP addresses listed byhostname -I
, but currently (as of 1.2.0-DEV.100) it only outputs its IPv4 address:The current docstring does not point out that
getipaddrs()
only returns IPv4 addresses. The returned type does not even have any provisions for IPv6 addresses.I don't think Julia should add in 2019 new API functions that only support IPv4. Instead, the Julia API should encourage a network programming style that works equally well on machines with IPv4-only, IPv6-only and IPv4+IPv6 interfaces. Many people have dual-stack IPv4/IPv6 network interfaces configured these days, for many home users IPv4 is now only provided by carrier-grade NAT (i.e., the less preferred protocol), and big data centers increasingly use IPv6-only subnets internally (as IPv4 addresses trade for nearly $20 these days).
There are also more types of addresses to distinguish in the filter parameters than just
lo
, e.g. a server who sends out invitations for reverse connections might want to avoid listing RFC 4149 temporary addresses.The text was updated successfully, but these errors were encountered: