Modify

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#10833 closed defect (fixed)

OSX: remote control listening on wrong interface (external IP address instead of localhost)

Reported by: Polarbear-j Owned by: team
Priority: normal Milestone: 14.12
Component: Core remotecontrol Version: latest
Keywords: localhost macosx Cc:

Description

When josm is started while the ethernet interface is up, it listens
to the ethernet IP address instead of localhost.

When ethernet is up but IPv4/DHCP disabled, josm listens to the external
IPv6 address.

When the ethernet status is being changed while josm is already running,
this has no influence.

Environment: MacOS 10.8.5 Java 1.8.0_25-b17, WLAN is off.

INFO: RemoteControl::Accepting connections on port 8111
INFO: RemoteControl::Accepting secure connections on port 8112

telnet localhost 8111

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
telnet: Unable to connect to remote host

(same for 8112)

telnet 192.168.1.### 8111

Trying 192.168.1.###...
Connected to macbookpro-###mac-addr###.fritz.box.
Escape character is ']'.
GET /
...
Server: JOSM RemoteControl

lsof -i:8111

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 2668 ###me### 67u IPv6 0x##### 0t0 TCP macbookpro-###mac-addr###.fritz.box:8111 (LISTEN)


Now, I unplug eth before starting josm, and replug once running:

telnet localhost 8111

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is ']'.
[bingo!]

lsof -i:8111

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 2687 ###me### 67u IPv6 0xe######## 0t0 TCP localhost:8111 (LISTEN)

the "last warnings" below are due to the disconnected network:

Revision: 7787
Repository Root: http://josm.openstreetmap.de/svn
Relative URL: ^/trunk
Last Changed Author: Don-vip
Last Changed Date: 2014-12-11 00:15:17 +0100 (Thu, 11 Dec 2014)
Build-Date: 2014-12-11 02:33:43
URL: http://josm.openstreetmap.de/svn/trunk
Repository UUID: ###
Last Changed Rev: 7787

Identification: JOSM/1.5 (7787 en) Mac OS X 10.8.5
Memory Usage: 347 MB / 910 MB (293 MB allocated, but free)
Java version: 1.8.0_25, Oracle Corporation, Java HotSpot(TM) 64-Bit Server VM

Plugins:
- FastDraw (30762)
- HouseNumberTaggingTool (30762)
- InfoMode (30737)
- PicLayer (30762)
- RoadSigns (30788)
- buildings_tools (30762)
- lakewalker (30737)
- log4j (30762)
- measurement (30737)
- proj4j (30738)
- reverter (30737)
- tageditor (30738)
- terracer (30737)
- turnlanes (30737)
- turnrestrictions (30762)
- undelete (30762)
- utilsplugin2 (30762)
- waydownloader (30762)
- wikipedia (30780)

Last errors/warnings:
- W: Mappaint style "standard" (Maxspeed) icon "maxspeed_icon.svg" not found.
- E: java.net.UnknownHostException: api.openstreetmap.org
- E: org.openstreetmap.josm.io.OsmTransferException: Could not connect to the OSM server. Please check your internet connection.. Cause: java.net.UnknownHostException: api.openstreetmap.org
- E: java.net.UnknownHostException: api.openstreetmap.org
- W: org.openstreetmap.josm.io.OsmTransferException: Could not connect to the OSM server. Please check your internet connection.. Cause: java.net.UnknownHostException: api.openstreetmap.org

Attachments (0)

Change History (16)

comment:1 by Polarbear-j, 10 years ago

Might be the solution for #10411

comment:2 by Polarbear-j, 10 years ago

RemoteControlHttpServer.java calls InetAddress.getByName(Main.pref.get("remote.control.host", "localhost")));

Testing this code:

import java.net.InetAddress;
import java.net.UnknownHostException;

class TestName {
    public static void main(String[] args) {
        InetAddress ip;
        String hostname;
        try {
            ip = InetAddress.getLocalHost();
            hostname = ip.getHostName();
            System.out.println("getLocalHost(): " + ip);
            System.out.println("ip.getHostName(): " + hostname);

            ip = InetAddress.getByName("localhost");
            hostname = ip.getHostName();
            System.out.println("getByName(localhost): " + ip);
            System.out.println("ip.getHostName(): " + hostname);

        } catch (UnknownHostException e) {

            e.printStackTrace();

        }
    }
}

When I use that on my machine while en0 is up, I get

getLocalHost(): localhost/127.0.0.1
ip.getHostName(): localhost
getByName(localhost): localhost/192.168.1.###
ip.getHostName(): localhost

when en0 is unplugged

getLocalHost(): localhost/127.0.0.1
ip.getHostName(): localhost
getByName(localhost): localhost/127.0.0.1
ip.getHostName(): localhost
Last edited 10 years ago by Don-vip (previous) (diff)

comment:3 by Don-vip, 10 years ago

Milestone: 14.12

comment:4 by Don-vip, 10 years ago

I got the exact opposite results on Windows 8.1 (same results with Java 7u72 and 8u25):

getLocalHost(): <Windows machine name>/192.168.0.###
ip.getHostName(): <Windows machine name>
getByName(localhost): localhost/127.0.0.1
ip.getHostName(): localhost

Same situation with my Linux server (Ubuntu 14.04 LTS)

getLocalHost(): #########.######.com/###.###.###.###
ip.getHostName(): #########.######.com
getByName(localhost): localhost/127.0.0.1
ip.getHostName(): localhost

So our method looks good. Only it does not seem to work for some OSX machines?

comment:5 by Don-vip, 10 years ago

Resolution: fixed
Status: newclosed

In 7800/josm:

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

comment:6 by Don-vip, 10 years ago

Thanks for the investigation!

comment:7 by Don-vip, 10 years ago

Ticket #10411 has been marked as a duplicate of this ticket.

comment:8 by Don-vip, 10 years ago

Keywords: macosx added
Summary: remote control listening on wrong interface (external IP address instead of localhost)OSX: remote control listening on wrong interface (external IP address instead of localhost)

comment:9 by Polarbear-j, 10 years ago

Testing latest 7801, unfortunately the issue is not fixed yet.
However the INFO line is more descriptive:

INFO: RemoteControl::Accepting connections on localhost/192.168.1.#:8111
INFO: RemoteControl::Accepting secure connections on localhost/192.168.1.#:8112

which is confirmed by lsof:

lsof -i:8111 -i:8112
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    2043 (me)   88u  IPv6 #      0t0  TCP macbookpro-#.fritz.box:8111 (LISTEN)
java    2043 (me)   89u  IPv6 #      0t0  TCP macbookpro-#.fritz.box:8112 (LISTEN)

This article was discussing some issues in finding the correct interface:
http://crunchify.com/how-to-get-server-ip-address-and-hostname-in-java/

comment:10 by Don-vip, 10 years ago

Resolution: fixed
Status: closedreopened

comment:11 by Polarbear-j, 10 years ago

A workaround is to set remote.control.host=127.0.0.1 instead of the current default remote.control.host=localhost.
Is there a reason why we won't use the numeric IP address in the first place?

comment:12 by Don-vip, 10 years ago

Resolution: fixed
Status: reopenedclosed

In 7826/josm:

fix #10833 - simplify remote control interface management: listen on 127.0.0.1 instead of localhost

comment:13 by stoecker, 10 years ago

You know that you kill "::1" with this? localhost is not 127.0.0.1 anymore.

comment:14 by Don-vip, 10 years ago

Are there ipv6-only systems out there?

comment:15 by Don-vip, 10 years ago

In 7830/josm:

fix #10833 - simplify remote control interface management: let Java return the local loopback interface by itself

in reply to:  14 comment:16 by stoecker, 10 years ago

Replying to Don-vip:

Are there ipv6-only systems out there?

Don't know. But there are systems, where localhost is IPV6 only which gave me really a lot of fun in the past.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.