Skip to content

Commit

Permalink
[ DDS ] Prefer IPv6 addresses if the VM service is using IPv6
Browse files Browse the repository at this point in the history
Fixes #56557

Change-Id: I6c18f31a49e6e0d924a467b4b8c1f9d5709d47d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382020
Commit-Queue: Derek Xu <[email protected]>
Commit-Queue: Ben Konyi <[email protected]>
Reviewed-by: Derek Xu <[email protected]>
Auto-Submit: Ben Konyi <[email protected]>
  • Loading branch information
bkonyi authored and Commit Queue committed Aug 23, 2024
1 parent b6e952b commit 13285dc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/dds/lib/src/dds_cli_entrypoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 13285dc

Please sign in to comment.