linux tun 读取数据,Linux Tun/Tap网口(/dev/net/tun)的读写方法 |
您所在的位置:网站首页 › tap怎么读 › linux tun 读取数据,Linux Tun/Tap网口(/dev/net/tun)的读写方法 |
我的代码 https://github.com/liuqun/demo-linux-tun-virtual-netcard/blob/master/demo-1-ioctl/src/main.c 代码片段1 以下代码节选自"openV屁N"的源码tun.c文件: openV屁N封装了一组读写函数如下: open_tun(dev_name, dev_type, dev_node, tuntap上下文)打开Tun虚拟网卡 close_tun(tuntap上下文) n_bytes = write_tun(tuntap上下文, buf, len) n_bytes = read_tun(tuntap上下文, buf, len) int write_tun(struct tuntap *tt, uint8_t *buf, int len) { return write(tt->fd, buf, len); } int read_tun(struct tuntap *tt, uint8_t *buf, int len) { return read(tt->fd, buf, len); } void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt) { struct ifreq ifr; /* * We handle --dev null specially, we do not open /dev/null for this. */ if (tt->type == D |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |