Couldn't I just add the packet[65536] into the structure ?
No. The inside of a structure is defined once and once only. Here's an example:
1 2 3 4 5
struct breakfast
{
int eggs;
int bacon;
}
It's set. You cannot just add things into it mid-program. If you want to change the structure, you have to rewrite it.
What do I need this for ?
It looks like a simple way of setting aside 65536 bytes for use as a IPV4_HDR object. Seems an awfully roundabout way of doing it when you could just make an actual IPV4_HDR like this:
class MemAlloc
{
private:
char* memory;
public:
MemAlloc(unsignedint size) { memory = newchar[size]; }
~memAlloc(void) { delete [] memory; }
char* getMemory(unsignedint amount)
{
// Find a free block of "memory" the size of amount
return thatBlock;
}
// A bunch of other functions for handling the "memory" array's blocks
};
int main(void)
{
MemAlloc myMemoryAllocator(1000000); // A 1,000,000 size char array is dynamically allocated
IPV4_HDR *v4hdr = (IPV4_HDR *) myMemoryAllocator.getMemory(sizeof(IPV4_HDR));
// Do things
That method was something I picked up in C class, not sure how real-life it is. This way your program can sort of handle it's own memory. Rather than always using new and delete you have your own little block to play with.