Ok I am putting the whole struct here, its specification of a protocol named openflow that is implemented in some of industrial switches , so the struct is like:
struct ofp_packet_in {
struct ofp_header header;
uint32_t buffer_id; /* ID assigned by datapath. */
uint16_t total_len; /* Full length of frame. */
uint16_t in_port; /* Port on which frame was received. */
uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
uint8_t pad;
uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,
so the IP header is 32-bit aligned. The
amount of data is inferred from the length
field in the header. Because of padding,
offsetof(struct ofp_packet_in, data) ==
sizeof(struct ofp_packet_in) - 2. */
};
OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
now I have to fill up some data in the last field that is –uint8_t data[0] which can be varied and info is gathered from the length field inside the header. I have to construct a packet in, and for that data has to be put in. Please take a look.
You’ll need to use a dynamic allocation and copy the contents.
Something like: