Originally Posted by
fudgecode
no problem, you just trying to help and i lack of explaining what i am looking for.
now, lets assume i have those a message from a remote system and i know the protocol, so i know the first 4 bytes is the ip, then 2 bytes port, then 20 bytes message. all this data is now in my recieved buffer. for me is the problem now to process it, this means:
- taking the first 4 bytes of the ip changing them to human readable and print
- taking the next 2 bytes of the port, changing to human readable and print
- taking the message out of the buffer, changing to human readable and print.
well i guess this is basic c things i am looking for, i would say in other languages like perl or python for this u use functions like pack or unpack.
thank you for helping
Assuming the IP is in machine order and the message is ascii characters...
Code:
// the recv buffer (big as you need)
unsigned char Buff[100];
// code to actually receive the message goes here
// display message
printf("Message from : %d,%d,%d,%d:%d \n",
Buff[0],Buff[1],Buff[2],Buff[3], *((uint16_t*)&Buff[4]) );
printf("Message reads: %s \n \n", (char*)&Buff[6] );
Now please bear in mind this isn't real world code. It's not likely you'll drop this into a procedure and have it work properly. It's only to give you some idea how to extract data from raw buffers.
As I pointed out earler the "socket" library has built in functions for transferring and decoding reply addresses, so it's very unlikely you will see them in the actual data buffer. What you would most likely get is just the text in which case you can simply print the buffer. The return address etc. would come from the recvfrom() call that fetched the buffer.