-
-
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
Add getipaddrs #30349
Add getipaddrs #30349
Conversation
getipaddr would only return the first ip address it would find. getipaddrs will return all the ip addresses it finds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add this to the Sockets section of the documentation alongside getipaddr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but it would be good to have another set of eyes on this from someone who knows more about these things.
EDIT: Needs an entry in NEWS.md.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I wouldn't mind if getipaddr()
used getipaddrs()
but to do that efficiently we'd probably want to make getipaddrs
return an generator.
for i = 0:(count-1) | ||
current_addr = addr + i*_sizeof_uv_interface_address | ||
if 1 == ccall(:jl_uv_interface_address_is_internal, Int32, (Ptr{UInt8},), current_addr) | ||
lo_present = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropping these seems odd to me. seems like these should probably be returned (with each entry being a namedtuple), or a perhaps configurable by function argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current behavior seems like it is a reasonable default, so we can add an option to list internal interfaces as well as external ones at a future time, although it would not be a bad addition to make in this PR given that this new feature won't land in a release until 1.2 in the spring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an include_lo
argument.
julia> getipaddrs(false)
1-element Array{IPv4,1}:
ip"10.255.0.183"
julia> getipaddrs()
1-element Array{IPv4,1}:
ip"10.255.0.183"
julia> getipaddrs(true)
2-element Array{IPv4,1}:
ip"127.0.0.1"
ip"10.255.0.183"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does my latest changes resolve this issue?
I think I'd like this to return a vector of namedtuples with all of the various properties exposed (https://nodejs.org/api/os.html#os_os_networkinterfaces) |
Would this be better in a different function instead of this one? I like the idea of If we want to go down that path, maybe a function named |
Please yes, it would be really unexpected if |
Mention that the function is available in Julia 1.2
Can I get this merged/re-reviewed? |
There's still ongoing discussion about whether to include internal IPs by default. Once that's decided, we can go ahead and merge this. @vtjnash, what are your thoughts on that issue? |
OK, I'm convinced. I just had a naming question: should we go with |
No, I think |
Is this good to merge? Have all the issues been resolved? |
I think this is good to go. I'll merge this at the end of my day (6 hours from now) unless there are objections. |
Thanks, Sam! Nice work 👍 |
* Add getipaddrs getipaddr would only return the first ip address it would find. getipaddrs will return all the ip addresses it finds. * Add getipaddrs to docs * Update NEWS for `getipaddrs` * Add Note To `getipaddrs` Mention that the function is available in Julia 1.2 * Allow `getipaddrs` to Return lo IPs * Add document on `include_lo`
This seems to have broken the buildbots, likely because of some weirdness within the buildbot setup. In particular, the failing test is:
It looks to me like there might be a problem when a machine has multiple IP addresses? |
The problem is how I compared the lists. I think we would want to replace the test with issubset(getipaddrs(), getipaddrs(true)) |
* Add getipaddrs getipaddr would only return the first ip address it would find. getipaddrs will return all the ip addresses it finds. * Add getipaddrs to docs * Update NEWS for `getipaddrs` * Add Note To `getipaddrs` Mention that the function is available in Julia 1.2 * Allow `getipaddrs` to Return lo IPs * Add document on `include_lo`
getipaddr
would only return the first IP address it would find.getipaddrs
will return all the IP addresses it finds.We ran into an issue when running on a machine with multiple IP addresses. The IP returned by
getipaddr
would not be the one we needed. This function solved the issue for us.