Skip to content

Commit

Permalink
Remove internal sort from getipaddrs (#32260)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored and JeffBezanson committed Jun 7, 2019
1 parent 9ee7d05 commit 2ebe0de
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 @@ -52,6 +52,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

0 comments on commit 2ebe0de

Please sign in to comment.