php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49423 fwrite doesn't send "REGISTER" to udp port 5060
Submitted: 2009-08-31 13:22 UTC Modified: 2009-09-09 01:00 UTC
Votes:2
Avg. Score:3.5 ± 1.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: david dot schueler at wapkamera dot de Assigned:
Status: No Feedback Package: Streams related
PHP Version: 5.2.10 OS: Gentoo Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
44 + 47 = ?
Subscribe to this entry?

 
 [2009-08-31 13:22 UTC] david dot schueler at wapkamera dot de
Description:
------------
If i execute the script below, it will not send the text "REGISTER" over UDP. If the text is prepended with any other character or sent to another port it will be transmitted successful.

Reproduce code:
---------------
<?php
$opts = array('socket' => array("bindto" => "0:5050")); // set source port = 5050
$context = stream_context_create($opts);
$socket = stream_socket_client("udp://127.0.0.1:5060", $errno, $error, 30, STREAM_CLIENT_CONNECT, $context);

fwrite($socket,'REGISTER \r\n');
?>

Expected result:
----------------
The text "REGISTER" followed by a line break to be send over UDP to the given host and port.

Actual result:
--------------
Nothing happens. No packet gets generated, no error or warning is thrown. fwrite() retuns 0.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-31 15:46 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Works fine for me. fwrite() returns int(13). 
 [2009-08-31 15:50 UTC] jani@php.net
And I guess you wanted to send the \r\n as line feed/break instead of literal \r\n ? If so, you should put double quotes around the text..
 [2009-08-31 16:20 UTC] sjoerd@php.net
Thank you for your report.

I could not reproduce your problem. You say it only fails to send something if port 5060 is used. This leads me to think this issue is specific to your computer. Maybe another program is running on port 5060, or a firewall has blocked this port. How do you determine whether the packet is sent?
 [2009-08-31 16:26 UTC] david dot schueler at wapkamera dot de
Yes i wanted to send as line feed. But it doesn't matter because even sending "REGISTER \r\n" nor "REGISTER abc" is working on 5.2.10.

I made a little script for showing what is happening:

<?php
echo phpversion()."\n";

$opts = array('socket' => array("bindto" => "0:5050"));
$context = stream_context_create($opts);
$socket = stream_socket_client("udp://127.0.0.1:5060", $errno, $error, 30, STREAM_CLIENT_CONNECT, $context);

$s[] = "REGISTER abc";
$s[] = "REGISTER";
$s[] = " REGISTER";
$s[] = "REGISTER ";

foreach ($s as $out) {
        echo "Outputting: \"".$out."\"\n";
        $bytes = fwrite($socket,$out);
        echo "Bytes written to socket: ".$bytes."\n";
}       
?> 

And the output is:

Kienzle ~ # php fwrite.php 
5.2.10-pl0-gentoo
Outputting: "REGISTER abc"
Bytes written to socket: 0
Outputting: "REGISTER"
Bytes written to socket: 8
Outputting: " REGISTER"
Bytes written to socket: 9
Outputting: "REGISTER "
Bytes written to socket: 9

Kienzle ~ # uname -a
Linux Kienzle 2.6.27-gentoo-r8 #7 SMP Wed Apr 29 18:42:19 CEST 2009 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 6000+ AuthenticAMD GNU/Linux

On another system, running the same version of php:
km33 ~ # php test.php 
5.2.10-pl0-gentoo
Outputting: "REGISTER abc"
Bytes written to socket: 0
Outputting: "REGISTER"
Bytes written to socket: 8
Outputting: " REGISTER"
Bytes written to socket: 9
Outputting: "REGISTER "
Bytes written to socket: 9
km33 ~ # uname -a
Linux km33902 2.6.30-gentoo-r4 #2 SMP Tue Aug 4 17:44:21 CEST 2009 x86_64 AMD Phenom(tm) 9950 Quad-Core Processor AuthenticAMD GNU/Linux

And for example on a Debian System:
ns20 ~ # php test.php
5.2.0-8+etch15
Outputting: "REGISTER abc"
Bytes written to socket: 12
Outputting: "REGISTER"
Bytes written to socket: 0
Outputting: " REGISTER"
Bytes written to socket: 9
Outputting: "REGISTER "
Bytes written to socket: 0
evil@ns2014921:~$ uname -a
Linux ns2014921.ovh.net 2.6.24.2-xxxx-std-ipv4-32 #4 SMP Wed Feb 13 16:50:04 CET 2008 i686 GNU/Linux

