brotherandy has asked for the wisdom of the Perl Monks concerning the following question:
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: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.
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:... 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 would be alot sexier to not have that intermediate file... Any help is appreciated$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;
|
|---|