Returns the {@link InetAddress} having the given string representation. <p>This deliberately avoids all nameservice lookups (e.g. no DNS). <p>IPv4-mapped IPv6 addresses (e.g. {@code "::ffff:192.168.0.1"}) are returned as {@link Inet4Address} objects, not {@link Inet6Address}. This is consistent wi
(String ipString)
| 159 | * required by Java's {@link InetAddress}) |
| 160 | */ |
| 161 | @CanIgnoreReturnValue // TODO(b/219820829): consider removing |
| 162 | public static InetAddress forString(String ipString) { |
| 163 | Scope scope = new Scope(); |
| 164 | byte[] addr = ipStringToBytes(ipString, scope); |
| 165 | |
| 166 | // The argument was malformed, i.e. not an IP string literal. |
| 167 | if (addr == null) { |
| 168 | throw formatIllegalArgumentException("'%s' is not an IP string literal.", ipString); |
| 169 | } |
| 170 | |
| 171 | return bytesToInetAddress(addr, scope.scope); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Returns {@code true} if the supplied string is a valid IP string literal, {@code false} |