Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Getting error while crafting frame through Net::Frame module

by sagarkha (Acolyte)
on Aug 26, 2010 at 07:58 UTC ( #857376=perlquestion: print w/replies, xml ) Need Help??
sagarkha has asked for the wisdom of the Perl Monks concerning the following question:

Hey, i am getting this error while try to craft a TCP/IP frame by using modules like Net:Frame. The error is: Can't call method "payload" on an undefined value at /opt/ActivePerl-5.10/site/lib/Net/Frame/Layer/ line 251. My code
my $target = ''; my $port = '22'; use Net::Frame::Device; use Net::Write::Layer3; use Net::Frame::Simple; use Net::Frame::Dump::Online; use Net::Frame::Layer::IPv4; use Net::Frame::Layer::TCP; my $oDevice = Net::Frame::Device->new(target => $target); my $ip4 = Net::Frame::Layer::IPv4->new( src => '', #src => $oDevice->ip, dst => $target, ); my $tcp = Net::Frame::Layer::TCP->new( dst => $port, options => "\x02\x04\x54\x0b", payload => 'rrrr' ); my $oWrite = Net::Write::Layer3->new(dst => $target); my $oDump = Net::Frame::Dump::Online->new(dev => $oDevice->dev); $oDump->start; my $oSimple = Net::Frame::Simple->new( layers => [ $ip4, $tcp ], ); $i=0; while ($i<10) { $oWrite->open; $oSimple->send($oWrite); $oWrite->close; $i++; } until ($oDump->timeout) { if (my $recv = $oSimple->recv($oDump)) { print "RECV:\n".$recv->print."\n"; last; } } $oDump->stop;
This was working perfectly earlier but all of a sudden it started giving error though i have not chnaged the code. Please help !!

Replies are listed 'Best First'.
Re: Getting error while crafting frame through Net::Frame module
by roboticus (Chancellor) on Aug 26, 2010 at 10:29 UTC


    I don't see any error checking in there, so a method is likely failing and you're calling a method on an object that was never properly created, was destroyed, was damaged, etc. Based on the text of the error message, I'd add this line after $ip4 is created:

    die "Can't connect to target!" unless defined $ip4";


      I added this to my code, but the same result, so i think this object was created without any problem otherwise it would have died. But i am not sure why i am still getting that error.


        I guess I should have been more explicit: You need to add error checking to your code. You keep calling methods on objects that may not have been successfully created. I gave you an example of one thing that may have been wrong, based on an error message. You need to look at other statements that could fail, and check their results.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://857376]
Approved by Corion
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-12-15 12:20 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (431 votes). Check out past polls.