(String ipString)
| 166 | } |
| 167 | |
| 168 | private static byte[] ipStringToBytes(String ipString) { |
| 169 | // Make a first pass to categorize the characters in this string. |
| 170 | boolean hasColon = false; |
| 171 | boolean hasDot = false; |
| 172 | for (int i = 0; i < ipString.length(); i++) { |
| 173 | char c = ipString.charAt(i); |
| 174 | if (c == '.') { |
| 175 | hasDot = true; |
| 176 | } else if (c == ':') { |
| 177 | if (hasDot) { |
| 178 | return null; // Colons must not appear after dots. |
| 179 | } |
| 180 | hasColon = true; |
| 181 | } else if (Character.digit(c, 16) == -1) { |
| 182 | return null; // Everything else must be a decimal or hex digit. |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // Now decide which address family to parse. |
| 187 | if (hasColon) { |
| 188 | if (hasDot) { |
| 189 | ipString = convertDottedQuadToHex(ipString); |
| 190 | if (ipString == null) { |
| 191 | return null; |
| 192 | } |
| 193 | } |
| 194 | return textToNumericFormatV6(ipString); |
| 195 | } else if (hasDot) { |
| 196 | return textToNumericFormatV4(ipString); |
| 197 | } |
| 198 | return null; |
| 199 | } |
| 200 | |
| 201 | private static byte[] textToNumericFormatV4(String ipString) { |
| 202 | byte[] bytes = new byte[IPV4_PART_COUNT]; |
no test coverage detected