Skip to content

Fix #35: TTL and time are inverted on Windows#36

Merged
point-source merged 1 commit intopoint-source:mainfrom
ckerens:fix-35-win-ttl-time
Jan 4, 2023
Merged

Fix #35: TTL and time are inverted on Windows#36
point-source merged 1 commit intopoint-source:mainfrom
ckerens:fix-35-win-ttl-time

Conversation

@ckerens
Copy link
Contributor

@ckerens ckerens commented Jan 4, 2023

The time and TTL capture groups were in the wrong order for Windows ping output. I converted the regex capture groups to named groups and also updated the regex to capture the Windows time<1ms output.

ping_parser.dart:

            var seq = match.groupNames.contains('seq') 
              ? match.namedGroup('seq') 
              : null;
            var ttl = match.namedGroup('ttl');
            var time = match.namedGroup('time');
            sink.add(
              PingData(
                response: PingResponse(
                  ip: match.namedGroup('ip'),
          // Summary
          if (data.contains(summaryStr)) {
            final match = summaryRgx.firstMatch(data);
            var tx = match?.namedGroup('tx');
            var rx = match?.namedGroup('rx');
            String? time;
            if ((match?.groupCount ?? 0) > 2) {
              time = match?.namedGroup('time');
            }

windows_ping.dart:

        responseStr: RegExp(r'Reply from'),
        responseRgx: RegExp(r'from (?<ip>.*): bytes=(?:\d+) time(?:=|<)(?<time>\d+)ms TTL=(?<ttl>\d+)'),
        summaryStr: RegExp(r'Lost'),
        summaryRgx: RegExp(r'Sent = (?<tx>\d+), Received = (?<rx>\d+), Lost = (?:\d+)'),

Ping command output:

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Console output:

Pinging 127.0.0.1
PingResponse(seq:null, ip:127.0.0.1, ttl:128, time:1.0 ms)
PingSummary(transmitted:1, received:1)

@point-source
Copy link
Owner

Thank you so much! This PR looks excellent and I must admit that I had missed issue #36 on accident. Thank you for covering this. I will review, merge, and publish asap.

@point-source point-source merged commit c0898a9 into point-source:main Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants