private void validateAddressMask(String value, Location location) throws XMLStreamException { final String[] split = value.split("/"); try { if (split.length != 2) { throw new XMLStreamException(MESSAGES.invalidAddressMaskValue(value), location); } // todo - possible DNS hit here final InetAddress addr = InetAddress.getByName(split[0]); // Validate both parts of the split addr.getAddress(); Integer.parseInt(split[1]); } catch (final NumberFormatException e) { throw new XMLStreamException(MESSAGES.invalidAddressMask(split[1], e.getLocalizedMessage()), location, e); } catch (final UnknownHostException e) { throw new XMLStreamException(MESSAGES.invalidAddressValue(split[0], e.getLocalizedMessage()), location, e); } }
private static InterfaceCriteria createSubnetMatchCriteria(final ModelNode model) throws ParsingException { String value; String[] split = null; try { value = model.asString(); split = value.split("/"); if (split.length != 2) { throw new ParsingException(MESSAGES.invalidAddressMaskValue(value)); } // todo - possible DNS hit here final InetAddress addr = InetAddress.getByName(split[0]); // Validate both parts of the split final byte[] net = addr.getAddress(); final int mask = Integer.parseInt(split[1]); return new SubnetMatchInterfaceCriteria(net, mask); } catch (final NumberFormatException e) { throw new ParsingException(MESSAGES.invalidAddressMask(split[1], e.getLocalizedMessage())); } catch (final UnknownHostException e) { throw new ParsingException(MESSAGES.invalidAddressValue(split[0], e.getLocalizedMessage())); } }
private static InterfaceCriteria createSubnetMatchCriteria(final ModelNode model) throws ParsingException { String value; String[] split = null; try { value = model.asString(); split = value.split("/"); if (split.length != 2) { throw new ParsingException(MESSAGES.invalidAddressMaskValue(value)); } // todo - possible DNS hit here final InetAddress addr = InetAddress.getByName(split[0]); // Validate both parts of the split final byte[] net = addr.getAddress(); final int mask = Integer.parseInt(split[1]); return new SubnetMatchInterfaceCriteria(net, mask); } catch (final NumberFormatException e) { throw new ParsingException(MESSAGES.invalidAddressMask(split[1], e.getLocalizedMessage())); } catch (final UnknownHostException e) { throw new ParsingException(MESSAGES.invalidAddressValue(split[0], e.getLocalizedMessage())); } }
public static ParsedResult parseMasked(ModelNode value) throws OperationFailedException { final String[] split = value.asString().split("/"); if (split.length != 2) { throw new OperationFailedException(MESSAGES.invalidAddressMaskValue(value.asString())); } try { // TODO - replace with non-dns routine InetAddress address = InetAddress.getByName(split[0]); int mask = Integer.parseInt(split[1]); int max = address.getAddress().length * 8; if (mask > max) { throw new OperationFailedException(MESSAGES.invalidAddressMask(split[1], "> " + max)); } else if (mask < 0) { throw new OperationFailedException(MESSAGES.invalidAddressMask(split[1], "< 0")); } return new ParsedResult(address, mask); } catch (final UnknownHostException e) { throw new OperationFailedException(MESSAGES.invalidAddressValue(split[0], e.getLocalizedMessage())); } catch (final NumberFormatException e) { throw new OperationFailedException(MESSAGES.invalidAddressMask(split[1], e.getLocalizedMessage())); } }
public static ParsedResult parseMasked(ModelNode value) throws OperationFailedException { final String[] split = value.asString().split("/"); if (split.length != 2) { throw new OperationFailedException(MESSAGES.invalidAddressMaskValue(value.asString())); } try { // TODO - replace with non-dns routine InetAddress address = InetAddress.getByName(split[0]); int mask = Integer.parseInt(split[1]); int max = address.getAddress().length * 8; if (mask > max) { throw new OperationFailedException(MESSAGES.invalidAddressMask(split[1], "> " + max)); } else if (mask < 0) { throw new OperationFailedException(MESSAGES.invalidAddressMask(split[1], "< 0")); } return new ParsedResult(address, mask); } catch (final UnknownHostException e) { throw new OperationFailedException(MESSAGES.invalidAddressValue(split[0], e.getLocalizedMessage())); } catch (final NumberFormatException e) { throw new OperationFailedException(MESSAGES.invalidAddressMask(split[1], e.getLocalizedMessage())); } }