ID:               40674
 Updated by:       [EMAIL PROTECTED]
 Reported By:      matth at mystictrd dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Sockets related
 Operating System: Debian 3.1
 PHP Version:      5.2.1
 New Comment:

"A non-authoritative server simply ignores the request, leading to an
implementation dependent time out for the client to give up on the
request and ask for a new IP."

Isn't that exactly what is happening here?


Previous Comments:
------------------------------------------------------------------------

[2007-03-06 17:12:03] matth at mystictrd dot com

My first message had a working example but here it is again with more 
information.

The purpose is to see DHCP requests from a DHCP Client.  So use a DHCP

Client to get an IP address on a system thats on the same network that

this script is running on. 

This first example WON'T see the packets:
<?php
$ip = "ENTER YOUR IP ADDRESS HERE"; //example: 192.168.0.100
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, $ip, 67);
while(1)
{
  if($src = @socket_recv($socket, $data, 9999, 0)) { echo "data!\n"; }
}
?>

This second example WILL see the packets:
<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, 0, 67);
while(1)
{
  if($src = @socket_recv($socket, $data, 9999, 0)) { echo "data!\n"; }
}
?>


This reference might give you a better idea of what I'm talking about:
http://en.wikipedia.org/wiki/Dhcp#DHCP_discovery

------------------------------------------------------------------------

[2007-03-02 20:24:54] matth at mystictrd dot com

The way it seems this should work (I easily could be completely off 
base) is:

socket_bind could be defined as:

bool socket_bind ( resource $socket, string $address [, int $port [, 
string $mac or $iface ]] )

------------------------------------------------------------------------

[2007-03-02 17:21:23] matth at mystictrd dot com

I believe in C/C++ you can specify hardware addresses to listen on -
specifically either a MAC address/an interface name (eth0 in linux).  

After doing some tests in C it seems that if you listen on an ip (i.e.
192.168.0.1) and you will not see that type of packet but if you listen
on 0.0.0.0 or INADDR_ANY you can see it.

------------------------------------------------------------------------

[2007-03-01 17:38:01] matth at mystictrd dot com

Ignore my previous workaround example, it did not work as expected.

------------------------------------------------------------------------

[2007-03-01 17:25:57] matth at mystictrd dot com

The reason why is if you take a normal DHCP server you can typically
listen on multiple interfaces.  If one wanted to know what interface is
receiving the data you would think to bind on the interfaces IP address.
 But since you cannot see that type of packet binding to an IP like that
you must bind to 0 or 0.0.0.0 which doesn't help with knowing what
interface recieved the data since the data does not contain information
about interface mac/ip destination from the client. I'm not positive if
this is a PHP issue or not but I believe you can do it in C/C++ and that
you should be able to do it with PHP.  A work around I'm experimenting
with  goes as:

<?php
$interface_ip = "10.66.66.1";
$interface_port = 67;
//listens for dhcp requests
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
//you must bind to 0.0.0.0 to actually see anything
socket_bind($socket, 0, 67);
while(1)
{
  if($src = @socket_recvfrom($socket, $data, 9999, 0, $interface_ip,
$interface_port))
  {
    echo "data!\n";
  }
}
?>

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/40674

-- 
Edit this bug report at http://bugs.php.net/?id=40674&edit=1

Reply via email to