Christopher Fowler wrote:
> This program simply places the packet in an array for the process thread
> to display it.  The next step is that I need to place a timestamp with
> the packet so that the process thread nows when that packet arrived.  To

FWIW, the 'header' argument passed to the pcap loop callback already has
the timestamp of packet receipt from libpcap's perspective.
($header->{tv_sec}, $header->{tv_usec}).

> do that I started heading down the road of creating a Packet object to
> append to the list.  Apparently not a good idea....

Perhaps pass an unblest reference through perl's prefab Thread::Queue class?

  # untested
  my $q = Thread::Queue->new;
  ...
  sub pcap_callback {
    my (undef, $hdr, $pkt) = @_;
    my $job = &share([]);

    @$job = ($pkt, $hdr->{tv_sec});
    $q->enqueue($job);
  }
  ...
  sub worker_thread {
    while (1) {
      my $job = $q->dequeue();
      my ($pkt, $when) = @$job;
      ...
    }
  }

HTH,
Mike

Reply via email to