PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
send raw packets Posted by t0rus on 14 Jul 2008 at 2:10 PM
I'm trying to send 27 bytes of data to a device connected at the specified IP address and port but it's not sending the right data.
here's the code:

<?php

function spk($packet){
$result='';
foreach(str_split($packet,2) as $byte){
$result.=chr(hexdec($byte));
}
return $result;
}
//hex code of the bytes i want to send:
$packet= spk("32CD54AB13C664000000641B0002000400000001000000FF000000");
$host="192.168.0.53";
$port=900;
$sock = socket_create(AF_INET, SOCK_RAW, SOL_UDP);
echo socket_sendto($sock, $packet, strlen($packet), 0, $host, $port)." bytes";
socket_close($sock);
?>


i tried sniffing the data, and it looks like i sent:
00 00 64 1B 00 02 00 04 00 00 00 01 00 00 00 FF
00 00 00

but i need to send:
32 CD 54 AB 13 C6 64 00 00 00 64 1B 00 02 00 04
00 00 00 01 00 00 00 FF 00 00 00

so it looks like it's not sending the first word, so i tried prefixing it with 0's and F's, and the sniffer then shows the right data, but the device is still not responding (it should click when it gets those 27 bytes)

i also tried changing icmp, and tcp protocols, but no success.

any ideas?

edit:
It's also sending to the wrong port #, so i think the SOCKET_RAW allows me to specify the header and all that, so i tried adding 0384 to the header to send it to the right port, and it does show up that it's going to port 900 in the sniffer, but still no reaction.

When i try to use SOL_TCP, i get this error:

unable to write to socket [0]: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.