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

Hi,

First of all: I'm a total newbie so sorry if I ask some basic question. I'm trying to write some kind of simplified DHCPv6 client/server application.

To do this I have my own subroutine that makes a DHCPv6 packet. That has to be wrapped in a UDP packet -> IP packet -> Ethernet packet (so I think, please correct me if I'm wrong).

This is my code:
$eth = Net::Packet::ETH->new(src=>$mac_end1,dst=>'ff:ff:ff:ff:ff:ff',t +ype=>'34525'); $ip6 = Net::Packet::IPv6->new(dst => 'FF02::1:2'); $udp = Net::Packet::UDP->new(src=>546,dst=>547); $data = make_sollicit(); $frame = Net::Packet::Frame->new(l2=>$eth,l3=>$ip6,l4=>$udp,l7=>$data) +; $frame->send();


The make sollicit is my own subroutine that generates the DHCPv6 packet. Now when I execute this, perl says: 'Can't call method getLength without a package or object reference at /usr/local/lib/perl/5.8.7/Net/Packet/UDP.pm line 114'

I'm guessing it's a simple mistake in the use of the Net::Packet modules. Can anyone help me? Or is there a better alternative to do this? I didn't find much more support for IPv6

Replies are listed 'Best First'.
Re: Problems with Net::Packet (newbie)
by fizbin (Chaplain) on Sep 13, 2005 at 16:47 UTC
    Another poster has pointed out that the problem is that the argument in "l7" that you're passing to Net::Packet::Frame->new isn't a Net::Packet object. Therefore, let's fix that:
    $eth = Net::Packet::ETH->new(src=>$mac_end1,dst=>'ff:ff:ff:ff:ff:ff',t +ype=>'34525'); $ip6 = Net::Packet::IPv6->new(dst => 'FF02::1:2'); $udp = Net::Packet::UDP->new(src=>546,dst=>547); $data = Net::Packet::Layer7->new(data => make_sollicit()); $frame = Net::Packet::Frame->new(l2=>$eth,l3=>$ip6,l4=>$udp,l7=>$data) +; $frame->send();
    Either that, or you could change make_sollicit so that it returns its data wrapped up in a Net::Packet::Layer7 object.
    --
    @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/
      Thanks that did the trick! I still have weird problems but I'll try to solve them first without bothering you guys!
Re: Problems with Net::Packet (newbie)
by davidrw (Prior) on Sep 13, 2005 at 15:55 UTC
    This is that line in the Net/Packet/UDP.pm source:
    $totalLength += $frame->l7->getLength if $frame->l7;
    So it is expecting that $frame->17 be an object that has a getLength method... in your case $frame->17 is your $data, which is your make_sollicit(), so the question is, what exactly is make_sollicit()? Can you rewrite it so that it returns an object that supports getLength() ?