Abby wrote:
I'm working on sending and receiving data packet using UDP. I don't
know the length of the data packet I'm receiving but I would like to
print out all bytes in that packet to the screen. How can I do that?
Right now, I have to do something like this ...
printf("Data Received: \n");
for (i=0; i<=50; i++){
printf("Data %d: %d\n", i, resp->data[i]);
}
"50" is the no. that I thought the data bytes in the packet will not
exceed this range. Please let me know if there're other ways to print
out the exact number of data bytes in the packet. Thank you.
Note that networking is not topical on c.l.c.
That said, in general, when you have a buffer partially filled with data
that you want to access, you need to have one of the two following
bits of information:
- either you should know the size of the data you are accessing.
- or you should have a marker of the end of the data (like the nul
terminator for C strings).
If you don't have any of these, you can't do what you want.
<OT>
In the terms of your own problem, you can only have a marker of the end
of the data if you know what the content of the UDP packets is, and if
(if any) there is a data terminator.
However, you are most likely using some implementation of the Berkeley
sockets to receive your packets, and the recv function lets you know how
much data was read (with its return value).
</OT>
--
Bertrand Mollinier Toublet
"Reality exists" - Richard Heathfield, 1 July 2003