【发布时间】:2013-11-18 23:44:12
【问题描述】:
我喜欢用 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(在这种情况下,从命令行不带任何开关)。 我的库有什么问题?
【问题讨论】:
-
尝试了(gcc 和 .c 文件扩展名以及 g++ 和 .cpp 文件扩展名),结果相同。