我喜欢用C ++程序创建一个TUN / TAP接口。我在网上发现了一个直接的foward教程 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(在这种情况下,从没有任何开关的命令行)。 我的图书馆出了什么问题?
答案 0 :(得分:3)
尝试其他包含。使用......
#include <net/if.h>
......而不是......
#include <linux/if.h>
此外,请包含其他文件。
#include <fcntl.h>