From:             [EMAIL PROTECTED]
Operating system: All
PHP version:      4.1.1
PHP Bug Type:     *Network Functions
Bug description:  detecting end of UDP packets


I am using PHP for UDP stuff (to block access to users based on a DNSBL).
With TCP connections, PHP detects the end of a packet.
This feature doesn't exist while dealing with UDP but it could exist.

ie:
If I do a TCP connection and I expect 1 packet (but doesn't know it's
size) I'll do this :
$fp=fsockopen ("www.stuff.mars", 80, $errno, $errstr, 30);
fputs ($fp, "GET / HTTP/1.0\r\nHost: www.stuff.mars\r\n\r\n");
echo fread ($fp,4096);
fclose ($fp);

Even if the packet isn't 4096 bytes long, it will be returned entirely
until fread gets to it's end.

With UDP, the end of the packet CAN be detected but IS NOT detected, if
you use fgets you get NOTHING and if you use fread you get only the number
of bytes you asked for. Worst is that if you set 4096 as the length for
fread, since it can't detect the end of a packet, it waits and stay stuck
on it until it received 4096 bytes worst of packets.

ie :
$fp=fsockopen ("udp://boo.stuff.mars", 13, $errno, $errstr, 3);
fputs ($fp, "\n");
echo fread ($fp,4096);
fclose ($fp);

Though I think you could do even better.

ie :
$fp=fsockopen ("udp://ns.stuff.mars", 53, $errno, $errstr, 3);
fputs ($fp, $dns_packet);
while ($rcvd=fread($fp,4096)) echo ord($rcvd);
fclose ($fp);

That's technically doable...

I know that there are new socket functions and I could probably use those
to do what I want to do.
But this report is just about if you want to support UDP sockets as one of
the standard features of PHP, then it needs to be well done.

Thank you guys, keep up the good work.
[ I give $10000 to the first one who come up with a PHP compiler for *nix
and Win. ]

-- 
Edit bug report at http://bugs.php.net/?id=15639&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=15639&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=15639&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=15639&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=15639&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=15639&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=15639&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=15639&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=15639&r=submittedtwice

Reply via email to