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

Hello!

I still have some problems with my code (see my previous thread Problems with Net::Packet (newbie)). I want to write a simplified DHCPv6 Client/Server. So, the first thing I want to do is send out a DHCP SOLLICIT

My packet gets sended right and eventually I receive it on my DHCP Server only it's going through the wrong interface.

I have 3 NICs:
- eth0: my connection with the rest of the network
- eth1: that connects my DHCP Client with the DHCP Server
- eth2: here's nothing is attached but it could be with another pc to form a chain of pc's.

My DHCP script has to send a DHCP sollicit on both eth1 and eth2. Only it sends two DHCP sollicits on eth0.

This is my code:
my $eth = Net::Packet::ETH->new(src=>$mac_end2,dst=>'ff:ff:ff:ff:ff:ff +',type=>'34525'); my $ip6 = Net::Packet::IPv6->new(src=>'::',dst => 'FF02::1:2',nextHead +er=>NP_IPv6_PROTOCOL_UDP ); my $udp = Net::Packet::UDP->new(src=>546,dst=>547); my $data = make_sollicit(); my $frame = Net::Packet::Frame->new(l2=>$eth,l3=>$ip6,l4=>$udp,l7=>$da +ta); $frame->send(); $eth = Net::Packet::ETH->new(src=>$mac_end1,dst=>'ff:ff:ff:ff:ff:ff',t +ype=>'34525'); $ip6 = Net::Packet::IPv6->new(src=>'::',dst => 'FF02::1:2',nextHeader= +>NP_IPv6_PROTOCOL_UDP ); $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->pack; $frame->send();


Two weird things I discovered when trying to find the solution:
- When I ask the src MAC address from Perl it gives the right MAC address. However, when I capture this packet (as well on Client as on Server) the MAC address seems to have shifted:
e.g. 00:12:34:56:78:9A changed in 12:34:56:78:9A:00

-When I capture the packet with Ethereal on the sending pc than it doesn't recognises the packet as DHCPv6. But it recognises the packet as DHCPv6 on the receiving pc

Edited by Chady -- linkified mentioned thread.

Replies are listed 'Best First'.
Re: Net:::Packet sending throug wrong interface
by idsfa (Vicar) on Sep 14, 2005 at 16:12 UTC

    You might want to use $eth1 and $eth2 instead of re-using the variable $eth. That said, have you investigated the created object to confirm it is what you think it is?

    print $eth1->print, "\n";

    It sounds like your frames are being sent to the default MAC. From Net::Packet::Env, it looks like you might want to do something more like:

    my $env1 = Net::Packet::Env->new(dev => 'eth1'); . . . my $frame = Net::Packet::Frame->new(env=>$env1,l3=>$ip6,l4=>$udp,l7=>$ +data);

    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. -- Cyrus H. Gordon
      Thanks for the hint but I keep getting the same problems. Only now I have some new warnings saying that there isn't an IPv4 address bound to the interface