diff options
author | Zhao Gang <gang.zhao.42@gmail.com> | 2018-08-13 23:12:42 +0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-08-16 12:08:09 -0700 |
commit | ace2a77bc9019d050112bed5a5d1eb2a3363d971 (patch) | |
tree | 20f6fc0ea5231489771c0854ab8ab27ae9d1bc76 /app/src/main/java/com/wireguard | |
parent | c21a2cb4f5ddcb6077e4e66f0d616a8692f8f426 (diff) |
config: fix wrong Peer endpoint string format
When a tunnel is running, saving the tunnel's config with an IPv6
address endpoint like [::1]:42 would result in the wrong format ::1:42.
This patch fixes it.
For endpoints with an IPv6 address(e.g. [::1]:42). Since the default
endpoint InetSocketAddress is created unresolved, getEndpointString()
returns "[::1]:42" (InetSocketAddress.getHostString() returns the
literal hostname). After the endpoint is resolved, getEndpointString()
returns "::1:42" (InetSocketAddress.getHostString() returns the IPv6
address without the square brackets). This inconsistent return values
caused the above mentioned bug.
With this patch, function getEndpointString would return the right
format string whether the endpoint is resolved or not.
Signed-off-by: Zhao Gang <gang.zhao.42@gmail.com>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Peer.java | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java index 49c8b70e..b65f52cb 100644 --- a/app/src/main/java/com/wireguard/config/Peer.java +++ b/app/src/main/java/com/wireguard/config/Peer.java @@ -71,7 +71,10 @@ public class Peer { private String getEndpointString() { if (endpoint == null) return null; - return String.format("%s:%d", endpoint.getHostString(), endpoint.getPort()); + if (endpoint.getHostString().contains(":") && !endpoint.getHostString().contains("[")) + return String.format("[%s]:%d", endpoint.getHostString(), endpoint.getPort()); + else + return String.format("%s:%d", endpoint.getHostString(), endpoint.getPort()); } public int getPersistentKeepalive() { |