Bring up tun interface upon creation
This commit is contained in:
parent
ba2293e039
commit
0332766f0d
1 changed files with 19 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue