Skip to content

Commit

Permalink
reverse the Networkinterface.getNetworkInterfaces output order to
Browse files Browse the repository at this point in the history
get a more proper local ip address.
  • Loading branch information
advancedxy committed Aug 14, 2014
1 parent 6b8de0e commit 087a785
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,10 @@ private[spark] object Utils extends Logging {
if (address.isLoopbackAddress) {
// Address resolves to something like 127.0.1.1, which happens on Debian; try to find
// a better address using the local network interfaces
for (ni <- NetworkInterface.getNetworkInterfaces) {
// getNetworkInterfaces returns ifs in reverse order compared to ifconfig output order
// on unix-like system. On windows, it returns in index order.
// It's more proper to pick ip address following the ifconfig output order
for (ni <- NetworkInterface.getNetworkInterfaces.toList.reverse) {
for (addr <- ni.getInetAddresses if !addr.isLinkLocalAddress &&
!addr.isLoopbackAddress && addr.isInstanceOf[Inet4Address]) {
// We've found an address that looks reasonable!
Expand Down

0 comments on commit 087a785

Please sign in to comment.