Search code examples
cubuntutcppingtun-tap

How to test ICMP in my stack over TAP device?


I'm writting code to implement a simple TCP/IP stack over TAP device. But when I want to test ICMP code, I find that ping $(TAP IP) won't send packets to TAP device. It always sends them to loopback. So how can I test my ICMP code?

My system is Ubuntu-18.04
When I test ARP, I use arping -I $(TAP NAME) $(TAP IP), and it works fine. But ping -I $(TAP NAME) $(TAP IP) still sends packets to loopback.


Solution

  • When you want to send out packet by your tap interface, you should set dst ip to remote addr instead of your local addr. Assume your tap ip is 192.168.1.10/24 , you should ping 192.168.1.20 for example. And before you ping, you should set static arp first.

    arp -s 192.168.1.20 12:34:56:78:90:ab