Hi Monks,
I am now studying
Net::DHCP::Packet by runing an example script copied from the module's document. but I find that all the DHCP packets sent by this script with the source IP address of my machine, but this address is supposed to be
0.0.0.0. I added a line which specifies the LocalAddr into it but the result was same. I looked into the source, and find out the problem may be is in
IO::Socket::INET. But even after I explicitly assigned 0.0.0.0 to LocalAddr, the result doesn't change at all. Could any one help me on this? Thanks a lot
Below is the code:
#!/usr/bin/perl
# Simple DHCP client - sending a broadcasted DHCP Discover request
use IO::Socket::INET;
use Net::DHCP::Packet;
use Net::DHCP::Constants;
# creat DHCP Packet
$discover = Net::DHCP::Packet->new(
xid => int(rand(0xFFFFFFFF)), # random xid
Flags => 0x8000, # ask for broadcast answer
DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER()
);
# send packet
$handle = IO::Socket::INET->new(Proto => 'udp',
Broadcast => 1,
PeerPort => '67',
LocalPort => '68',
LocalAddr => '0.0.0.0', # I added this line
PeerAddr => '255.255.255.255')
or die "socket: $@"; # yes, it uses $@ here
$handle->send($discover->serialize())
or die "Error sending broadcast inform:$!\n";
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.