(Tokenizer st, Name origin)
| 171 | } |
| 172 | |
| 173 | void |
| 174 | rdataFromString(Tokenizer st, Name origin) throws IOException { |
| 175 | elements = new ArrayList(1); |
| 176 | while (true) { |
| 177 | Tokenizer.Token t = st.get(); |
| 178 | if (!t.isString()) |
| 179 | break; |
| 180 | |
| 181 | boolean negative = false; |
| 182 | int family = 0; |
| 183 | int prefix = 0; |
| 184 | |
| 185 | String s = t.value; |
| 186 | int start = 0; |
| 187 | if (s.startsWith("!")) { |
| 188 | negative = true; |
| 189 | start = 1; |
| 190 | } |
| 191 | int colon = s.indexOf(':', start); |
| 192 | if (colon < 0) |
| 193 | throw st.exception("invalid address prefix element"); |
| 194 | int slash = s.indexOf('/', colon); |
| 195 | if (slash < 0) |
| 196 | throw st.exception("invalid address prefix element"); |
| 197 | |
| 198 | String familyString = s.substring(start, colon); |
| 199 | String addressString = s.substring(colon + 1, slash); |
| 200 | String prefixString = s.substring(slash + 1); |
| 201 | |
| 202 | try { |
| 203 | family = Integer.parseInt(familyString); |
| 204 | } |
| 205 | catch (NumberFormatException e) { |
| 206 | throw st.exception("invalid family"); |
| 207 | } |
| 208 | if (family != Address.IPv4 && family != Address.IPv6) |
| 209 | throw st.exception("unknown family"); |
| 210 | |
| 211 | try { |
| 212 | prefix = Integer.parseInt(prefixString); |
| 213 | } |
| 214 | catch (NumberFormatException e) { |
| 215 | throw st.exception("invalid prefix length"); |
| 216 | } |
| 217 | |
| 218 | if (!validatePrefixLength(family, prefix)) { |
| 219 | throw st.exception("invalid prefix length"); |
| 220 | } |
| 221 | |
| 222 | byte [] bytes = Address.toByteArray(addressString, family); |
| 223 | if (bytes == null) |
| 224 | throw st.exception("invalid IP address " + |
| 225 | addressString); |
| 226 | |
| 227 | InetAddress address = InetAddress.getByAddress(bytes); |
| 228 | elements.add(new Element(negative, address, prefix)); |
| 229 | } |
| 230 | st.unget(); |
nothing calls this directly
no test coverage detected