-
My advance so far: I have used read() to read from a file in a given block size and put that data in a struct. What happens if my block size is bigger that the whole file I am reading from?
Will my struct be filled with the actual contents of the file and then random data will be added. or zeroes added?
The protocol I'm implementing splits a file in 60k blocks, and it identifies the last packet as one with less than 60k of data.
thnks
J
-
Well, it depends how exactly your "putting your data in a struct" but you probably will have random data (perhaps 0s, depending on the OS and/or malloc, and previous allocations...).
Generally you'll want to have a header for each packet (datagram) with the packet id and data length, and optionally but preferably a checksum to make sure your file is intact when all is said and done...
While it's true that the max for a datagram is technically 64K, that does imply fragmentation (at best) or the datagram being dropped (if the router doesn't want to frag...) or more chances of loosing a packet fragment in route...
You might want to check the code of a TFTP implementation to see all everything's done (and perhaps copy your whole implementation from a BSD licensed source if you feel like it!)
Ammo