Marste
Marste

Reputation: 679

C compiler errors on TUN/TAP

I like to create a TUN/TAP interface out of a C++ program. I found a straight foward tutorial on the net at http://backreference.org/2010/03/26/tuntap-interface-tutorial/.

The problem is, that I seem to have linking problems with with if.h and if_tun.h. When I strip the tutorial to the minimal example below, only to open a slot, I get a number of errors. Example:

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

If think this should compile, yet I get the following errors:

/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

I'm using GCC 4.7.2 (in this case, from the command line without any switches) on Fedora 18 with Linux 3.11.4. What's wrong with my libraries?

Upvotes: 3

Views: 1962

Answers (1)

rickhg12hs
rickhg12hs

Reputation: 11912

Try a different include. Use ...

#include <net/if.h>

... instead of ...

#include <linux/if.h>

In addition, include another file.

#include <fcntl.h>

Upvotes: 3

Related Questions