• IPV6 ND协议--源码解析【根源分析】


    ND协议介绍

    ND介绍请阅读上一篇文章:IPv6知识 - ND协议【一文通透】
    11.NDP协议分析与实践_router solicitation报文中不携带source link-layer address-CSDN博客

    ND协议定义了5种ICMPv6报文类型,如下表所示:

    NS/NA报文主要用于地址解析
    RS/RA报文主要用于无状态地址自动配置
    Redirect报文用于路由器重定向。

    源码存在于头文件

    #include
    #include
    #include
    
    • 1
    • 2
    • 3

    NS包解析

    ICMPv6邻居请求(Neighbor Solicitation)消息

    其中各字段的含义如下:
    1)Target Address:待解析的IPv6地址,16types。Target Address不能是组播地址,可以是链路本地地址、站点本地地址和全球单播地址。
    2)Options:地址解析中只使用了链路层地址选项(Link-Layer Address Option),是发送NS报文节点的链路层地址。
    Source/Target Link-Layer Address(链路层地址选项)的格式如下图所示:

    其中各字段含义如下:
    1)Type:选项类型,在链路层地址选项中包括如下两种:

    • Type=1,表明链路层地址为Source Link-Layer Address(源链路层地址),在NS,RS,Redirect报文中使用。
    • Type=2,表明链路层地址为Target Link-Layer Address(目标链路层地址),在NA,Redirect报文中使用。

    2)Length:选项长度,以8bytes为单位。
    3)Link-Layer Address:链路层地址。长度可变,对于以太网为6bytes。

    邻居请求报文NS(Neighbor Solicitation)报文:Type字段值为135,Code字段值为0,在地址解析中的作用类似于IPv4中的ARP请求报文。用来获取邻居的链路层地址,验证邻居是否可达,进行重复地址检测等。

    image.png
    image.png

    NA包解析

    ICMPv6邻居通告(Neighbor Adivertisment)消息


    其中各字段的含义如下:
    1)Target Address:待解析的IPv6地址,16types。Target Address不能是组播地址,可以是链路本地地址、站点本地地址和全球单播地址。被公告的 IP 地址,不能是多播地址
    2)R (Router flag) : 发送者是否为 Router; 当 Router 不再扮演 Router 角色时,将该值设置为 0,Hosts 会将该 Router 从默认路由表中删除
    3)S (Solicited flag) : 是否为 NS 响应消息
    4)O (Override flag) : 通知其他节点 link 地址变化
    5)Options: 地址解析中只使用了链路层地址选项(Link-Layer Address Option),是发送NS报文节点的链路层地址。链路层地址选项的格式如下图所示:
    其中各字段含义如下:
    1)Type:选项类型,在链路层地址选项中包括如下两种:

    • Type=1,表明链路层地址为Source Link-Layer Address(源链路层地址),在NS,RS,Redirect报文中使用。
    • Type=2,表明链路层地址为Target Link-Layer Address(目标链路层地址),在NA,Redirect报文中使用。

    2)Length:选项长度,以8bytes为单位。
    3)Link-Layer Address:链路层地址。长度可变,对于以太网为6bytes。

    邻居通告报文NA(Neighbor Adivertisment)报文:Type字段值为136,Code字段值为0,在地址解析中的作用类似于IPv4中的ARP应答报文。用来对NS消息进行响应。另外,当节点在链路层变化的时候主动发出NA消息,告知邻居本节点的变化。

    image.png
    image.png

    ========================

    RS包解析

    ICMPv6路由器请求(Router Solicitation)消息

    其中字段含义如下:
    Options(选项)字段:只能是源链路层地址选项,表明该报文发送者的链路层地址,不过如果IPv6报头的源地址为未指定地址,则不能包括该选项。
    ICMPv6路由器请求(Router Solicitation)消息Type字段值为133,节点启动后,通过RS消息向路由器发出请求,请求前缀和其他配置信息,用于节点的自动配置。

    RS包(路由请求):结构体nd_router_solicit解析
    image.png
    image.png
    image.png

    RA包解析

    ICMPv6路由器通告(Router Advertisement)消息

    • 路由器周期性地发布 RA 消息,包含 on-link/off-link 的 prefix、hop-limit 和 link-MTU 等



    其中字段含义如下:

    • 类型 : 消息类型, RA 固定为 134
    • 代码 : 发送者固定为 0,接收者忽略
    • 校验和 : 用于校验 ICMPv6 和部分 IPv6 首部完整性
    • 跳数限制 : 主机跳数限制,0 表示路由器没有指定,需主机设置
    • M (Managed Address Configuration) :
      • M=1 : 表示目标机使用 DHCPv6 获取 IPv6 地址
      • M=0 : 表示目标机使用无状态自动配置SLAAC,根据RA 消息获得的 IPv6 前缀构造 IPv6 地址
    • O (Other Configuration) :
      • O=1 : 目标机使用 DHCPv6 获取其他配置信息(不包括 IPv6 地址),比如 DNS 等
      • O=0 : 目标机不使用 DHCPv6 获取其他配置信息(不包括 IPv6 地址),比如手工配置 DNS 等
    • 默认路由器有效期: 表示该路由器能当默认路由器的时间,0 表示不是默认路由,单位为秒
    • 节点可达有效期 : 表示某个节点被确认可达之后的有效时间,0 表示路由器没有指定,需主机设置,单位毫秒
    • 重传间隔时间 : 重新发送 NS 消息间隔时间,单位毫秒



    Options选项字段中个选项的含义如下:
    1)源链路层地址选项:路由器发送RA报文的接口的链路层地址。
    2)MTU选项:包含了在链路上运行的链路层协议所能支持的MTU最大值,如果 MTU 可变, router 会发送该选项。
    3)前缀信息选项(Prefix Information Option):用于地址自动配置的前缀信息,可包含多个。前缀信息选项在RFC2461中定义,用于表示地址前缀和有关地址自动配置的信息,值用于RA报文中;在其他的消息中,此选项应该被忽略。自动配置地址时,指明前缀是否为 on-link 和是否可用来自动配置 IPv6 地址
    其格式如下图所示:


    4)路由信息选项(Route Information Option):用于主机生产默认路由。通知主机添加指定的路由到路由表。
    路由信息选项在RFC4191中定义,取代了原前缀信息选项的功能。接收RA报文的主机将选项中的信息添加到自己的路由表中,以便在发送报文时做出更好地转发决定,其个数如下图所示:

    其中各字段含义如下所示:

    5)通告间隔 : Mobile IPv6 extension,通知主机每隔多久 home agent 会定期发送 NA 消息
    6)Home Agent Info : Mobile IPv6 extension,每个 Home agent 用来公告自己的优先顺序及有效期

    RA包:nd_router_advert 解析

    image.png
    image.png
    image.png

    选项Options 解析

    Options选项字段中个选项的含义如下:
    1)源链路层地址选项:路由器发送RA报文的接口的链路层地址。
    2)MTU选项:包含了在链路上运行的链路层协议所能支持的MTU最大值。
    image.png
    image.png

    前缀信息选项 解析

    (3)前缀信息选项(Prefix Information Option):用于地址自动配置的前缀信息,可包含多个。前缀信息选项在RFC2461中定义,用于表示地址前缀和有关地址自动配置的信息,值用于RA报文中;在其他的消息中,此选项应该被忽略。自动配置地址时,指明前缀是否为 on-link 和是否可用来自动配置 IPv6 地址
    其格式如下图所示:


    image.png
    image.png
    image.png

    ========================

    ND重定向解析

    当路由器发现更好的报文转发路径(next-hop)时候,会用重定向报文告诉主机

    类型 : 消息类型, 固定为 137
    代码 : 发送者固定为 0,接收者忽略
    **校验和 **: 用于校验 ICMPv6 和部分 IPv6 首部完整性
    **目标地址 **: 重定向后的 Router 地址
    **目的地址 **: 原始封包的目的位址
    选项 :

    • 目标链路层地址选项 : 目标的链路层地址,如果知道的话
    • 重定向头部选项 : 引起 Router 发送 Redirect message 的原始封包內容或部分內容(重定向消息大小不能超过1280 bytes)
      image.pngimage.png

    实战演练—NDP 编程

    地址解析

    • 地址解析在三层完成,不同的二层介质可以采用相同的地址解析协议
    • 可以使用三层的安全机制(例如 IPsec)避免地址解析攻击
    • 使用组播方式发送请求报文,减少二层网络的性能压力
    • NS/NA 消息的目的 IPv6 地址是个特定的组播地址,跳数限制为 255,保证不会跑远(不能转发或者路由)

    ndp.h

    #ifndef __ndp_h_
    #define __ndp_h_
    
    /* 参考 linux /usr/include/netinet/icmp6.h */
    #define ND_ROUTER_SOLICIT           133
    #define ND_ROUTER_ADVERT            134
    #define ND_NEIGHBOR_SOLICIT         135
    #define ND_NEIGHBOR_ADVERT          136
    #define ND_REDIRECT                 137
    
    #define ND_OPT_SOURCE_LINKADDR      1
    #define ND_OPT_TARGET_LINKADDR      2
    #define ND_OPT_PREFIX_INFORMATION   3
    #define ND_OPT_REDIRECTED_HEADER    4
    #define ND_OPT_MTU                  5
    #define ND_OPT_RTR_ADV_INTERVAL     7
    #define ND_OPT_HOME_AGENT_INFO      8
    
    struct icmp6_hdr {
    	uint8_t  icmp6_type;   /* type field */
    	uint8_t  icmp6_code;   /* code field */
    	uint16_t icmp6_cksum;  /* checksum field */
    	union {   
    		uint32_t icmp6_un_data32[1]; /* type-specific field */
    		uint16_t icmp6_un_data16[2]; /* type-specific field */
    		uint8_t  icmp6_un_data8[4];  /* type-specific field */
    	} icmp6_dataun;
    };  
    
    struct nd_router_solicit      /* router solicitation */
    {
    	struct icmp6_hdr nd_rs_hdr;
    	/* could be followed by options */
    };
    
    #define nd_rs_type               nd_rs_hdr.icmp6_type
    #define nd_rs_code               nd_rs_hdr.icmp6_code
    #define nd_rs_cksum              nd_rs_hdr.icmp6_cksum
    #define nd_rs_reserved           nd_rs_hdr.icmp6_data32[0]
    
    struct nd_router_advert       /* router advertisement */
    {
    	struct   icmp6_hdr nd_ra_hdr;
    	uint32_t nd_ra_reachable;   /* reachable time */
    	uint32_t nd_ra_retransmit;  /* retransmit timer */
    	/* could be followed by options */
    };
    
    #define nd_ra_type               nd_ra_hdr.icmp6_type
    #define nd_ra_code               nd_ra_hdr.icmp6_code
    #define nd_ra_cksum              nd_ra_hdr.icmp6_cksum
    #define nd_ra_curhoplimit        nd_ra_hdr.icmp6_data8[0]
    #define nd_ra_flags_reserved     nd_ra_hdr.icmp6_data8[1]
    #define ND_RA_FLAG_MANAGED       0x80
    #define ND_RA_FLAG_OTHER         0x40
    #define ND_RA_FLAG_HOME_AGENT    0x20
    #define nd_ra_router_lifetime    nd_ra_hdr.icmp6_data16[1]
    
    struct nd_neighbor_solicit    /* neighbor solicitation */
    {
    	struct icmp6_hdr nd_ns_hdr;
    	uint8_t nd_ns_target[16]; /* target address */
    	uint8_t nd_ns_options[0];
    };
    
    #define nd_ns_type               nd_ns_hdr.icmp6_type
    #define nd_ns_code               nd_ns_hdr.icmp6_code
    #define nd_ns_cksum              nd_ns_hdr.icmp6_cksum
    #define nd_ns_reserved           nd_ns_hdr.icmp6_data32[0]
    
    struct nd_neighbor_advert     /* neighbor advertisement */
    {
    	struct icmp6_hdr  nd_na_hdr;
    	uint8_t nd_na_target[16]; /* target address */
    	uint8_t nd_na_options[0]; /* could be followed by options */
    };
    
    #define nd_na_type               nd_na_hdr.icmp6_type
    #define nd_na_code               nd_na_hdr.icmp6_code
    #define nd_na_cksum              nd_na_hdr.icmp6_cksum
    #define nd_na_flags_reserved     nd_na_hdr.icmp6_data32[0]
    #define ND_NA_FLAG_ROUTER        0x00000080
    #define ND_NA_FLAG_SOLICITED     0x00000040
    #define ND_NA_FLAG_OVERRIDE      0x00000020
    
    struct nd_redirect            /* redirect */
    {
    	struct icmp6_hdr  nd_rd_hdr;
    	uint8_t nd_rd_target[16]; /* target address */
    	uint8_t nd_rd_dst[16];    /* destination address */
    	/* could be followed by options */
    };
    
    #define nd_rd_type               nd_rd_hdr.icmp6_type
    #define nd_rd_code               nd_rd_hdr.icmp6_code
    #define nd_rd_cksum              nd_rd_hdr.icmp6_cksum
    #define nd_rd_reserved           nd_rd_hdr.icmp6_data32[0]
    
    struct nd_opt_hdr              /* Neighbor discovery option header */
    {
    	uint8_t  nd_opt_type;
    	uint8_t  nd_opt_len;       /* in units of 8 octets */
    	uint8_t  nd_opt_data[0];   /* followed by option specific data */
    };
    
    
    struct nd_neighbor_solicit* nd_alloc_ns(const char *taddr, 
    		const struct nd_opt_hdr *opt, size_t size);
    
    void nd_free_ns(struct nd_neighbor_solicit **ns);
    
    void nd_print_na(const struct nd_neighbor_advert *na, 
    		const struct nd_opt_hdr *tar_opt);
    
    
    struct nd_opt_hdr *nd_alloc_opt_src(const char *smac, int *size);
    
    void nd_free_opt(struct nd_opt_hdr **opt);
    
    
    int nd_socket(uint8_t hop_limit);
    
    ssize_t nd_send(int sockfd, const void *data, size_t size, 
    		const char *daddr, int flags);
    
    ssize_t nd_recv(int sockfd, void *buf, size_t size, 
    		const char *daddr, int flags); 
    
    void nd_close(int sockfd);
    
    #endif /* __ndp_h_ */
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132

    ndp.c

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include   /* for ether_aton */
    
    #include "ndp.h"
    #include "common.h"
    
    struct nd_neighbor_solicit* nd_alloc_ns(const char *taddr, 
    		const struct nd_opt_hdr *opt, size_t size)
    {
    	struct sockaddr_in6 addr;
    	struct nd_neighbor_solicit *ns;
    
    	ns = (struct nd_neighbor_solicit *) calloc(1, sizeof(struct nd_neighbor_solicit) + size);
    	ns->nd_ns_type = ND_NEIGHBOR_SOLICIT;
    	ns->nd_ns_code = 0;
    	
    	if (inet_pton(AF_INET6, taddr, &addr.sin6_addr) == 0) 
    		handle_error_en(EINVAL, "taddr");
    	memcpy(ns->nd_ns_target, &addr.sin6_addr, sizeof(addr.sin6_addr));
    
    	if (NULL != opt && size > 0) 
    		memcpy(ns->nd_ns_options, opt, size);
    	return ns;
    }
    
    void nd_free_ns(struct nd_neighbor_solicit **ns)
    {
    	if (NULL != ns && NULL != *ns) {
    		free(*ns);
    		*ns = NULL;
    	}
    }
    
    void nd_print_na(const struct nd_neighbor_advert *na, 
    		const struct nd_opt_hdr *tar_opt) 
    {
    	char buffer[INET6_ADDRSTRLEN];
    
    	printf("%02x\n", na->nd_na_type);
    	printf("%02x\n", na->nd_na_code);
    	printf("%04x\n", htons(na->nd_na_cksum));
    	
    	if (inet_ntop(AF_INET6, na->nd_na_target, buffer, INET6_ADDRSTRLEN) == NULL)
    		handle_error("inet_ntop");
    	printf("%s\n", buffer);
    	printf("%s\n", ether_ntoa((struct ether_addr *) tar_opt->nd_opt_data));
    }
    
    
    struct nd_opt_hdr *nd_alloc_opt_src(const char *smac, int *size)
    {
    	struct ether_addr *addr;
    	struct nd_opt_hdr *opt;
    	int tot_len = sizeof(struct nd_opt_hdr) + sizeof(struct ether_addr);
    
    	opt = (struct nd_opt_hdr *) calloc(1, tot_len);
    	opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
    	opt->nd_opt_len  = 1;
    
    	addr = ether_aton(smac);
    	memcpy(opt->nd_opt_data, addr->ether_addr_octet, sizeof(addr->ether_addr_octet));
    
    	*size = tot_len;
    	return opt;
    }
    
    void nd_free_opt(struct nd_opt_hdr **opt)
    {
    	if (NULL != opt && NULL != *opt) {
    		free(*opt);
    		*opt = NULL;
    	}
    }
    
    
    int nd_socket(uint8_t hop_limit) 
    {
    	int sockfd;
    	int hops = hop_limit;
    
    	if ((sockfd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) == -1) 
    		handle_error("socket");
    
    	if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops, sizeof(hops)) == -1)
    		handle_error("setsockopt : IPV6_HOPLIMIT");
    	return sockfd;
    }
    
    ssize_t nd_send(int sockfd, const void *data, size_t size, 
    		const char *daddr, int flags) 
    {
    	ssize_t count;
    	struct sockaddr_in6 addr;
    
    	memset(&addr, 0, sizeof(addr));
    	addr.sin6_family = AF_INET6;
    	inet_pton(addr.sin6_family, daddr, &addr.sin6_addr);
    
    	if ((count = sendto(sockfd, data, size, flags, (struct sockaddr *)&addr, sizeof(addr))) == -1)
    		handle_error("sendto");
    	return count;
    }
    
    ssize_t nd_recv(int sockfd, void *buf, size_t size, 
    		const char *daddr, int flags) 
    {
    	ssize_t count;
    	struct sockaddr_in6 addr;
    	socklen_t socklen = sizeof(addr);
    
    	memset(&addr, 0, sizeof(addr));
    	addr.sin6_family = AF_INET6;
    	inet_pton(addr.sin6_family, daddr, &addr.sin6_addr);
    
    	if ((count = recvfrom(sockfd, buf, size, flags, (struct sockaddr *)&addr, &socklen)) == -1)
    		handle_error("recvfrom");
    	return count;
    }
    
    void nd_close(int sockfd) 
    {
    	if (close(sockfd) == -1)
    		handle_error("close");
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130

    main.c

    #include 
    #include 
    #include 
    #include 
    #include 
    
    #include "ndp.h"
    #include "ipv6.h"
    
    #define BUFFER_SIZE 1500
    
    static void ndp_addr_resolution(const char *smac, const char *saddr, 
    		const char *daddr, const char *taddr)
    {
    	int sockfd, opt_len, tot_len;
    	struct nd_opt_hdr *opt;
    	struct nd_neighbor_advert *na;
    	struct nd_neighbor_solicit *ns;
    	char buffer[BUFFER_SIZE];
    
    	sockfd = nd_socket(255);   // 跳数限制为 255,保证不会跑远(不能转发或者路由)
    
    	// 构建消息
    	opt = nd_alloc_opt_src(smac, &opt_len);               // 设置自己的链接层地址
    	ns = nd_alloc_ns(taddr, opt, opt_len); 
    	tot_len = sizeof(struct nd_neighbor_solicit) + opt_len;
    	ns->nd_ns_cksum = ipv6_cksum(saddr, daddr, IPPROTO_ICMPV6, ns, tot_len);
    
    	// 发送消息
    	nd_send(sockfd, ns, tot_len, daddr, 0);
    	nd_free_ns(&ns);
    	nd_free_opt(&opt);
    
    	// 接收消息
    	memset(buffer, 0, sizeof(buffer));
    	nd_recv(sockfd, buffer, sizeof(buffer), taddr, 0);
    
    	// 解析消息
    	na = (struct nd_neighbor_advert *) buffer;
    	opt = (struct nd_opt_hdr *) (buffer + sizeof(struct nd_neighbor_advert));
    	nd_print_na(na, opt);
    
    	nd_close(sockfd);
    }
    
    int main(int argc, char *argv[])
    {
    	const char *smac  = "00:0c:0c:0c:0c:0c";        // 发送者链路层地址
    	const char *saddr = "fe80::20c:cff:fe0c:c0c";   // 本机 IPv6 地址
    	const char *daddr = "ff02::1:ff0d:d0d";         // 发给组播地址
    	const char *taddr = "fe80::20d:dff:fe0d:d0d";   // 待解析 IPv6 地址
    	ndp_addr_resolution(smac, saddr, daddr, taddr);
    	return 0;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55

    测试结果

    gcc -Wall -g -o ndp ipv6.c ndp.c cksum.c main.c && watch sudo ./ndp
    
    88
    00
    b087
    fe80::20d:dff:fe0d:d0d
    0:d:d:d:d:d                # 解析出来的 link 层地址
    
    192.168.2.200> sudo tcpdump -nt -XX icmp6
    IP6 fe80::20c:cff:fe0c:c0c > ff02::1:ff0d:d0d: ICMP6, neighbor solicitation, who has fe80::20d:dff:fe0d:d0d, length 32
    	0x0000:  3333 ff0d 0d0d 000c 0c0c 0c0c 86dd 6005  # 以太网地址第一位为奇数,表示组播地址
    	0x0010:  cbe6 0020 3aff fe80 0000 0000 0000 020c  ....:...........
    	0x0020:  0cff fe0c 0c0c ff02 0000 0000 0000 0000  ................
    	0x0030:  0001 ff0d 0d0d 8700 2314 0000 0000 fe80  ........#.......
    	0x0040:  0000 0000 0000 020d 0dff fe0d 0d0d 0101  ................
    	0x0050:  000c 0c0c 0c0c                           ......
    IP6 fe80::20d:dff:fe0d:d0d > fe80::20c:cff:fe0c:c0c: ICMP6, neighbor advertisement, tgt is fe80::20d:dff:fe0d:d0d, length 32
    	0x0000:  000c 0c0c 0c0c 000d 0d0d 0d0d 86dd 6000  ..............`.
    	0x0010:  0000 0020 3aff fe80 0000 0000 0000 020d  ....:...........
    	0x0020:  0dff fe0d 0d0d fe80 0000 0000 0000 020c  ................
    	0x0030:  0cff fe0c 0c0c 8800 b087 6000 0000 fe80  ..........`.....
    	0x0040:  0000 0000 0000 020d 0dff fe0d 0d0d 0201  ................
    	0x0050:  000d 0d0d 0d0d                           ......    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
  • 相关阅读:
    OpenCV遍历图像像素
    原型设计软件,异地办公提升效率
    基于STM32结合CubeMX学习Free-RT-OS的源码之消息队列
    mysql给所有数据库表加字段
    wireshark与tcpdump
    Explain语句结果中各个字段分别表示什么
    matlab预测股票价格走势
    【图画】【终身学习】
    【2012】【论文笔记】超材料的二维等价物——GSTC
    卷积神经网络-池化层和激活层
  • 原文地址:https://blog.csdn.net/m0_51451952/article/details/133861380