diff options
author | Samuel Holland <samuel@sholland.org> | 2018-06-19 00:43:49 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-06-19 21:59:44 -0500 |
commit | b9991e4229b49e08beebbae5519cfed5de99c051 (patch) | |
tree | 4a233404b0b910539b149fbbda97f689ec31d6bc /app/src/main/java/com/wireguard/config/IPCidr.java | |
parent | util: Extract non-Android utility interfaces (diff) | |
download | wireguard-android-b9991e4229b49e08beebbae5519cfed5de99c051.tar.xz wireguard-android-b9991e4229b49e08beebbae5519cfed5de99c051.zip |
config: Refactor IPCidr and use of InetAddress
Use a canonically-named utility class to tack on methods to the existing
InetAddress class. Rename IPCidr to InetNetwork so it better matches
InetAddress and is more pronouceable :) While here, simplify the
constructor and toString() functions, and properly implement hashCode().
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/IPCidr.java')
-rw-r--r-- | app/src/main/java/com/wireguard/config/IPCidr.java | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/app/src/main/java/com/wireguard/config/IPCidr.java b/app/src/main/java/com/wireguard/config/IPCidr.java deleted file mode 100644 index bfa92e07..00000000 --- a/app/src/main/java/com/wireguard/config/IPCidr.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2018 Samuel Holland <samuel@sholland.org> - * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -package com.wireguard.config; - -import java.net.Inet4Address; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.util.Locale; - -public class IPCidr { - private final InetAddress address; - private int cidr; - - @SuppressWarnings("MagicNumber") - public IPCidr(String in) { - cidr = -1; - final int slash = in.lastIndexOf('/'); - if (slash != -1 && slash < in.length() - 1) { - try { - cidr = Integer.parseInt(in.substring(slash + 1), 10); - in = in.substring(0, slash); - } catch (final Exception ignored) { - } - } - address = Attribute.parseIPString(in); - if ((address instanceof Inet6Address) && (cidr > 128 || cidr < 0)) - cidr = 128; - else if ((address instanceof Inet4Address) && (cidr > 32 || cidr < 0)) - cidr = 32; - } - - public InetAddress getAddress() { - return address; - } - - public int getCidr() { - return cidr; - } - - @Override - public String toString() { - return String.format(Locale.getDefault(), "%s/%d", address.getHostAddress(), cidr); - } -} |