Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Socket Listen/Send DHCP

by drip (Beadle)
on Oct 11, 2008 at 10:36 UTC ( [id://716581]=note: print w/replies, xml ) Need Help??


in reply to Socket Listen/Send DHCP

I find it easy to use Net::PcapUtils when capturing packets..

here's a part of the module(for dhcp testing) i am trying to finish..

sub getreply{ my $self=shift; my $packetcap1= Net::PcapUtils::open( FILTER =>'udp dst port 6 +8' , DEV => $self->{INTERFACE}, SNAPLEN => 400); my ($packetcap)=Net::PcapUtils::next($packetcap1); my $ethpack=NetPacket::Ethernet->decode($packetcap); my $ipack=NetPacket::IP->decode($ethpack->{data}); my $udpack=NetPacket::UDP->decode($ipack->{data}); my $capture=Net::DHCP::Packet->new($udpack->{data}); my $smac=sprintf ($ethpack->{src_mac}); my $dmac=sprintf ($ethpack->{dest_mac}); my $srcmac= sprintf("%s%s:%s%s:%s%s:%s%s:%s%s:%s%s", split//, +$smac); my $destmac= sprintf("%s%s:%s%s:%s%s:%s%s:%s%s:%s%s", split//, + $dmac); print ("====================BOOT REPLY======================== +\n"); print "\n"; print $ipack->{src_ip} . "=====>" . $ipack->{dest_ip} . "(id : + $ipack->{id}, ttl: $ipack->{ttl})" . "\n"; print "UDP Source: $udpack->{src_port} ==> UDP Destination: $ +udpack->{dest_port} \n"; print "UDP Length: $udpack->{len}, UDP Data Length:", length($ +udpack->{data})," \n"; print "UDP Checksum: $udpack->{cksum} \n"; print "\n"; print "Source Mac address is : ".$srcmac."=====>"; print "Destination Mac address is: " . $destmac."\n"; my $ethtype=sprintf("%0.4x", $ethpack->{type}); print "Ethertype: ". $ethtype . "\n"; print "\n"; print ("====================UDP PACKET======================== +\n"); print $capture->toString()."\n"; return $ipack; }

Hope you find it useful..

Cheers,
drip

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://716581]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-20 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found