#32324 [Opn->Fbk]: socket_recvfrom stops reading at null char

From: Date: Tue, 15 Mar 2005 23:19:12 +0000
Subject: #32324 [Opn->Fbk]: socket_recvfrom stops reading at null char
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-75386@lists.php.net to get a copy of this message
ID: 32324 Updated by: sniper@php.net Reported By: admin at freeworldonline dot com -Status: Open +Status: Feedback Bug Type: Sockets related Operating System: Linux stripples.devel.redhat.com PHP Version: 4.3.10 New Comment: Please try using this CVS snapshot: http://snaps.php.net/php4-STABLE-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-STABLE-latest.zip I can not reproduce this. I get only "Message from 127.0.0.1:52345 (363/363 bytes)..." Previous Comments: ------------------------------------------------------------------------ [2005-03-15 20:19:07] admin at freeworldonline dot com Description: ------------ I am trying to recieve data via a UDP socket using the socket_recvfrom function. It works fine unless there is a null char anywhere in the packet. If there is the buffer returned only contains data up to that point, although the value returned by the function shows there is actually more data. Reproduce code: --------------- if (!$sock=socket_create(AF_INET,SOCK_DGRAM,SOL_UDP)) { echo "<b>Error:</b> Failed to create socket, ".socket_strerror(socket_last_error($sock))."<br>\n"; } elseif (!socket_bind($sock,"0.0.0.0",41330)) { echo "<b>Error:</b> Failed to bind socket, ".socket_strerror(socket_last_error($sock))."<br>\n"; socket_close($sock); } else { echo "<b>Ready, please send a message to port 41330 using UDP</b><br><br>\n"; $size=socket_recvfrom($sock,$buf,65535,0,$clientIP,$clientPort); if ($buf===FALSE) { echo "<b>Error:</b> Returned false, ".socket_strerror(socket_last_error($sock))."<br>\n"; } else { echo "Message from ".$clientIP.":".$clientPort." (".strlen($buf)."/".$size." bytes)...<br>\n"; } socket_close($sock); } Expected result: ---------------- All data to be placed into the buffer regardless of any null characters in the packet. Actual result: -------------- If you send a datagram to port 41330 while this is running with a null character mid way into the packet, any data from there onwards will not be placed into $buf. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32324&edit=1

« previous php.bugs (#75386) next »