One thought for comparison.. try using the perl leasequery tool to see if you see it generating the same packet on the wire.<div><br></div><div>I have tried the perl tool before and was never able to get it working either. I'm wondering if there is a common issue here (probably me not getting it to work right either way :)</div>
<div><br></div><div>I went as far as trying to get a perl cli tool to work for what I needed so that I could just "exec" it from within PHP. This was not ideal of course but I never got either one working. </div>
<div><br></div><div>Just a thought... I'd work on it too but I'm seriously swamped at work right now. Hopefully that will get better soon............</div><div><br></div><div>Thanks.<br><br><div class="gmail_quote">
On Fri, May 21, 2010 at 9:12 AM, Pat Winn <span dir="ltr"><<a href="mailto:ptwinn@cimtel.net">ptwinn@cimtel.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
All,<br>
I have gotten as far as to send a packet which in my WireShark<br>
packet trace..at least..LOOKS to me like it *should* be correct.<br>
Yet, I still receive no response.<br>
<br>
The code snippet I'm attaching is but a simple single file<br>
with the basic code needed to construct and send a DHCPLEASEQUERY<br>
packet in PHP. It will send the packet but not listen for a<br>
response. As yet, I'm only watching the server output, server logs<br>
and WireShark packet sniff/traces to see what is going back and<br>
forth over the wire.<br>
<br>
The packet goes out, looks good but as I mentioned above, the<br>
server never responds to it. Either I'm still off on something<br>
in the packet or something is not right in the server?<br>
(running 4.1.1 freshly compiled).<br>
<br>
The code (real IP's replaced with dummys of course..):<br>
(sorry if my web mail client borks up the formatting)..<br>
<br>
#!/usr/bin/php -e<br>
<?<br>
<br>
$packet = Array();<br>
<br>
$packet['op'] = '01';<br>
$packet['htype'] = '00';<br>
$packet['hlen'] = '00';<br>
$packet['hops'] = '00';<br>
$packet['xid'] = '12345678';<br>
$packet['secs'] = '0005';<br>
$packet['flags'] = '0000';<br>
$packet['ciaddr'] = ip2hex("1.2.3.4");<br>
$packet['yiaddr'] = ip2hex("0.0.0.0");<br>
$packet['siaddr'] = ip2hex("0.0.0.0");<br>
$packet['giaddr'] = ip2hex("1.2.5.1");<br>
$packet['chaddr'] = '00000000000000000000000000000000';<br>
$packet['sname'] =<br>
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';<br>
$packet['file'] =<br>
'0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';<br>
$packet['magic'] = '63825363';<br>
$packet['options'] = int2hex(53) . int2hex(1) . int2hex(10); //<br>
DHCPLEASEQUERY packet type<br>
$packet['options'] .= int2hex(55) . int2hex(2) . int2hex(58);<br>
$packet['options'] .= int2hex(82) . int2hex(255);<br>
<br>
$myPacket = pack("H2H2H2H2H8H4H4H8H8H8H8H32H128H256H8H*",<br>
$packet['op'], $packet['htype'], $packet['hlen'], $packet['hops'],<br>
$packet['xid'],<br>
$packet['secs'], $packet['flags'], $packet['ciaddr'],<br>
$packet['yiaddr'], $packet['siaddr'],<br>
$packet['giaddr'], $packet['chaddr'], $packet['sname'], $packet['file'],<br>
$packet['magic'], $packet['options']);<br>
<br>
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);<br>
socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);<br>
socket_bind($socket, "1.2.5.1", 68);<br>
<br>
$error = socket_sendto($socket, $myPacket, strlen($myPacket), 0,<br>
'1.2.5.1', 67);<br>
<br>
if ($error === FALSE) {<br>
print("Send failed for address");<br>
print_r("ERROR: ". $error ." while trying to send.");<br>
} else {<br>
echo "Sent ". $error ." bytes\n";<br>
}<br>
<br>
// convert a string to hex values<br>
function str2hex($s) {<br>
$hex = '';<br>
for ($i = 0 ; $i < strlen($s); $i++) {<br>
$hex .= dechex(ord($s[$i]));<br>
}<br>
<br>
return($hex);<br>
}<br>
<br>
// convert an ip address to hex values<br>
function ip2hex($ip) {<br>
$t = explode(".", $ip);<br>
return int2hex($t[0]) . int2hex($t[1]) . int2hex($t[2]) . int2hex($t[3]);<br>
}<br>
<br>
// convert an int value to 0 padded hex value<br>
function int2hex($int) {<br>
$hex = base_convert($int, 10, 16);<br>
<br>
switch(strlen($hex)) {<br>
case 1:<br>
case 3:<br>
case 7: $hex = '0' . $hex; break;<br>
case 5: $hex = '000' . $hex; break;<br>
}<br>
<br>
return $hex;<br>
}<br>
<br>
?><br>
<br>
<br>
..and then, the packet trace (what was actually sent):<br>
<br>
No. Time Source Destination Protocol Info<br>
104942 1994.263153 1.2.5.1 1.2.5.1 DHCP DHCP Lease<br>
query - Transaction ID 0x12345678<br>
<br>
Frame 104942 (292 bytes on wire, 292 bytes captured)<br>
Arrival Time: May 21, 2010 09:56:26.129252000<br>
[Time delta from previous captured frame: 0.000276000 seconds]<br>
[Time delta from previous displayed frame: 1.795716000 seconds]<br>
[Time since reference or first frame: 1994.263153000 seconds]<br>
Frame Number: 104942<br>
Frame Length: 292 bytes<br>
Capture Length: 292 bytes<br>
[Frame is marked: False]<br>
[Protocols in frame: sll:ip:udp:bootp]<br>
[Coloring Rule Name: UDP]<br>
[Coloring Rule String: udp]<br>
Protocol: IP (0x0800)<br>
Internet Protocol, Src: 1.2.5.1 (1.2.5.1), Dst: 1.2.5.1 (1.2.5.1)<br>
Version: 4<br>
Header length: 20 bytes<br>
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)<br>
0000 00.. = Differentiated Services Codepoint: Default (0x00)<br>
.... ..0. = ECN-Capable Transport (ECT): 0<br>
.... ...0 = ECN-CE: 0<br>
Total Length: 276<br>
Identification: 0x0000 (0)<br>
Flags: 0x04 (Don't Fragment)<br>
0... = Reserved bit: Not set<br>
.1.. = Don't fragment: Set<br>
..0. = More fragments: Not set<br>
Fragment offset: 0<br>
Time to live: 64<br>
Protocol: UDP (0x11)<br>
Header checksum: 0x7ffb [correct]<br>
[Good: True]<br>
[Bad : False]<br>
Source: 1.2.5.1 (1.2.5.1)<br>
Destination: 1.2.5.1 (1.2.5.1)<br>
User Datagram Protocol, Src Port: bootpc (68), Dst Port: bootps (67)<br>
Source port: bootpc (68)<br>
Destination port: bootps (67)<br>
Length: 256<br>
Checksum: 0xd472 [correct]<br>
[Good Checksum: True]<br>
[Bad Checksum: False]<br>
Bootstrap Protocol<br>
Message type: Boot Request (1)<br>
Hardware type: NET/ROM pseudo<br>
Hardware address length: 0<br>
Hops: 0<br>
Transaction ID: 0x12345678<br>
Seconds elapsed: 5<br>
Bootp flags: 0x0000 (Unicast)<br>
0... .... .... .... = Broadcast flag: Unicast<br>
.000 0000 0000 0000 = Reserved flags: 0x0000<br>
Client IP address: 1.2.3.4 (1.2.3.4)<br>
Your (client) IP address: 0.0.0.0 (0.0.0.0)<br>
Next server IP address: 0.0.0.0 (0.0.0.0)<br>
Relay agent IP address: 1.2.5.1 (1.2.5.1)<br>
Client address not given<br>
Server host name not given<br>
Boot file name not given<br>
Magic cookie: (OK)<br>
Option: (t=53,l=1) DHCP Message Type = DHCP Lease query<br>
Option: (53) DHCP Message Type<br>
Length: 1<br>
Value: 0A<br>
Option: (t=55,l=2) Parameter Request List<br>
Option: (55) Parameter Request List<br>
Length: 2<br>
Value: 3A52<br>
58 = Renewal Time Value<br>
82 = Agent Information Option<br>
End Option<br>
<br>
<br>
Umm....help?<br>
<br>
Thanks again for any help offered!!<br>
<br>
<br>
--<br>
Patrick T. Winn<br>
Systems Engineer<br>
Cimarron Telephone Co.<br>
(918) 865-3311 x280 - office<br>
(918) 606-6602 - cell<br>
<br>
<br>
<br>
_______________________________________________<br>
dhcp-hackers mailing list<br>
<a href="mailto:dhcp-hackers@lists.isc.org">dhcp-hackers@lists.isc.org</a><br>
<a href="https://lists.isc.org/mailman/listinfo/dhcp-hackers" target="_blank">https://lists.isc.org/mailman/listinfo/dhcp-hackers</a><br>
</blockquote></div><br></div>