diff --git a/TunDevice.cpp b/TunDevice.cpp index 0787f15..a7b3fe2 100644 --- a/TunDevice.cpp +++ b/TunDevice.cpp @@ -44,6 +44,25 @@ TunDevice::TunDevice(const std::string& dev) _dev_name = ifr.ifr_name; _fd = fd; + // Bring interface up + kdebugf("Bringing interface up...\n"); + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); // Any socket will do + if(ioctl(sockfd, SIOCGIFFLAGS, (void*) &ifr) < 0) { + close(fd); + close(sockfd); + throw TunDevice::InitializationError( + "Could not get tunnel interface flags", errno, true); + } + ifr.ifr_flags |= IFF_UP | IFF_RUNNING; + + if(ioctl(sockfd, SIOCSIFFLAGS, (void*) &ifr) < 0) { + close(fd); + close(sockfd); + throw TunDevice::InitializationError( + "Could not bring tunnel interface up", errno, true); + } + close(sockfd); + // The device is now fully set up _poll_fd.fd = _fd; _poll_fd.events = POLLIN;