Forum Moderators: coopster

Message Too Old, No Replies

Udp sockets

         

morfeas

8:00 am on Mar 30, 2009 (gmt 0)

10+ Year Member



Good afternoon
i have the code below to catch dns requst and
save it to a file ip.txt
the problem is that while a dns repuest is being
send (73 bytes eg) only a few are received or saved to
the ip.txt at about 20 to 30 each time
anyome knows what happens?
<?
while(TRUE) {
$socketD = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socketD, "192.168.1.1", 53);
socket_recvfrom($socketD, $buf, 65535, 0, $clientIP, $clientPort);
$File = "ip.txt";
$Handle = fopen($File, 'w');
$Data = $buf;
fwrite($Handle, $Data);
fclose($Handle);
socket_close($socketD);}

coopster

7:12 pm on Apr 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are not performing any type of validation whatsoever. Perhaps you should be checking for return values on your socket_* functions and upon false use the socket error handling functions to determine your issue.