ethhdr、ether_header、iphdr、tcphdr、udphdr 结构介绍

本文介绍了网络协议中的ethhdr、ether_header、iphdr、tcphdr、udphdr结构,包括每个字段的含义,如源和目标地址、协议类型、包长度、序列号等,帮助理解网络数据包的构成。

转自:http://blog.csdn.net/petershina/article/details/8573853

 

************************eth的结构**************************************

struct ethhdr {
unsigned char h_dest[ETH_ALEN];
unsigned char h_source[ETH_ALEN];
__be16 h_proto;
} __attribute__((packed));

struct ether_header
{
u_int8_t ether_dhost[ETH_ALEN];      // destination eth addr 
u_int8_t ether_shost[ETH_ALEN];      // source ether addr    
u_int16_t ether_type;                 // packet type ID field

[2025-08-30 10:11:51] [ 35.133999] CPU: 3 PID: 7641 Comm: conn-indicator Tainted: P 5.4.281 #0 [2025-08-30 10:11:51] [ 35.134000] Hardware name: MediaTek MT7987A SPIM-NAND RFB (DT) [2025-08-30 10:11:51] [ 35.134004] pstate: 80000005 (Nzcv daif -PAN -UAO) [2025-08-30 10:11:51] [ 35.134022] pc : _101+0x14/0x140 [safesearch_dns] [2025-08-30 10:11:51] [ 35.134028] lr : _17+0x57c/0xa60 [safesearch_dns] [2025-08-30 10:11:51][ 35.200947] sp : ffffffc014e43a20 [2025-08-30 10:11:51] [ 35.200951] x29: ffffffc014e43a20 x28: 0000000000000011 [2025-08-30 10:11:51][ 35.210943] x27: 000000000100007f x26: 000000000000001d [2025-08-30 10:11:51] [ 35.217622] x25: ffffff80161c0358 x24: 0000000000000008 [2025-08-30 10:11:51] [ 35.224313] x23: ffffffc014e43ab0 x22: ffffff801e0a2600 [2025-08-30 10:11:51] [ 35.230996] x21: 0000000000000000 x20: ffffff80138e0800 [2025-08-30 10:11:51] [[ 35.237676] x19: ffffff801e0a2600 x18: 0000000000000014 [2025-08-30 10:11:51][ 35.244364] x17: 000000003e8682d5 x16: 00000000e9d0bd4d [2025-08-30 10:11:51] [ 35.251059] x15: 0000000078bb11e4 x14: 00000000bc920407 [2025-08-30 10:11:51] [ 35.257744] x13: 0000000065d224f1 x12: 00000000e7f97447 [2025-08-30 10:11:51] 35.264429] x11: 00000000f33a3ba0 x10: 0000000074a2d65c [2025-08-30 10:11:51] [ 35.271126] x9 : 000000000bb80982 x8 : 6c7967656e657261 [2025-08-30 10:11:51] [ 35.271129] x7 : 0000000000000003 x6 : 0000000000000000 [2025-08-30 10:11:51] [ 35.271131] x5 : 000000000000ffff x4 : ffffff800f006bff [2025-08-30 10:11:51] [ 35.271133] x3 : ffffff800eff6c00 x2 : 0000000000000008 [2025-08-30 10:11:51] [ 35.271135] x1 : ffffff801e0a2600 x0 : ffffff801e0a2600 [2025-08-30 10:11:51] [ 35.271139] Call trace: [2025-08-30 10:11:51] [ 35.271159] _101+0x14/0x140 [safesearch_dns] [2025-08-30 10:11:51]  35.305791] nf_hook_slow+0x50/0x120 [2025-08-30 10:11:51] [ 35.310752] __ip_local_out+0x18c/0x1a0 [2025-08-30 10:11:51] [ 35.315964] ip_local_out+0x20/0x58 [2025-08-30 10:11:51]  [ 35.320828] ip_send_skb+0x1c/0x78 [2025-08-30 10:11:51] [ 35.325609] udp_send_skb.isra.59+0x130/0x348 [2025-08-30 10:11:51] [ 35.331337] udp_sendmsg+0x6ec/0x898 [2025-08-30 10:11:51] [ 35.336289] inet_sendmsg+0x40/0x68 [2025-08-30 10:11:51] [ 35.341156] __sys_sendto+0xd8/0x148 [2025-08-30 10:11:51] [ 35.346108] __arm64_sys_sendto+0x24/0x30 [2025-08-30 10:11:51][ 35.346228] S95done (8004): drop_caches: 3 [2025-08-30 10:11:51][ 35.351488] el0_svc_common.constprop.2+0x7c/0x110 [2025-08-30 10:11:51] [ 35.351491] el0_svc_handler+0x20/0x80 [2025-08-30 10:11:51] [35.351494] el0_svc+0x8/0x6c0 [2025-08-30 10:11:51] [ 35.351502] Code: 79416c05 79416002 8b050064 53087c46 (79401881) 其中反汇编如下: _101(): 2e38: f9406003 ldr x3, [x0, #192] 2e3c: 79416c05 ldrh w5, [x0, #182] 2e40: 79416002 ldrh w2, [x0, #176] 2e44: 8b050064 add x4, x3, x5 2e48: 53087c46 lsr w6, w2, #8 2e4c: 79401881 ldrh w1, [x4, #12] 2e50: 2a0220c2 orr w2, w6, w2, lsl #8 2e54: 13003c42 sxth w2, w2 2e58: 53087c26 lsr w6, w1, #8 2e5c: 2a0120c1 orr w1, w6, w1, lsl #8 2e60: 13003c21 sxth w1, w1 2e64: 6b02003f cmp w1, w2 2e68: 540005a0 b.eq 2f1c <_101+0xe4> // b.none 在2e4c处异常 原始代码为 struct ethhdr *ethh = NULL; struct iphdr *iph = NULL; struct ipv6hdr *ip6h = NULL; struct udphdr *udph = NULL; struct tcphdr *tcph = NULL; int is_valid_ethh = 0; // [pppoe fix] package from wan to lan do not hava valid // ether header in data buffer. Using information in skb instead. ethh = eth_hdr(skb); if (ntohs(ethh->h_proto) == pkg_buff_attr_protocol(skb)) { 这一句 is_valid_ethh = 1; } else { is_valid_ethh = 0; } 如果修改为 + ethh = eth_hdr(skb); + if (skb_mac_header_was_set(skb) && ethh && (ntohs(ethh->h_proto) == pkg_buff_attr_protocol(skb))) { + is_valid_ethh = 1; + } else { + is_valid_ethh = 0; 可以解决吗
最新发布
09-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值