parseIPv4Address static method

List<int> parseIPv4Address(
  1. String host, [
  2. @Since.new('3.10') int start = 0,
  3. @Since.new('3.10') int? end
])

Parses the host as an IP version 4 (IPv4) address, returning the address as a list of 4 bytes in network byte order (big endian).

If start and end are provided, only that range, which must be a valid range of host, is parsed. Defaults to all of host.

Throws a FormatException if (the range of) host is not a valid IPv4 address representation, meaning something of the form <octet>.<octet>.<octet>.<octet> where each octet is a decimal numeral in the range 0..255 with no leading zeros.

Implementation

static List<int> parseIPv4Address(
  String host, [
  @Since('3.10') int start = 0,
  @Since('3.10') int? end,
]) {
  end = RangeError.checkValidRange(start, end, host.length);
  var list = Uint8List(4);
  _parseIPv4Address(host, start, end, list, 0);
  return list;
}