【测试项目开源】基于LwIP实现在一个网口上同时支持IPv6+IPv4通信
来源:恩智浦MCU加油站 发布时间:2021-12-23 分享至微信
本文基于恩智浦的i.MX RT1170 EVK及SDK,讨论如何在一个以太网口上同时实现IPv6和IPv4通信。
测试环境:
SDK:2.10.1
IDE: MCUXpresso 11.4.0
EVK: i.MX RT1170
PC: Windows10
2、在lwipopts.h文件中, 参考本文提供的代码链接, 添加以下代码:
#define LWIP_IPV6 1
3、在lwip_udpecho_bm.c文件中, 参考本文提供的代码链接,添加以下代码:
ip6_addr_t ipaddr_v6;
s8_t chosen_idx;
IPv6
IP6_ADDR(&ipaddr_v6,PP_HTONL(0xFE800000),PP_HTONL(0x0),PP_HTONL(0x3DD79303),PP_HTONL(0x126c0df0));
netif_add_ip6_address(&netif, &ipaddr_v6, &chosen_idx);
netif.ip6_addr_state[chosen_idx] = IP6_ADDR_VALID;
ip6_addr_assign_zone(ip_2_ip6(&netif.ip6_addr[0]), IP6_UNICAST, &netif);
netif_ip6_addr_set_state(&netif, 0, IP6_ADDR_TENTATIVE);
5、参考下图用网线连接PC机和目标板。
C:\Users\nxa16038>ping 192.168.0.102
Pinging 192.168.0.102 with 32 bytes of data:
Reply from 192.168.0.102: bytes=32 time=2ms TTL=255
Reply from 192.168.0.102: bytes=32 time=1ms TTL=255
Reply from 192.168.0.102: bytes=32 time=1ms TTL=255
Reply from 192.168.0.102: bytes=32 time=1ms TTL=255
Ping statistics for 192.168.0.102:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 2ms, Average = 1ms
C:\Users\nxa16038>ping -6 FE80::3DD7:9303:126c:0df0
Pinging fe80::3dd7:9303:126c:df0 with 32 bytes of data:
Reply from fe80::3dd7:9303:126c:df0: time=1ms
Reply from fe80::3dd7:9303:126c:df0: time=1ms
Reply from fe80::3dd7:9303:126c:df0: time=1ms
Reply from fe80::3dd7:9303:126c:df0: time=2ms
Ping statistics for fe80::3dd7:9303:126c:df0:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 2ms, Average = 1ms
7、UDP测试
UDP测试需要使用相关的工具,在本文提供的代码链接中附带了此工具,测试命令和log如下所示:
C:\Users\nxa16038\Desktop\tt2\udp_test_tool\x64\Debug>udp_test.exe -6 FE80::3DD7:9303:126c:df0 7 5001 test_string_12345
Build date and time: Oct 22 2021, 18:50:48
arc = 6
arg[0] = udp_test.exe
arg[1] = -6
arg[2] = FE80::3DD7:9303:126c:df0
arg[3] = 7
arg[4] = 5001
arg[5] = test_string_12345
Send ok.
Receiving...
Get connection.
Get string: test_string_12345
Remote addr: fe80:0000:0000:0000:3dd7:9303:126c:0df0
C:\Users\nxa16038\Desktop\tt2\udp_test_tool\x64\Debug>udp_test.exe -4 192.168.0.102 7 5001 test_string_12345
Build date and time: Oct 22 2021, 18:50:48
arc = 6
arg[0] = udp_test.exe
arg[1] = -4
arg[2] = 192.168.0.102
arg[3] = 7
arg[4] = 5001
arg[5] = test_string_12345
Send ok.
Receiving...
Get connection.
Get string: test_string_12345, len = 17
Remote addr: 192.168.0.102
本文的原代码可以从github.com进行下载,无需密码,下载链接为:
https://github.com/jiaguonxpcom/lwip_ipv6_ipv4
该代码编译后可以直接下载到i.MX RT1170 EVK运行。
[ 新闻来源:恩智浦MCU加油站,更多精彩资讯请下载icspec App。如对本稿件有异议,请联系微信客服specltkj]
存入云盘 收藏
举报
全部评论
暂无评论哦,快来评论一下吧!
恩智浦MCU加油站
开创IC领域,共创美好未来!
查看更多
相关文章
华为MateX6:全球首款支持三网卫星通信
2024-12-18
成都:拟对109个集成电路项目进行支持
2024-11-12
维信诺第6代AMOLED生产线项目顺利交付
2024-11-11
投资10亿元,盛路通信建设新一代智能通信设备项目
2024-11-12
苹果面临创新挑战,下一个爆款产品或难再现
2024-11-11
热门搜索