Skip to content
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

Merged
merged 9 commits into from
Dec 22, 2018
Merged

Add getipaddrs #30349

merged 9 commits into from
Dec 22, 2018

Conversation

samuel-massinon
Copy link
Contributor

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.

getipaddr would only return the first ip address it would find.
getipaddrs will return all the ip addresses it finds.
@ararslan ararslan added stdlib Julia's standard library feature Indicates new feature / enhancement requests labels Dec 11, 2018
Copy link
Member

@ararslan ararslan left a 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?

stdlib/Sockets/src/addrinfo.jl Outdated Show resolved Hide resolved
Copy link
Member

@ararslan ararslan left a 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.

@ararslan ararslan requested a review from omus December 11, 2018 20:04
@ararslan ararslan added the needs news A NEWS entry is required for this change label Dec 11, 2018
Copy link
Member

@omus omus left a 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
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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"

Copy link
Contributor Author

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?

@vtjnash
Copy link
Member

vtjnash commented Dec 11, 2018

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)

@samuel-massinon
Copy link
Contributor Author

@vtjnash

Would this be better in a different function instead of this one? I like the idea of getipaddrs just returning a list of values getipaddr should return.

If we want to go down that path, maybe a function named get_network_interfaces could return somthing like you posted.

@StefanKarpinski
Copy link
Member

If we want to go down that path, maybe a function named get_network_interfaces could return somthing like you posted.

Please yes, it would be really unexpected if getipaddr returns one IP address and getipaddrs doesn't return a list of the same. If we want a Sockets.getifaces function that returns a bunch of structs or named tuples, that would be fine, but that's a different feature entirely.

Samuel Massinon added 2 commits December 12, 2018 13:51
Mention that the function is available in Julia 1.2
@ararslan ararslan removed the needs news A NEWS entry is required for this change label Dec 12, 2018
@samuel-massinon
Copy link
Contributor Author

Can I get this merged/re-reviewed?

@StefanKarpinski
Copy link
Member

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?

@vtjnash
Copy link
Member

vtjnash commented Dec 13, 2018

OK, I'm convinced. I just had a naming question: should we go with getallipaddr, to parallel with getalladdrinfo?

@StefanKarpinski
Copy link
Member

No, I think getipaddrs is better—I kind of wish that getalladdrinfo had been called getaddrinfo.

@samuel-massinon
Copy link
Contributor Author

Is this good to merge? Have all the issues been resolved?

@omus
Copy link
Member

omus commented Dec 21, 2018

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.

@omus omus merged commit da1df1e into JuliaLang:master Dec 22, 2018
@ararslan
Copy link
Member

Thanks, Sam! Nice work 👍

staticfloat pushed a commit that referenced this pull request Dec 30, 2018
* 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`
@staticfloat
Copy link
Member

This seems to have broken the buildbots, likely because of some weirdness within the buildbot setup. In particular, the failing test is:

Error in testset Sockets:
Test Failed at /buildworker/worker/tester_linux32/build/share/julia/stdlib/v1.2/Sockets/test/runtests.jl:427
  Expression: getipaddrs(true) >= getipaddrs()
   Evaluated: Sockets.IPv4[ip"127.0.0.1", ip"172.19.0.4", ip"172.18.0.4"] >= Sockets.IPv4[ip"172.19.0.4", ip"172.18.0.4"]

It looks to me like there might be a problem when a machine has multiple IP addresses?

@samuel-massinon
Copy link
Contributor Author

The problem is how I compared the lists.
I was thinking that getipaddrs(true) >= getipaddrs() would test if getipaddrs() is a subset of getipaddrs(true). But I guess the order of the list matters.

I think we would want to replace the test with

issubset(getipaddrs(), getipaddrs(true))

staticfloat pushed a commit that referenced this pull request Jan 4, 2019
* 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests stdlib Julia's standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants