免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1601 | 回复: 4
打印 上一主题 下一主题

请教一个关于skb的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-18 21:36 |只看该作者 |倒序浏览
我从网卡的环行缓冲队列里取了一个skb,我如何判断他是那种类型的数据包呢?比如说tcp udp

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
2 [报告]
发表于 2009-04-19 08:00 |只看该作者
仔细看一下skb结构体。关键的是skb->data成员。他指向数据报文的头部。同时,data还是随着报文在不同的层指向不同的内容。如果报文还在链路层,那么data指向MAC,如果是网络层,指向iphdr. 能够得到报文的头部,整个报文的内容你都可以通过偏移取出来了

论坛徽章:
0
3 [报告]
发表于 2009-04-19 18:23 |只看该作者
哦·谢谢啊~!

论坛徽章:
0
4 [报告]
发表于 2009-04-24 23:26 |只看该作者
我觉得还有个简单点的方法.
skb中有个成员叫h,就是表示header的.
下面这段来自LDD3 CHAPTER 17  PAGE 529

SKB data structure:
union { /* ... */ } h;
union { /* ... */ } nh;
union { /*... */} mac;
Pointers to the various levels of headers contained within the packet. Each field
of the union is a pointer to a different type of data structure. h hosts pointers to
transport layer headers (for example, struct tcphdr *th); nh includes network
layer headers (such as struct iphdr *iph); and mac collects pointers to link-layer
headers (such as struct ethdr *ethernet).
If your driver needs to look at the source and destination addresses of a TCP
packet, it can find them in skb->h.th. See the header file for the full set of header
types that can be accessed in this way.

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
5 [报告]
发表于 2009-04-24 23:43 |只看该作者
原帖由 accessory 于 2009-4-24 23:26 发表
我觉得还有个简单点的方法.
skb中有个成员叫h,就是表示header的.
下面这段来自LDD3 CHAPTER 17  PAGE 529

SKB data structure:
union { /* ... */ } h;
union { /* ... */ } nh;
union { /*... */} ma ...


这个是有条件限制的,LZ需要了解一下这几个分别在什么时候才可以使用
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP