Skip to content

Commit

Permalink
Remove internal sort from getipaddrs (#32260)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2ebe0de)
  • Loading branch information
omus authored and KristofferC committed Jun 9, 2019
1 parent 5a1a361 commit 9ce9000
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ Standard library changes
form `kron(u, v')`, `u * v'`, and `u .* v'` where `u` and `v` are sparse vectors or column
views ([#24980]).

#### 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
* `quantile` now accepts in all cases collections whose `eltype` is not a subtype of `Number` ([#30938]).

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

0 comments on commit 9ce9000

Please sign in to comment.