From bd9b37a5a0e04a445664e3fa7da90bdafdefdb71 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 13 Apr 2014 20:22:53 -0400 Subject: [PATCH] Fix IPv6 incompatibility in HTTP code due to using raw IPv6 addresses in string format --- .../src/com/limelight/nvstream/http/NvHTTP.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java index 8ed565a2..9434d650 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java @@ -3,6 +3,7 @@ package com.limelight.nvstream.http; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.Inet6Address; import java.net.InetAddress; import java.net.URL; import java.net.URLConnection; @@ -26,7 +27,17 @@ public class NvHTTP { public NvHTTP(InetAddress host, String uniqueId, String deviceName) { this.uniqueId = uniqueId; this.deviceName = deviceName; - this.baseUrl = "http://" + host.getHostAddress() + ":" + PORT; + + String safeAddress; + if (host instanceof Inet6Address) { + // RFC2732-formatted IPv6 address for use in URL + safeAddress = "["+host.getHostAddress()+"]"; + } + else { + safeAddress = host.getHostAddress(); + } + + this.baseUrl = "http://" + safeAddress + ":" + PORT; } private String getXmlString(InputStream in, String tagname)