Look, the problem occures at "REGISTER".

I use "tcpdump -i lo -s0 -A port 5060" to look for the packet being sent. And if fwrite() returns 0 then there arent any bytes on the interface. So the output seems to be true.
 [2009-08-31 16:54 UTC] david dot schueler at wapkamera dot de
Okay, here's a tcpdump output, which shows that the other REGISTER strings are beeing sent:

km33 ~ # tcpdump -i lo -s0 -A port 5060
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
18:42:22.598199 IP localhost.5050 > localhost.5060: SIP, length: 8
E..$|B@.@..................#REGISTER
18:42:22.598231 IP localhost.5050 > localhost.5060: SIP, length: 9
E..%|C@.@..................$ REGISTER
18:42:22.598242 IP localhost.5050 > localhost.5060: SIP, length: 9
E..%|D@.@..................$REGISTER
^C
3 packets captured
6 packets received by filter
0 packets dropped by kernel

As you can see i'm sending from port 5050 to port 5060 (which is the default SIP port). No other process is listening on port 5050. Only asterisk is listening on port 5060, which i want to communicate with.

km33 ~ # netstat -anp | grep 5050
km33 ~ # netstat -anp | grep 5060
udp   0   0 0.0.0.0:5060   0.0.0.0:*   11132/asterisk

And i'm not blocking any ports on my system, because i'm not using any firewall on my testsystem.
 [2009-08-31 17:37 UTC] david dot schueler at wapkamera dot de
Again with latest php5.2:

~ # php test.php 
5.2.11RC2-dev
Outputting: REGISTER abc
Bytes written to socket: 0
Outputting: REGISTER
Bytes written to socket: 8
Outputting:  REGISTER
Bytes written to socket: 9
Outputting: REGISTER 
Bytes written to socket: 9

~ # tcpdump -i lo -s0 -A port 5060
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
19:35:25.189697 IP localhost.5050 > localhost.5060: SIP, length: 8
E..$<.@.@..$...............#REGISTER
19:35:25.189911 IP localhost.5050 > localhost.5060: SIP, length: 9
E..%<.@.@.."...............$ REGISTER
19:35:25.189953 IP localhost.5050 > localhost.5060: SIP, length: 9
E..%<.@.@..!...............$REGISTER 
^C
3 packets captured
6 packets received by filter
0 packets dropped by kernel
 [2009-08-31 19:56 UTC] sjoerd@php.net
I can reproduce the behavior you describe, but only if there is no process listening on port 5060. If I start "nc -l -u -p 5060", the fwrites succeed. Do you have a program listening on port 5060? 
 [2009-09-01 08:55 UTC] david dot schueler at wapkamera dot de
Yes. Asterisk is listening on port 5060, which i want to communicate with, as i described before.

I got this problem when i was trying to send a SIP REGISTER packet to asterisk.

For beeing sure asterisk is working on 127.0.0.1 i placed a SIP REGISTER in a file and ran this command:

Kienzle ~ # nc -u 127.0.0.1 5060 < register 
SIP/2.0 404 Not found
From: Joe User <sip:joe@example.com>
To: "J. User" <sip:joe@example.com>;tag=as23fd48f7
Call-ID: 39485832@joespc.example.com
CSeq: 19 REGISTER
User-Agent: WAPKamera Notifier
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces
Content-Length: 0


So the asterisk is answering with 404 not foud, which is correct.
Even netstat is confirming this.
Kienzle ~ # netstat -anp | grep 5060
udp   0   0 0.0.0.0:5060   0.0.0.0:*   4481/asterisk


But, even if no process is listening on port 5060 nothing would change, as you can see:

Kienzle ~ # /etc/init.d/asterisk stop
 * Stopping Asterisk ...                     [ ok ]
Kienzle ~ # netstat -anp | grep 5060
Kienzle ~ # php fwrite.php 
5.2.10-pl0-gentoo
Outputting: REGISTER abc
Bytes written to socket: 0
Outputting: REGISTER
Bytes written to socket: 8
Outputting:  REGISTER
Bytes written to socket: 0
Outputting: REGISTER 
Bytes written to socket: 9
Kienzle ~ # nc -u 127.0.0.1 5060 < register 

