Bug #40674 [Com]: socket_bind on interface wont see broadcasts to 255.255.255.255

From: Date: Tue, 01 Mar 2022 09:31:54 +0000
Subject: Bug #40674 [Com]: socket_bind on interface wont see broadcasts to 255.255.255.255
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240088@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=40674&edit=1 ID: 40674 Comment by: worker at cksn dot tk Reported by: matth at mystictrd dot com Summary: socket_bind on interface wont see broadcasts to 255.255.255.255 Status: No Feedback Type: Bug Package: Sockets related Operating System: Debian 3.1 PHP Version: 5.2.1 Block user comment: N Private report: N New Comment: i'm running into the same problem to receive DHCP packets via PHP8.1 ... all the here mentioned codes arnt working now, maybe someone can confirm the behavior or give me a new hint to solve this problem. regards, volker. Previous Comments: ------------------------------------------------------------------------ [2010-05-06 12:21:40] agv at rsh dot hu Hy! I solved the problem: <?php $bc_socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); // for broadcast packets $if_socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); // for answer packets socket_bind($bc_socket, "255.255.255.255", 67); // listen to discover pcks. socket_bind($if_socket, "10.0.0.1", 67); // target interface address socket_set_option($bc_socket, SOL_SOCKET, SO_BROADCAST, 1); socket_set_option($bc_socket, SOL_SOCKET, SO_REUSEADDR, 1); socket_set_option($bc_socket, SOL_SOCKET, SO_DEBUG, 0); socket_set_option($if_socket, SOL_SOCKET, SO_BROADCAST, 1); socket_set_option($if_socket, SOL_SOCKET, SO_REUSEADDR, 1); socket_set_option($if_socket, SOL_SOCKET, SO_DEBUG, 0); while(1) { if($src = @socket_recv($bc_socket, $data, 9999, 0)) { echo "data!\n"; $senddata = "...."; socket_sendto($if_socket, $senddata, strlen($senddata),0, "255.255.255.255", 68); } } ?> ------------------------------------------------------------------------ [2007-09-06 01:00:01] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2007-08-29 11:55:31] jani@php.net "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? ------------------------------------------------------------------------ [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 ]] ) ------------------------------------------------------------------------ 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 https://bugs.php.net/bug.php?id=40674 -- Edit this bug report at https://bugs.php.net/bug.php?id=40674&edit=1

« previous php.bugs (#240088) next »