Click here to get back home

Net::DHCP::Packet - problems recv'ing broadcasted DHCP Offer

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Net::DHCP::Packet - problems recv'ing broadcasted DHCP Offer DJ Stunks 02-10-2008
Posted by DJ Stunks on February 10, 2008, 8:14 pm
Please log in for more thread options
Hi all,

I'm trying to write a DHCP stress tester to mimic thousands of
complete
DHCP transactions (discover, offer, request, ack) and record the
results.

I'm following the example found at

http://search.cpan.org/src/SHADINGER/Net-DHCP-0.66/examples/dhcpd_test.pl.

I'm able to generate and transmit the Discover packet. The DHCP
server
responds with the offer but my $socket->recv($buf,1024); just hangs.

I'm using Linux and I have eth0 set up with a static IP (10.0.0.1).

I believe the socket blocks because it's never receiving any data -
I believe this is because the offer is broadcasted to udp port 68
but the socket is listening on udp://10.0.0.1:68? This is just a
guess.

My code is as follows. Any suggestions would be appreciated.

Thanks,
-jp


#!/usr/bin/perl

use strict;
use warnings;

use IO::Socket::INET;
use Net::DHCP::Packet;
use Net::DHCP::Constants;

use POSIX qw{ strftime };

#open socket for packet tx & rx
my $socket = IO::Socket::INET->new( Proto => 'udp',
Broadcast => 1,
LocalAddr => '10.0.0.1',
LocalPort => 68,
PeerAddr =>
'255.255.255.255',
PeerPort => 67,
) || die "Unable to create socket: $@\n";

my $discover = Net::DHCP::Packet->new(
Xid => int rand(0xFFFFFFFF),
                Chaddr => 00011aabbccd,
                DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER(),
                DHO_VENDOR_CLASS_IDENTIFIER() => 'MyVendorClassID',
                DHO_DHCP_PARAMETER_REQUEST_LIST() => '1 2 6 12 15 28 67',
                );
$discover->addOptionRaw( 61, pack('H*','0100011aabbccd') );

logger("Sending DISCOVER to 255.255.255.255:67");

$socket->send( $discover->serialize() ) or die "Unable to send
Discover:$!\n";

my $buf;
logger("Waiting for response from server");
print $socket->sockhost(), ':', $socket->sockport(), "\n";
$socket->recv($buf, 1024);

logger("Got response");
my $offer = new Net::DHCP::Packet($buf);
logger($offer->toString());

# sample logger
sub logger{
my $str = shift;
print STDOUT strftime "[%d/%b/%Y:%H:%M:%S] ", localtime;
print STDOUT "$str\n";
}

__END__




Posted by DJ Stunks on February 16, 2008, 3:23 am
Please log in for more thread options
DJ Stunks wrote:
> Hi all,
>
> I'm trying to write a DHCP stress tester to mimic thousands of
> complete
> DHCP transactions (discover, offer, request, ack) and record the
> results.
>
> I'm following the example found at
>
> http://search.cpan.org/src/SHADINGER/Net-DHCP-0.66/examples/dhcpd_test.pl.
>
> I'm able to generate and transmit the Discover packet. The DHCP
> server
> responds with the offer but my $socket->recv($buf,1024); just hangs.
>
> I'm using Linux and I have eth0 set up with a static IP (10.0.0.1).
>
> I believe the socket blocks because it's never receiving any data -
> I believe this is because the offer is broadcasted to udp port 68
> but the socket is listening on udp://10.0.0.1:68? This is just a
> guess.
>
> My code is as follows. Any suggestions would be appreciated.
>
> Thanks,
> -jp
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use IO::Socket::INET;
> use Net::DHCP::Packet;
> use Net::DHCP::Constants;
>
> use POSIX qw{ strftime };
>
> #open socket for packet tx & rx
> my $socket = IO::Socket::INET->new( Proto => 'udp',
> Broadcast => 1,
> LocalAddr => '10.0.0.1',
> LocalPort => 68,
> PeerAddr =>
> '255.255.255.255',
> PeerPort => 67,
> ) || die "Unable to create socket: $@\n";
>
> my $discover = Net::DHCP::Packet->new(
> Xid => int rand(0xFFFFFFFF),
>                 Chaddr => 00011aabbccd,
>                 DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER(),
>                 DHO_VENDOR_CLASS_IDENTIFIER() => 'MyVendorClassID',
>                 DHO_DHCP_PARAMETER_REQUEST_LIST() => '1 2 6 12 15 28 67',
>                 );
> $discover->addOptionRaw( 61, pack('H*','0100011aabbccd') );
>
> logger("Sending DISCOVER to 255.255.255.255:67");
>
> $socket->send( $discover->serialize() ) or die "Unable to send
> Discover:$!\n";
>
> my $buf;
> logger("Waiting for response from server");
> print $socket->sockhost(), ':', $socket->sockport(), "\n";
> $socket->recv($buf, 1024);
>
> logger("Got response");
> my $offer = new Net::DHCP::Packet($buf);
> logger($offer->toString());
>
> # sample logger
> sub logger{
> my $str = shift;
> print STDOUT strftime "[%d/%b/%Y:%H:%M:%S] ", localtime;
> print STDOUT "$str\n";
> }
>
> __END__

