blob: c73ae92f063a41cd30b861e2597e27e84ad47c31 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
#include "../net-util.h"
#include <assert.h>
#include <errno.h>
#include <net/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <sched.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/if_tun.h>
int main(void)
{
char newname[IFNAMSIZ], name[IFNAMSIZ] = "tap%d";
struct ifreq ifr;
int r, fd;
unshare(CLONE_NEWUSER|CLONE_NEWNET);
r = snprintf(newname, sizeof newname, "_tap%d", rand());
assert(r > 0 && (size_t)r < sizeof newname);
if ((fd = tap_open(name, 0)) == -1)
return errno == EPERM || errno == ENOENT ? 77 : 1;
assert(!if_rename(name, newname));
assert(!ioctl(fd, (unsigned)TUNGETIFF, &ifr));
assert(!strcmp(ifr.ifr_name, newname));
}
|