brotherandy has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, I guess the short version of my question is can Net::Pcap::dump_open somehow write to a filehandle? From perldoc Net::Pcap:
Net::Pcap::dump_open($pcap_t, $filename); Open a savefile for writing and return a descriptor for + doing so. If $filename is "-" data is written to standard output.
Passing a filehandle doesn't exactly do much. Ok some further background on what I'm trying to do: I want to pipe the output of the Net::Pcap capture into tethereal to dissect and return a nice string of all the fields. I can currently accomplish this by using a temporary file. That is by passing a filename to the dump_open and then reading it in later on with a call to tethereal with the -r parameter. And then deleting the file:
... my $result = Net::Pcap::loop($pcap_desc, $args{NUMPACKETS}, \&sniffi +t, args{USERDATA}); ... sub sniffit { my ($args,$header,$packet) = @_; my $pcap_dumper_t = Net::Pcap::dump_open($pcap_desc, "/tmp/andy.pc +ap"); Net::Pcap::dump($pcap_dumper_t, $header, $packet); Net::Pcap::dump_close($pcap_dumper_t); open(FH,"tethereal -V -r /tmp/andy.pcap |"); print <FH>; close(FH); unlink("/tmp/andy.pcap"); }
It works but I thought if I could use open2 for all my bidirectional needs to talk to tethereal, and then send it my capture as it comes in and read it's output as it spews it out, all without an intermediate file, that I would fall on the floor shuddering in ecstacy. What I envisioned was something like this:
$pid = open2(*Reader, *Writer, "tethereal -V -i -" ); # open tethere +al reading on STDIN my $pcap_dumper_t = Net::Pcap::dump_open($pcap_desc, *Writer); # wri +te to Writer FH Net::Pcap::dump($pcap_dumper_t, $header, $packet); Net::Pcap::dump_close($pcap_dumper_t); $got = <Reader>; print $got;
It would be alot sexier to not have that intermediate file... Any help is appreciated
  • Comment on Net::Pcap::dump_open, filehandles and Bidirectional Communication with Another Process
  • Select or Download Code