(C) 虚拟网络适配器
Linux中是否有任何方法可以以编程方式创建一个可以监听的虚拟网络适配器,以便每当尝试通过适配器发送数据时,都会调用一个方法?
我试图将所有数据包转发到一个 IP 地址,然后将它们的原始位置包含在数据包中。
就像这样:
void sendPacket(char to[], char data[])
如果我通过虚拟网络适配器 ping google.com,该方法将像这样调用 sendPacket("GooglesIp","Whatever data a ping Sends")
Is there any way in linux to programatically create a virtual network adapter that can be listened to, so that whenever an attempt is made to send data through the adapter, a method is called?
I am trying to forward all packets to a single ip address, then include their original location in the packet.
something like this:
void sendPacket(char to[], char data[])
So like if I ping google.com through the virtual network adapter, the method will be called like this sendPacket("GooglesIp","Whatever data a ping sends")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的是 Linux 中的 TUN/TAP 设备,它允许程序充当网络接口。
http://en.wikipedia.org/wiki/TUN/TAP
然后你可以编写一个程序来听TUN/TAP 接口用于接收传入数据,并进行相应处理。基本上,您会将 ping 路由到新的 TUN/TAP 接口,然后让程序从接口读取数据包,并从那里路由它们。
I think what you are looking for is a TUN/TAP device in Linux, which allows a program to act as a network interface.
http://en.wikipedia.org/wiki/TUN/TAP
You could then write a program to listen to that TUN/TAP interface for incoming data, and process it accordingly. Basically you would route the pings to the new TUN/TAP interface, then have a program read the packets off the interface, and route them from there.