
大约一年前,对于内核2.6.26,我这样做是这样的:
// Do we need extra space?if(len - skb_tailroom(skb) > 0){ // Expand skb tail until we have enough room for the extra data if (pskb_expand_head(skb, 0, extra_data_len - skb_tailroom(skb), GFP_ATOMIC)) { // allocation failed. Do whatever you need to do } // Allocation succeeded // Reserve space in skb and return the starting point your_favourite_structure* ptr = (your_favourite_structure*) skb_push(skb, sizeof(*ptr)); // Now either set each field of your structure or memcpy into it. // Remember you can use a char*}不要忘记:
重新计算UDP校验和,因为您更改了传输数据中的数据。
更改
tot_len
ip标头中的字段(总长度),因为您已向数据包中添加了数据。重新计算IP标头校验和,因为您更改了该
tot_len
字段。
附加说明
:这只是简单的事情。我在您的代码中看到您正在分配
tmp一个200字节的数组,并使用该数组存储消息的数据。如果发送更大的数据包,将很难调试,因为由于内存溢出而导致的内核崩溃太痛苦了。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)