How to access data/payload from tcphdr (sk_buff) struct on debian 64 bits?

北慕城南 提交于 2019-12-05 12:11:34

(char *)((int)tcph + (int)(tcph->doff * 4)); is wrong, it should be

(char *)((unsigned char *)tcph + (tcph->doff * 4));

Note that printk(KERN_DEBUG "data len : %d\ndata : \n", (int) strlen(data)); is not at all a safe thing to do. You don't know if the data contains text, and if it does, it might not contain a 0 terminated string which strlen(data) would need to work as you expect.

You probably need to care about endianess as well, when comparing the ports and possibly other fields.

Change this line :

data = (char *)((int)tcph + (int)(tcph->doff * 4));

To:

data = (char *)((void *)tcph + (int)(tcph->doff * 4));

Use

printk(KERN_INFO ...);

rather than

printk(KERN_DEBUG ...);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!