dart-lang / sdk

The Dart SDK, including the VM, dart2js, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
9.94k stars 1.53k forks source link

[dart:io] Reverse DNS lookup on LAN ip Android regression #54435

Open guyluz11 opened 6 months ago

guyluz11 commented 6 months ago

Reverse DNS lookup on LAN IP Android does not work in the last Flutter version. I understand that this is dart-lang and my issue is with Flutter Android but I got redirected https://github.com/flutter/flutter/issues/140506

Can reproduce for Android, tested also on Flutter Linux and couldn't reproduce. I think this is a regression. Only for local IP (LAN).

  1. Create an app and prepare an Android device.
  2. Find a local network's IP with a hostname.
  3. Add internet permission to Android <uses-permission android:name="android.permission.INTERNET"/>
  4. Paste the example code and replace ip_with_host_name with the IP you found.

Getting an error in the console that the devices can't be found.

Logs

Logs ```console E/flutter ( 6212): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Failed reverse host lookup (OS Error: hostname nor servname provided, or not known, errno = 8), address = 192.168.31.81 E/flutter ( 6212): #0 _NativeSocket.reverseLookup. (dart:io-patch/socket_patch.dart:538:9) E/flutter ( 6212): E/flutter ( 6212): #1 _MyHomePageState.initialize (package:untitled/main.dart:42:18) E/flutter ( 6212): ```

Code sample

Code sample ```dart import 'dart:io'; import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @override void initState() { super.initState(); initialize(); } initialize() async { print('go'); print('Ip ${(await InternetAddress('ip_with_host_name').reverse()).host}'); } @override Widget build(BuildContext context) { return const Scaffold( body: SizedBox(), ); } } ```

Flutter Doctor output

Doctor output ```console Flutter 3.16.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision 78666c8dc5 (2 days ago) • 2023-12-19 16:14:14 -0800 Engine • revision 3f3e560236 Tools • Dart 3.2.3 • DevTools 2.28.4 ```
a-siva commented 6 months ago

@guyluz11 You mention above that this is a regression. Which version onwards you are seeing this failure. That would help us track down the potential change which could have triggered the regression.

guyluz11 commented 6 months ago

I can't really tell sorry, I'm pretty sure it worked a year ago.

a-siva commented 6 months ago

@guyluz11 Have you also upgraded the version of Android you are using or is it the same version you had when it was working? I am trying to determine if there could be a potential regression in Android OS.

guyluz11 commented 6 months ago

Android version got upgraded as well

brianquinlan commented 6 months ago

InternetAddress.reverse() uses getnameinfo on Android.

guyluz11 commented 6 months ago

Android 14 has already been released on Samsung phones. I am testing on Samsung Galaxy s21 Ultra, Android 14, One UI 6.0. Can someone test on Android 13?

iadept commented 5 months ago

I have the same problem, tested on Android emulator starting from version 9

a-siva commented 1 month ago

Not sure if there is anything to do on the Dart side if this is a regression in Android's getnameinfo function.