osociety / network_tools

Networking Tools library which can help you discover open ports, devices on subnet and many other things.
https://pub.dev/packages/network_tools
BSD 3-Clause "New" or "Revised" License
45 stars 13 forks source link

Error runnig getAllPingableDevices inside snap confinement #59

Closed guyluz11 closed 2 years ago

guyluz11 commented 2 years ago

As I am using this package inside of a snap there can be new limitations that can happen. Snap is a very confined environment and the developer needs to specify in advance (and sometimes get permission) in order to use different systems calls and info.

This leads me to a new bug that I am not sure how much it is common to get and it is permission denied on using the avahi-browse command.

This is my log.

  Check that /usr/bin/timeout exists
    command: timeout 2s avahi-browse --all -p
  Check that /usr/bin/timeout exists
    command: timeout 2s mdns-scan
You can make the mdns process better by installing `mdns-scan`
Unhandled exception:
ProcessException: Permission denied
  Command: ping -O -n -W 1 -i 1 -t 255 -c 1 192.168.31.1
#0      _ProcessImpl._start (dart:io-patch/process_patch.dart:401)
#1      Process.start (dart:io-patch/process_patch.dart:38)
#2      BasePing.platformProcess (package:dart_ping/src/ping/base_ping.dart:71)
#3      BasePing._onListen (package:dart_ping/src/ping/base_ping.dart:86)
#4      _runGuarded (dart:async/stream_controller.dart:814)
#5      _StreamController._subscribe.<anonymous closure> (dart:async/stream_controller.dart:692)
#6      _BufferingStreamSubscription._guardCallback (dart:async/stream_impl.dart:417)
#7      _StreamController._subscribe (dart:async/stream_controller.dart:691)
#8      _ControllerStream._createSubscription (dart:async/stream_controller.dart:827)
#9      _StreamImpl.listen (dart:async/stream_impl.dart:473)
#10     _StreamIterator._initializeOrDone (dart:async/stream_impl.dart:1028)
#11     _StreamIterator.moveNext (dart:async/stream_impl.dart:1004)
#12     HostScanner._getHostFromPing (package:network_tools/src/host_scanner.dart)
#13     HostScanner.getAllPingableDevices (package:network_tools/src/host_scanner.dart:41)
<asynchronous suspension>

To fix that and still allow a better way of finding all the SRV lists in Linux if it is possible I am suggesting the following.

  1. Short fix for most cases - by default it will not use the Linux-specific implementation, a boolean value can be passed if needed.
  2. We find a way to catch the error and in case of missing permission it calls the non-Linux specific implementation.

I think 2 will be a little difficult since it is hard to debug the program when it runs as a snap so we can just level it open and not touch it at all. We can add to it p4 after completing 1 for now.

guyluz11 commented 2 years ago

Opened the issue wrong. Will close it.