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

Remove internal sort from getipaddrs #32260

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Standard library changes

* Fixed `repr` such that it displays `Time` as it would be entered in Julia ([#32103]).

#### Sockets

* `getipaddrs` returns IP addresses in the order provided by libuv ([#32260]).
* `getipaddr` prefers to return the first `IPv4` interface address provided by libuv ([#32260]).

#### Statistics

* `mean` now accepts both a function argument and a `dims` keyword ([#31576]).
Expand Down
15 changes: 5 additions & 10 deletions stdlib/Sockets/src/addrinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,14 @@ ip"fe80::9731:35af:e1c5:6e49"
"""
function getipaddr(addr_type::Type{T}) where T<:IPAddr
addrs = getipaddrs(addr_type)

if length(addrs) == 0
error("No networking interface available")
end
return addrs[1]

# Prefer the first IPv4 address
i = something(findfirst(ip -> ip isa IPv4, addrs), 1)
return addrs[i]
end
getipaddr() = getipaddr(IPv4)

Expand Down Expand Up @@ -295,14 +299,5 @@ function getipaddrs(addr_type::Type{T}=IPAddr; loopback::Bool=false) where T<:IP
end
end
ccall(:uv_free_interface_addresses, Cvoid, (Ptr{UInt8}, Int32), addr, count)
sort!(addresses, lt=(addr1,addr2) -> begin
if addr1 isa IPv4 && addr2 isa IPv6
return true
elseif addr1 isa IPv6 && addr2 isa IPv4
return false
else
return addr1 < addr2
end
end)
return addresses
end