Merge pull request #151 from ThiefMaster/eventserver-ipv4-only
Only use IPv4 for EventServer connections
This commit is contained in:
commit
34a74b48ab
|
@ -26,6 +26,7 @@ import org.xbmc.kore.jsonrpc.HostConnection;
|
||||||
import org.xbmc.kore.jsonrpc.method.Application;
|
import org.xbmc.kore.jsonrpc.method.Application;
|
||||||
import org.xbmc.kore.jsonrpc.type.ApplicationType;
|
import org.xbmc.kore.jsonrpc.type.ApplicationType;
|
||||||
import org.xbmc.kore.utils.LogUtils;
|
import org.xbmc.kore.utils.LogUtils;
|
||||||
|
import org.xbmc.kore.utils.NetUtils;
|
||||||
import org.xbmc.kore.utils.Utils;
|
import org.xbmc.kore.utils.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -97,7 +98,7 @@ public class EventServerConnection {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
hostInetAddress = InetAddress.getByName(hostInfo.getAddress());
|
hostInetAddress = NetUtils.getInet4AddressByName(hostInfo.getAddress());
|
||||||
} catch (UnknownHostException exc) {
|
} catch (UnknownHostException exc) {
|
||||||
LogUtils.LOGD(TAG, "Got an UnknownHostException, disabling EventServer");
|
LogUtils.LOGD(TAG, "Got an UnknownHostException, disabling EventServer");
|
||||||
hostInetAddress = null;
|
hostInetAddress = null;
|
||||||
|
@ -164,7 +165,7 @@ public class EventServerConnection {
|
||||||
// Get the InetAddress
|
// Get the InetAddress
|
||||||
final InetAddress hostInetAddress;
|
final InetAddress hostInetAddress;
|
||||||
try {
|
try {
|
||||||
hostInetAddress = InetAddress.getByName(hostInfo.getAddress());
|
hostInetAddress = NetUtils.getInet4AddressByName(hostInfo.getAddress());
|
||||||
} catch (UnknownHostException exc) {
|
} catch (UnknownHostException exc) {
|
||||||
LogUtils.LOGD(TAG, "Couldn't get host InetAddress");
|
LogUtils.LOGD(TAG, "Couldn't get host InetAddress");
|
||||||
reportTestResult(callerHandler, callerCallback, false);
|
reportTestResult(callerHandler, callerCallback, false);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InterfaceAddress;
|
import java.net.InterfaceAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
@ -36,6 +37,21 @@ import java.util.Enumeration;
|
||||||
public class NetUtils {
|
public class NetUtils {
|
||||||
private static final String TAG = LogUtils.makeLogTag(NetUtils.class);
|
private static final String TAG = LogUtils.makeLogTag(NetUtils.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an IPv4 address from a host name
|
||||||
|
* @param host The host to look up
|
||||||
|
* @return Inet4Address
|
||||||
|
*/
|
||||||
|
public static Inet4Address getInet4AddressByName(String host) throws UnknownHostException {
|
||||||
|
InetAddress[] addrs = InetAddress.getAllByName(host);
|
||||||
|
for (InetAddress addr : addrs) {
|
||||||
|
if (addr instanceof Inet4Address) {
|
||||||
|
return (Inet4Address)addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new UnknownHostException("No ipv4 address found");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a IPv4 address from an integer to an InetAddress.
|
* Convert a IPv4 address from an integer to an InetAddress.
|
||||||
* @param hostAddress an int corresponding to the IPv4 address in network byte order
|
* @param hostAddress an int corresponding to the IPv4 address in network byte order
|
||||||
|
|
Loading…
Reference in New Issue