目录
1、ping的原理及实现
关于ping的原理,我在这篇博客里说明ping的原理及实现,可以参考
2、ipv6
2.1、ipv6报头
从上图我们可以看出ipv6
-
数据链路层(L2)的type字段标识为0x86dd,表示承载的上层协议为ipv6(ipv4的表示符为0x0800)
-
ipv6的固定报头结构(40字节)
- Version字段表示版本号,ipv6中该字段必须为6
- Traffic Class字段含义类似IPv4中的TOS(Type Of Service)
- Flow Label字段用于标识同一业务流的包
- Payload Length字段用于标识有效的负载长度,只计算报头后面的扩展和数据部分的长度,不包括ipv6(40字节)的长度。该字段最多表示长度为64KB有效负载长度
- Next Header字段用于标识当前报头(或者扩展报头)的下一个头部类型,每种扩展报头都有其对应的值。
- Hop Limit字段与ipv4中的TTL字段,指定了报文可以有效转发的次数
2.2、Linux中ipv6头部结构
struct ip6_hdr
{
union
{
struct ip6_hdrctl
{
uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC, 20 bits flow-ID */
uint16_t ip6_un1_plen; /* payload length */
uint8_t ip6_un1_nxt; /* next header */
uint8_t ip6_un1_hlim; /* hop limit */
} ip6_un1;
uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits tclass */
} ip6_ctlun;
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */
};
#define ip6_vfc ip6_ctlun.ip6_un2_vfc//版本号以及通信类型
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow//流标签
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen//有效负载长度
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt