Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Net::Packet::Dump can't bless non-reference as 'IO::File'

by jeffguy (Sexton)
on Dec 07, 2005 at 23:38 UTC ( #515073=perlquestion: print w/replies, xml ) Need Help??

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

I want code capable of listening for network input (possibly a connect() on an unexpected port) and reading the raw packet, going as low as the IP layer. I don't want to write the code that does all that, so I decided to use Net::Packet::Dump. I started with the first half of the example in the POD of Net::Packet::Dump:
# Instanciate object, will start capturing from network my $dump = Net::Packet::Dump->new( filter => 'tcp', noStore => 1, ); while (1) { if (my $frame = $dump->next) { do_stuff($frame); } }
I get an error: Can't bless non-reference value at .../Dump.pm line 250. So I tried perl -d server.pl. The error occurs at this expression:
bless(Net::Packet::netpacket_pcap_fp($self->_pcapd), 'IO::File')
Net::Packet::netpacket_pcap_fp is a reference to a C function:
FILE * netpacket_pcap_fp(pcap_t *pd){ if (pd == NULL) return(0); else return(pd->sf.rfile); }
and when I print $self->_pcapd in the debugger, I get
'_pcapd' => pcap_tPtr=SCALAR(0x896dde8) -> 144211632
which I think is a reference (pointer) to the beginning of the data structure written in C of type struct pcapd, which is defined as follows:
struct pcap_sf { FILE *rfile; ... }; ... struct pcap { ... struct pcap_sf sf; ... };
So it looks like Net::Packet::Dump is trying to get a FILE* from C and bless it as an 'IO::File'. I've tried many things, even downloading the PeepPoke module so I could inspect that C data structure to be sure that FILE*rfile is not null (and no, it is not null). I found no reference online that suggests others may be having this problem.

I am grateful for any advice you can give! Thanks in advance!

--jeffguy

Replies are listed 'Best First'.
Re: Net::Packet::Dump can't bless non-reference as 'IO::File'
by Corion (Patriarch) on Dec 08, 2005 at 08:15 UTC

    If you're not already tied to use Net::Packet::Dump, I've had great success using Net::Pcap. It also uses the libpcap library and worked without problems for me. The interface is different from Net::Packet::Dump though.

      I'm not yet tied to Net::Packet::Dump. I'll give Net::Pcap a look. Thanks for the advice!
Re: Net::Packet::Dump can't bless non-reference as 'IO::File'
by robin (Chaplain) on Dec 08, 2005 at 13:42 UTC
    I suggest that you:
    • Contact the module author;
    • Try adding the line
      FILE * T_PTROBJ
      to the typemap file in the module distribution, and see whether that helps.
      I tried adding the specified line to typemap and then
      make clean perl Makefile.PL make make install perl server.pl
      But got the same error. I will email the author the contents of my original post. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://515073]
Approved by bageler
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-10-05 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (20 votes). Check out past polls.

    Notices?