Kienzle ~ # tcpdump -i lo -s0 -A port 5060
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
10:54:43.706902 IP localhost.5050 > localhost.5060: SIP, length: 8
E..$.y@.@..M...............#REGISTER
10:54:43.707031 IP localhost.5050 > localhost.5060: SIP, length: 9
E..%.z@.@..K...............$REGISTER 
^C
2 packets captured
4 packets received by filter
0 packets dropped by kernel
Kienzle ~ #
 [2009-09-01 12:39 UTC] david dot schueler at wapkamera dot de
Okay. I built 5.2.11 on an other systerm running debian.

Here are the results with no process listening on port 5060:
ns20 ~ # php test.php 
5.2.11RC2-dev
Outputting: "REGISTER abc"
Bytes written to socket: 12
Outputting: "REGISTER"
Bytes written to socket: 0
Outputting: " REGISTER"
Bytes written to socket: 9
Outputting: "REGISTER "
Bytes written to socket: 0

And, with listening nc on 5060:
ns20 ~ # nc -l -u -p 5060
REGISTER abcREGISTER REGISTERREGISTER 

ns20 ~ # php test.php
5.2.11RC2-dev
Outputting: "REGISTER abc"
Bytes written to socket: 12
Outputting: "REGISTER"
Bytes written to socket: 8
Outputting: " REGISTER"
Bytes written to socket: 9
Outputting: "REGISTER "
Bytes written to socket: 9

So on that debian system it is working. But i don't know why its running on that system and not on the Gentoo platform.
There's really no firewall blocking the traffic. Even if it would so, no packet should go through. But some are doing.

This is driving me crazy. :-/
 [2009-09-01 12:52 UTC] david dot schueler at wapkamera dot de
And on a non 64bit system running Gentoo:

athen ~ # uname -a
Linux athen 2.6.20-hardened-r5 #1 SMP Sun Jul 29 21:36:07 GMT 2007 i686 AMD Duron(tm) processor AuthenticAMD GNU/Linux

athen ~ # php fwrite.php 
5.2.3-pl3-gentoo
Outputting: REGISTER abc
Bytes written to socket: 12
Outputting: REGISTER
Bytes written to socket: 8
Outputting:  REGISTER
Bytes written to socket: 9
Outputting: REGISTER 
Bytes written to socket: 9

athen ~ # nc -l -u -p 5060
REGISTER abcREGISTER REGISTERREGISTER 

So this is running fine with a listening process.
So may this issue due to the 64bit?
 [2009-09-01 13:06 UTC] david dot schueler at wapkamera dot de
And here on a 2nd non-64bit system:

Hauser ~ # php fwrite.php 
5.2.6RC4-pl0-gentoo
Outputting: REGISTER abc
Bytes written to socket: 12
Outputting: REGISTER
Bytes written to socket: 8
Outputting:  REGISTER
Bytes written to socket: 9
Outputting: REGISTER 
Bytes written to socket: 9

Hauser ~ # nc -l -u -p 5060
REGISTER abcREGISTER REGISTERREGISTER 

So this really looks to me, that it is depending on 64bit.
Is it possible to you to reproduce this on 64bit?
 [2009-09-01 15:36 UTC] sjoerd@php.net
Also, please try on the problematic system with nc instead of asterisk as the listening process.
 [2009-09-01 15:56 UTC] david dot schueler at wapkamera dot de
My comment from 2009-09-01 08:55:49 was already on the 64bit system with netcat.
 [2009-09-01 16:00 UTC] david dot schueler at wapkamera dot de
Oh. Sorry. I'm wrong.

Here's the test with netcat on 64bit system:

Kienzle ~ # php /var/www/videoobservance/fwrite.php 
5.2.10-pl0-gentoo
Outputting: REGISTER abc
Bytes written to socket: 0
Outputting: REGISTER
Bytes written to socket: 8
Outputting:  REGISTER
Bytes written to socket: 9
Outputting: REGISTER 
Bytes written to socket: 9

Kienzle ~ # nc -l -u -p 5060
REGISTER REGISTERREGISTER
 [2009-09-09 01:00 UTC] 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".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC