send raw packets - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

send raw packets

t0rust0rus Posts: 1Member
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:


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

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?

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.
Sign In or Register to comment.