5

I am unable to set TUN interface. Everywhere i searched and it says the device should be rooted. I am setting up proxyserver on my ubuntu 14.04 system

static int get_interface(char *name) {
int interface = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;   
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));

if (ioctl(interface, TUNSETIFF, (void *)&ifr) < 0) {
    perror("Cannot get TUN interface");
    exit(1);
}

return interface;

}

user2044000
  • 53
  • 1
  • 1
  • 5
  • User Mode Linux Utitilies contains tools for manipulating TUN and TAP devices. Peek into the source there. http://user-mode-linux.sourceforge.net/downloads.html – Stian Skjelstad May 04 '16 at 11:30

1 Answers1

1

Check your device name (i.e. ifr.ifr_name). Another process maybe using the same device. For example, you may be trying to use tun0 and another process has it open already.

hackmaxed
  • 41
  • 2