#!/usr/bin/perl

$SIG{PIPE} = 'IGNORE';

use IO::Socket::INET;
print "$IO::Socket::INET::VERSION\n";
my $socket = IO::Socket::INET->new(LocalPort => 12345, Listen => 5) or die $!;
print "$socket\n";
while (my $ns = $socket->accept) {
  select $ns;
  $|=1;
  print "Accepted.\n";
  open TCPDUMP, "tcpdump -l |" or die $!;
  while (<TCPDUMP>) {
    print STDOUT $_;
    last unless print $ns $_;
  }
  print "Closed.\n";
}
print "accept: $!";
