PHP socket_recv packet of missing bytes

I am trying to get a package in PHP, but it looks like socket_recv to lose a few bytes.

I know that the package was sent normally:

0:13:58.951742 IP 192.168.0.101.1458 > 192.168.0.107.8000: Flags [P.], seq 1:7, ack 1, win 64240, length 6 0x0000: 4500 002e 631d 4000 8006 158c c0a8 0065 E...c.@........e 0x0010: c0a8 006b 05b2 1f40 6557 d628 4e87 cadd ...k...@eW. (N... 0x0020: 5018 faf0 e808 0000 0068 6f6c 6100 P........hola. 

and the data has the following meanings: 0000 0068 6f6c 6100

but whit:

 socket_recv($socket, $buffer, 100, 0); echo bin2hex($buffer); echo unpack("H*", $buffer); 

im getting both echoes: 00686f6c6100

it means:

 sended: 0000 0068 6f6c 6100 receive: 00 68 6f6c 6100 

what am I doing wrong?

thanks.

edit: I found a problem. Was on the code. thanks!

+4
source share
1 answer

Try:

echo sprintf ("% 02x", unpack ("H *", $ buffer));

You may need to split the bytes into two parts first. IE Im not sure if 0x0000 translates as 0x0 to 0 (twice) or from 0x0000 to 00.

0
source

All Articles