ps3mediaserver/ps3mediaserver — pull request #107 by thepadawan42 (2013-04-18 13:01:13+00:00)
Title: Fixnetwork: Incorrect server IP address when starting PMS by launching PMS.exe or PMS.bat

System Information
------------------------
OS: Windows 7 Home Basic Service Pack 1 (64bit)
java version "1.7.0_17"

In my system I have 4 basic network adapters:
1. Ethernet (not used).
2. Wifi Atheros (IPv6 disabled).
3. VirtualBox Host-Only Ethernet Adapter.
4. A VPN adater (TAP).

Problem description
-------------------------
Starting PMS thorugh PMS.exe or PMS.bat:
a) If the VirtualBox adapter is enabled then PMS will use the IP of the VirtualBox adapter.
b) If the VirtualBox adapter is disabled then PMS will use the IP of the VPN adapter.

The correct IP address (the Wifi adapter) is used only when starting PMS directly thorugh PMS.jar

The error is related to passing '-Djava.net.preferIPv4Stack=true' to the JVM, for some reason when this value is set ( PMS.exe and PMS.bat) the JVM returns a NULL value when requesting InterfaceAddresses on the WiFi adapter, then:
a) If the VirtualBox adapter is enabled, the JVM will (successfully) return its InterfaceAddresses and thus the IP of this adapter will be set as the local IP.
b) If the VirtualBox adapter is disabled, then no IP address is selected and PMS (HTTPServer.start()) will simply open a local server socket and afterwards query for the local address; in this case the IP address of the VPN adapter is returned.
In either case, PMS will broadcast the incorrect IP address and the UPNP clients will not be able to contact the server.

Proposed solution
----------------------
When checking the network interfaces (net.pms.network.NetworkConfiguration.checkNetworkInterface()) do not query for InterfaceAddress objects but for IntetAddress, that is, use networkInterface.getInetAddresses() instead of networkInterface.getInterfaceAddresses(); anyway PMS only uses the IP address and not the extra information (subnet mask and broadcast address) provided by the class InterfaceAddresses.

For the VirtualBox adapter to be ignored add the string 'virtualbox' to the list KEY_SKIP_NETWORK_INTERFACES (net.pms.configuration.PmsConfiguration)