作为一个个人项目,我想使用 C/C++ 和 Tap 接口构建一个 TCP/IP 堆栈。我有一个连接到互联网的 wlan0 接口(无线)。现在我想通过这个 wlan0 接口从互联网发送和接收数据包。
我怎样才能做到这一点?
这些是我用来创建我的点击界面的命令:
sudo ip tuntap add name tap1 mode tap
sudo ip link set tap1 up
sudo ip link set tap1 promisc on
sudo ip addr add 10.0.0.2/24 dev tap1
sudo ip route add dev tap1 10.0.0.0/24
这是的输出ip a
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether dc:f5:05:2c:12:a1 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.14/24 brd 192.168.1.255 scope global dynamic noprefixroute wlan0
valid_lft 84147sec preferred_lft 84147sec
inet6 fe80::1e59:c571:bc2f:66b9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
6: tap1: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether da:e8:0d:67:e7:fd brd ff:ff:ff:ff:ff:ff
inet 10.0.0.2/24 scope global tap1
valid_lft forever preferred_lft forever
inet6 fe80::d8e8:dff:fe67:e7fd/64 scope link
valid_lft forever preferred_lft forever
如果你想测试它,这是代码(我还在写它) https://github.com/Bechir-Brahem/tuntap-device