其他分享
首页 > 其他分享> > c-TUN / TAP上的C编译器错误

c-TUN / TAP上的C编译器错误

作者:互联网

我喜欢用C程序创建TUN / TAP接口.我在网上找到了直接的前瞻性教程
http://backreference.org/2010/03/26/tuntap-interface-tutorial/.

问题是,我似乎与if.h和if_tun.h有链接问题.
当我将教程简化为下面的最小示例时,仅打开一个插槽,就会遇到许多错误.
例:

#include <linux/if.h>
#include <linux/if_tun.h>
int main(void){
char *clonedev = "/dev/net/tun";
open(clonedev,O_RDWR);
return 0;
}

如果认为这应该编译,但出现以下错误:

/usr/include/linux/if.h:184:19: error: field 'ifru_addr' has incomplete type
/usr/include/linux/if.h:185:19: error: field 'ifru_dstaddr' has incomplete type
/usr/include/linux/if.h:186:19: error: field 'ifru_broadaddr' has incomplete type
/usr/include/linux/if.h:187:19: error: field 'ifru_netmask' has incomplete type
/usr/include/linux/if.h:188:20: error: field 'ifru_hwaddr' has incomplete type
tuntap.cpp: In function 'int main()':
tuntap.cpp:6:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tuntap.cpp:7:15: error: 'O_RDWR' was not declared in this scope
tuntap.cpp:7:21: error: 'open' was not declared in this scope

我在Linux 3.11.4的Fedora 18上使用GCC 4.7.2(在这种情况下,是从命令行使用的,没有任何开关).
我的图书馆怎么了?

解决方法:

尝试其他包含.采用 …

#include <net/if.h>

… 代替 …

#include <linux/if.h>

此外,包括另一个文件.

#include <fcntl.h>

标签:c-3,linux,c-4,tun
来源: https://codeday.me/bug/20191122/2060087.html