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

In reply to Re: Socket Listen/Send DHCP by drip
in thread Socket Listen/Send DHCP by maclaren_sg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.