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/IPv4.pm line 251. My code
my $target = '172.28.89.120'; 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 => '172.28.89.120', #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

    sagarkha:

    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";

    ...roboticus

      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.

        sagarkha:

        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.

        ...roboticus