point-source / dart_ping

Multi-platform network ping utility for Dart
30 stars 14 forks source link

[Windows] FormatException: Unexpected extension byte (at offset 18) #66

Open ynnob opened 2 months ago

ynnob commented 2 months ago

Almost the same error as #65 but the offset is different.

ping to google.com produces -> Unexpected extension byte (at offset 18) ping to https://google.com produces -> Unexpected extension byte (at offset 64)

OS: Windows 11 Language: German

main.dart

  final ping = Ping(
    'google.com',
    count: 5,
  );

  // Begin ping process and listen for output
  ping.stream.listen((event) {
    print(event);
  });

Exception:

FormatException: Unexpected extension byte (at offset 18)
#0      _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1956:7)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:304:28)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:300:5)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:69:18)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#9      _StreamController._add (dart:async/stream_controller.dart:658:7)
#10     _StreamController.add (dart:async/stream_controller.dart:606:5)
#11     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#13     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#14     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#15     _StreamController._add (dart:async/stream_controller.dart:658:7)
#16     _StreamController.add (dart:async/stream_controller.dart:606:5)
#17     _Socket._onData (dart:io-patch/socket_patch.dart:2455:41)
#18     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#19     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#20     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#21     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#22     _StreamController._add (dart:async/stream_controller.dart:658:7)
#23     _StreamController.add (dart:async/stream_controller.dart:606:5)
#24     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1942:33)
#25     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1385:14)
#26     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#27     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#28     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#29     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)
point-source commented 2 months ago

This is likely because of the default codepage on your OS, since it is set to German. Have you tried the solution mentioned here to override it?

ynnob commented 2 months ago

This is likely because of the default codepage on your OS, since it is set to German. Have you tried the solution mentioned here to override it?

Oh yes i did and i forgot to mention that. The forceCodepage parameter did not change it but since the other user reported success i will retry it again and report back to you.

Maybe i messed something up.

point-source commented 2 months ago

Okay, sounds good. You may also need to try some of the options for non-english language support here: https://github.com/point-source/dart_ping/tree/main/dart_ping#non-english-language-support

If you need help creating German regexes, let me know

ynnob commented 2 months ago

@point-source Thanks! So i digged a bit more.

forceCodepage: true seems to be not relevant for this problem. The problem is indeed the german umlaute that can't be parsed.

Example ping:

ping ynnob.com

Ping wird ausgeführt für ynnob.com [157.90.5.237] mit 32 Bytes Daten:
Antwort von 157.90.5.237: Bytes=32 Zeit=18ms TTL=55
Antwort von 157.90.5.237: Bytes=32 Zeit=17ms TTL=55
Antwort von 157.90.5.237: Bytes=32 Zeit=20ms TTL=55
Antwort von 157.90.5.237: Bytes=32 Zeit=15ms TTL=55

Ping-Statistik für 157.90.5.237:
    Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
    (0% Verlust),
Ca. Zeitangaben in Millisek.:
    Minimum = 15ms, Maximum = 20ms, Mittelwert = 17ms

Setting the codec to Utf8Codec(allowMalformed: true) produces:

image

Setting the code to latin1 produces:

image

Additionally i tried my best to create a regex template for that:

  final parser = PingParser(
    responseRgx: RegExp(
        r'Antwort von (?<ip>.*): Bytes=(?:\d+) Zeit=(?<time>\d+)ms TTL=(?<ttl>\d+)'),
    summaryRgx: RegExp(
        r'Gesendet = (?<tx>\d+), Empfangen = (?<rx>\d+), Verloren = (?:\d+)'),
    timeoutRgx: RegExp(r'host unreachable'),
    timeToLiveRgx: RegExp(
        r'Antwort von (?<ip>.*): Die Gültigkeitsdauer wurde bei der Übertragung überschritten.'),
    unknownHostStr: RegExp(
        r'Ping-Anforderung konnte den Host nicht finden. Überprüfen Sie den Namen, und versuchen Sie es erneut.'),
  );

This produces a output but is missing the bytes. the 'seq' capturing group is not set in my template but i don't think this is intendended to represent the bytes right? just wondering, i don't really need that information.

But what is 'seq' representing in the timeToLiveRgx RegEx? It seems to be required but i can not see you extracting that information int the documentation example https://github.com/point-source/dart_ping/tree/main/dart_ping#non-english-language-support

Btw: Using forceCodepage breaks the custom parser example because the codepage number will trigger a match for timeToLiveRgx which will ultimatly fail because the expected captuaring groups are not actually captured.

Maybe you can help me out a bit with the Regex! Thank you