Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Issue with Net::Frame packages

by WalkingZero (Sexton)
on Jun 01, 2008 at 10:09 UTC ( #689534=perlquestion: print w/replies, xml ) Need Help??
WalkingZero has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I had posted this code at the end of my discussion in ARP Lookups and at the time of posting the code worked flawlessly. Went to run it today and I'm getting:
Can't call method "opCode" on an undefined value at ./ line 46.

If I step it back a level just to the ref of $r->ref->{ARP} there is nothing there. However if I go back and do a r->print or if I unpack the raw data, I can see the ARP layer plain as day. I supposed I could use ->print and regex my output, but the modules i'm using shouldn't require me to do that. Any ideas? Code Below:

#!/usr/bin/perl use Net::ARP; use Net::Netmask; use Net::Frame::Simple; use Net::Frame::Dump::Online; my $dev= "eth1"; $ifconf= `ifconfig $dev`; $ifconf=~ /\d+\.\d+\.\d+\.\d+/; $ipdec= $&; $ifconf=~ /Mask:\d+\.\d+\.\d+\.\d+/; $nmaskdec= $&; $nmaskdec=~s/Mask://; my $netblock= $ipdec . ":" . $nmaskdec ; $netmask=new Net::Netmask ($netblock); my @iprange = $netmask->enumerate; $arpDump=Net::Frame::Dump::Online->new( dev => $dev, filter => 'arp'); $arpDump->start; my %livehosts; my $reply; $counter=0; while ($counter<3){ for $ipts (@iprange){ Net::ARP::send_packet($dev,$ipdec,$ipts,"00:18:de:34:8e:7b","f +f:ff:ff:ff:ff:ff","request"); } until ($arpDump->timeout){ if ($next=$arpDump->next){ my $r=Net::Frame::Simple->newFromDump($next); $opc=$r->ref->{ARP}->opCode; next unless $opc == 2; $livehosts{$r->ref->{ARP}->srcIp}=$r->ref->{ARP}->src; } } $arpDump->timeoutReset; $counter++; } foreach $key (keys %livehosts){ print "IP Address $key is up with mac of $livehosts{$key} \n"; } $arpDump->stop;

UPDATE: Arg , what a total waste of time. I went and reloaded Net::Frame from CPAN and now it works fine. Sorry, folks.

Replies are listed 'Best First'.
Re: Issue with Net::Frame packages
by Anonymous Monk on Jun 01, 2008 at 10:39 UTC
    Try adding some error checking. Example
    sub computeLengths { my $self = shift; if (exists $self->[$__ref]->{IPv4} || exists $self->[$__ref]->{IPv6 +}) { my $ip = $self->[$__ref]->{IPv4} || $self->[$__ref]->{IPv6}; if (exists $self->[$__ref]->{TCP}) { my $tcp = $self->[$__ref]->{TCP}; $tcp->computeLengths; $ip->computeLengths({ payloadLength => $tcp->getLength + $tcp->getPayloadLength, });

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://689534]
Approved by Erez
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2018-04-21 20:02 GMT
Find Nodes?
    Voting Booth?