Issue
I am working on a kernel module, in which i want to transfer a structure via skb. I can do so by putting each of data element of struct in skb; however my question is: can I put complete structure in skb in one shot and send it across ?
Solution
You can simply get a pointer to the whole struct then memcpy the contents to your buffer.
/* skb_put returns a pointer to the beginning of the data area in the skb*/
unsigned char *skb_data = skb_put(skb, size_of_data);
unsigned char *your_data = (unsigned char *) your_struct;
memcpy(skb_data, your_data, size_of_data);
Of course, make sure the skb has enough data space, you can do that using the skb_tailroom
function.
Answered By - Fingolfin Answer Checked By - David Goodson (WPSolving Volunteer)