From 13285dc8f811efe1b89021ab232858e87ef72433 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Fri, 23 Aug 2024 15:33:54 +0000 Subject: [PATCH] [ DDS ] Prefer IPv6 addresses if the VM service is using IPv6 Fixes https://github.com/dart-lang/sdk/issues/56557 Change-Id: I6c18f31a49e6e0d924a467b4b8c1f9d5709d47d8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382020 Commit-Queue: Derek Xu Commit-Queue: Ben Konyi Reviewed-by: Derek Xu Auto-Submit: Ben Konyi --- pkg/dds/lib/src/dds_cli_entrypoint.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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);