Skip to content

Commit

Permalink
Refactor traceroute output parsing for IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
Valéria Frčková committed May 14, 2024
1 parent 2d06c2c commit c0498d8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/command/traceroute-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isIpPrivate } from '../lib/private-ip.js';
import { scopedLogger } from '../lib/logger.js';
import { InvalidOptionsException } from './exception/invalid-options-exception.js';

const reHost = /(\S+)\s+\((?:((?:\d+\.){3}\d+)|([\da-fA-F:]+(?:::)?[\da-fA-F:]+))\)/; // /(\S+)\s+\((?:((?:\d+\.){3}\d+)|([\da-fA-F:]))\)/;
const reHost = /(\S+)\s+\((?:((?:\d+\.){3}\d+|[\da-fA-F:]+))\)/;
const reRtt = /(\d+(?:\.?\d+)?)\s+ms(!\S*)?/g;

export type TraceOptions = {
Expand Down Expand Up @@ -230,7 +230,7 @@ export class TracerouteCommand implements CommandInterface<TraceOptions> {

return {
host: hostMatch[0] ?? '',
resolvedAddress: hostMatch[2] !== undefined ? hostMatch[2] : (hostMatch.length >= 3 ? hostMatch[3] : ''),
resolvedAddress: hostMatch[2],
};
}

Expand All @@ -240,7 +240,7 @@ export class TracerouteCommand implements CommandInterface<TraceOptions> {

return {
resolvedHostname: hostMatch?.[1] ?? '*',
resolvedAddress: hostMatch?.[2] !== undefined ? hostMatch?.[2] : (hostMatch && hostMatch.length >= 3 ? (hostMatch?.[3] ?? '*') : '*'),
resolvedAddress: hostMatch?.[2] ?? '*',
timings: rttList.map(rtt => ({ rtt })),
};
}
Expand Down

0 comments on commit c0498d8

Please sign in to comment.