4 # Accept intercept data from l2tpns, write to a file in pcap format
5 # (http://wiki.ethereal.com/Development/LibpcapFileFormat) suffixed
6 # with timestamp. Killing the process with SIGHUP causes a new file
13 use Time::HiRes 'gettimeofday';
15 (my $cmd = $0) =~ s!.*/!!;
17 die "Usage: $cmd PREFIX PORT\n" unless @ARGV == 2 and $ARGV[1] =~ /^\d+$/;
19 my ($prefix, $port) = @ARGV;
20 my $sock = IO::Socket::INET->new(
24 ) or die "$cmd: can't bind to port $port ($!)\n";
27 $SIG{HUP} = sub { $restart++ };
29 my $header = pack LSSlLLL =>
30 0xa1b2c3d4, # magic no
33 0, # timezone offset (GMT)
34 0, # timestamp accuracy
36 12; # link type (RAW_IP)
45 $file = $prefix . time;
46 $cap = IO::File->new("> $file")
47 or die "$0: can't create capture file $file ($!)\n";
50 or die "$0: error writing to $file ($!)\n";
53 while ($sock->recv($buf, 1600))
56 # packet header: sec, usec, included size, original size
57 (pack LLLL => (gettimeofday), (length $buf) x 2),
59 ) or die "$0: error writing to $file ($!)\n";