It's been almost a week and no responses. Do I need to clarify the
question or post this at c.l.p.m? Are there any suggestions I could
try?

Thanks,
-jp

Posted by DJ Stunks on February 17, 2008, 11:09 am
Please log in for more thread options
> DJ Stunks wrote:
> > Hi all,
>
> > I'm trying to write a DHCP stress tester to mimic thousands of
> > complete
> > DHCP transactions (discover, offer, request, ack) and record the
> > results.
>
> > I'm following the example found at
>
> >http://search.cpan.org/src/SHADINGER/Net-DHCP-0.66/examples/dhcpd_tes....
>
> > I'm able to generate and transmit the Discover packet. The DHCP
> > server
> > responds with the offer but my $socket->recv($buf,1024); just hangs.
>
> > I'm using Linux and I have eth0 set up with a static IP (10.0.0.1).
>
> > I believe the socket blocks because it's never receiving any data -
> > I believe this is because the offer is broadcasted to udp port 68
> > but the socket is listening on udp://10.0.0.1:68? This is just a
> > guess.
>
> > My code is as follows. Any suggestions would be appreciated.
>
> > Thanks,
> > -jp
>
> > #!/usr/bin/perl
>
> > use strict;
> > use warnings;
>
> > use IO::Socket::INET;
> > use Net::DHCP::Packet;
> > use Net::DHCP::Constants;
>
> > use POSIX qw{ strftime };
>
> > #open socket for packet tx & rx
> > my $socket = IO::Socket::INET->new( Proto => 'udp',
> > Broadcast => 1,
> > LocalAddr => '10.0.0.1',
> > LocalPort => 68,
> > PeerAddr =>
> > '255.255.255.255',
> > PeerPort => 67,
> > ) || die "Unable to create socket: $@\n";
>
> > my $discover = Net::DHCP::Packet->new(
> > Xid => int rand(0xFFFFFFFF),
> > Chaddr => 00011aabbccd,
> > DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER(),
> > DHO_VENDOR_CLASS_IDENTIFIER() => 'MyVendorClassID',
> > DHO_DHCP_PARAMETER_REQUEST_LIST() => '1 2 6 12 15 28 67',
> > );
> > $discover->addOptionRaw( 61, pack('H*','0100011aabbccd') );
>
> > logger("Sending DISCOVER to 255.255.255.255:67");
>
> > $socket->send( $discover->serialize() ) or die "Unable to send
> > Discover:$!\n";
>
> > my $buf;
> > logger("Waiting for response from server");
> > print $socket->sockhost(), ':', $socket->sockport(), "\n";
> > $socket->recv($buf, 1024);
>
> > logger("Got response");
> > my $offer = new Net::DHCP::Packet($buf);
> > logger($offer->toString());
>
> > # sample logger
> > sub logger{
> > my $str = shift;
> > print STDOUT strftime "[%d/%b/%Y:%H:%M:%S] ", localtime;
> > print STDOUT "$str\n";
> > }
>
> > __END__
>
> It's been almost a week and no responses. Do I need to clarify the
> question or post this at c.l.p.m? Are there any suggestions I could
> try?

Posted in c.l.p.m:
http://groups.google.com/group/comp.lang.perl.misc/msg/dc432be04691b704?

-jp



Similar ThreadsPosted
ANNOUNCE: Net::Packet 2.00 released January 28, 2005, 12:30 am
Problems using GD.pm January 8, 2005, 8:05 pm
Problems when using Net::MSN 1.022 May 4, 2005, 1:20 pm
LWP problems July 11, 2005, 3:50 pm
PPM Problems on Win.XP November 5, 2007, 4:26 pm
LWP Problems (Authentication?) September 5, 2004, 7:12 am
Net::FTP mdtm problems December 14, 2004, 11:00 pm
Problems with Parse::Lex May 5, 2005, 8:22 pm
DBI_DB2 problems June 2, 2006, 5:24 pm
CGI.pm: encoding problems June 9, 2006, 10:53 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap