tun-device: Avoid opening /dev/tunX multiple times (e.g. on FreeBSD)
This commit is contained in:
parent
dcaf8d570c
commit
c8a56512a6
|
@ -390,14 +390,18 @@ static bool init_tun(private_tun_device_t *this, const char *name_tmpl)
|
|||
/* this works on FreeBSD and might also work on Linux with older TUN
|
||||
* driver versions (no IFF_TUN) */
|
||||
char devname[IFNAMSIZ];
|
||||
int i;
|
||||
/* the same process is allowed to open a device again, but that's not what
|
||||
* we want (unless we previously closed a device, which we don't know at
|
||||
* this point). therefore, this counter is static so we don't accidentally
|
||||
* open a device twice */
|
||||
static int i = -1;
|
||||
|
||||
if (name_tmpl)
|
||||
{
|
||||
DBG1(DBG_LIB, "arbitrary naming of TUN devices is not supported");
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
for (; ++i < 256; )
|
||||
{
|
||||
snprintf(devname, IFNAMSIZ, "/dev/tun%d", i);
|
||||
this->tunfd = open(devname, O_RDWR);
|
||||
|
|
Loading…
Reference in New Issue