2 # vim: shiftwidth=4 tabstop=4
4 # This program dumps to standard output the content of the file written
5 # by pppd's lcp-rtt-file configuration option.
7 # Copyright (C) Marco d'Itri <md@linux.it>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
18 use POSIX qw(strftime);
21 my $data = read_data($ARGV[0] || '/run/ppp-rtt.data');
22 die "The data file is invalid!\n" if not $data;
29 say "status: $s->{status}";
30 say "interval: $s->{echo_interval}";
31 say "position: $s->{position}";
32 say 'elements: ' . scalar(@{ $s->{data} });
35 foreach (my $i= 0; $i < @{ $s->{data} }; $i++) {
36 my $date = strftime('%F %T', localtime($s->{data}->[$i]->[0]));
37 print "$i\t$date\t$s->{data}->[$i]->[1]\t$s->{data}->[$i]->[2]\n";
45 open(my $fh, '<', $file);
49 $bytes_read = sysread($fh, $data, 8192, length($data));
50 } while ($bytes_read == 8192);
53 my ($magic, $status, $position, $echo_interval, $rest)
54 = unpack('NNNN a*', $data);
55 return undef if $magic != 0x19450425;
57 # the position is relative to the C array, not to the logical entries
60 my @rawdata = unpack('(N C a3)*', $rest);
62 while (my ($time, $loss, $rtt) = splice(@rawdata, 0, 3)) {
63 push(@data, [ $time, unpack('N', "\000$rtt"), $loss ]);
68 # skip any "empty" (null) entries
70 # rearrange the list in chronological order
71 (@data[$position+1 .. $#data], @data[0 .. $position]);
76 echo_interval => $echo_interval,
77 position => $position,