getAddress method
- @protected
- AddressType type, [
- LookupFunction lookup = InternetAddress.lookup
inherited
Read various size bytes depending on type
and parse IPv4/IPv6 address or lookup hostname.
Implementation
@protected
Future<InternetAddress?> getAddress(AddressType type, [LookupFunction lookup = InternetAddress.lookup]) async {
if (type == AddressType.domain) {
final length = await readUint8();
final domain = await readBytes(length);
final addresses = await lookup(ascii.decode(domain));
if (addresses.isEmpty)
return null;
return addresses[0];
}
return InternetAddress.fromRawAddress(
Uint8List.fromList(
await readBytes(type == AddressType.ipv4 ? 4 : 16),
),
);
}