Ignore:
Timestamp:
2014-12-12T20:08:22+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #10833 - robustness to localhost name resolution for remote control

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java

    r7702 r7800  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io.remotecontrol;
     3
     4import java.net.InetAddress;
     5import java.net.UnknownHostException;
    36
    47import org.openstreetmap.josm.Main;
     
    3437    static final int protocolMajorVersion = 1;
    3538    static final int protocolMinorVersion = 7;
     39
     40    private static final String LOCALHOST = "localhost";
    3641
    3742    /**
     
    7176        return Main.pref.getPreferencesDir() + "remotecontrol/";
    7277    }
     78
     79    /**
     80     * Returns the inet address used for remote control.
     81     * @return the inet address used for remote control
     82     * @throws UnknownHostException if the local host name could not be resolved into an address.
     83     * @since 7800
     84     */
     85    public static InetAddress getInetAddress() throws UnknownHostException {
     86        String hostname = Main.pref.get("remote.control.host", LOCALHOST);
     87        InetAddress result = InetAddress.getByName(hostname);
     88        // Sometimes localhost resolution does not work as expected, see #10833
     89        if (LOCALHOST.equalsIgnoreCase(hostname) && !LOCALHOST.equalsIgnoreCase(result.getHostName())) {
     90            InetAddress localhostAddr = InetAddress.getLocalHost();
     91            // Use this result if it's better. Not sure if it's a Java bug or not
     92            if (LOCALHOST.equalsIgnoreCase(localhostAddr.getHostName())) {
     93                result = localhostAddr;
     94            }
     95        }
     96        return result;
     97    }
    7398}
Note: See TracChangeset for help on using the changeset viewer.