| 880 | // returns net addr + netmask in a single long value |
| 881 | // throws NumericException on error |
| 882 | public static long getIPv4Subnet(CharSequence sequence) throws NumericException { |
| 883 | int netmask = getIPv4Netmask(sequence); |
| 884 | if (netmask == BAD_NETMASK) { |
| 885 | throw NumericException.instance().put("invalid netmask in IPv4 subnet: ").put(sequence); |
| 886 | } |
| 887 | |
| 888 | int mid = Chars.indexOf(sequence, 0, '/'); |
| 889 | |
| 890 | try { |
| 891 | if (mid == -1) { // no netmask |
| 892 | return pack(parseIPv4(sequence), netmask); |
| 893 | } |
| 894 | |
| 895 | int ipv4 = parseIPv4_0(sequence, 0, mid); |
| 896 | return pack(ipv4, netmask); |
| 897 | } catch (NumericException e) { |
| 898 | if (mid == -1) { |
| 899 | throw NumericException.instance().put("invalid IPv4 subnet format, expected format: x.x.x.x/mask, got: ").put(sequence); |
| 900 | } |
| 901 | return pack(parseSubnet0(sequence, 0, mid, getNetmaskLength(netmask)), netmask); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * Returns the maximum value for a specific precision. |