diff --git a/pkg/dds/lib/src/dds_cli_entrypoint.dart b/pkg/dds/lib/src/dds_cli_entrypoint.dart index ce44c14583b9..665ac276cf54 100644 --- a/pkg/dds/lib/src/dds_cli_entrypoint.dart +++ b/pkg/dds/lib/src/dds_cli_entrypoint.dart @@ -55,16 +55,21 @@ ${argParser.usage} argResults[DartDevelopmentServiceOptions.vmServiceUriOption], ); + // Prefer IPv4 addresses if we can't determine the address type from the + // VM service host. + final preferredProtocolType = + InternetAddress.tryParse(remoteVmServiceUri.host)?.type ?? + InternetAddressType.IPv4; + // Resolve the address which is potentially provided by the user. late InternetAddress address; final bindAddress = argResults[DartDevelopmentServiceOptions.bindAddressOption]; try { final addresses = await InternetAddress.lookup(bindAddress); - // Prefer IPv4 addresses. for (int i = 0; i < addresses.length; i++) { address = addresses[i]; - if (address.type == InternetAddressType.IPv4) break; + if (address.type == preferredProtocolType) break; } } on SocketException catch (e, st) { writeErrorResponse('Invalid bind address: $bindAddress', st);