patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 49003e979fa8eccee66a0271026d712725715ed6 717 bytes (raw)

 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
34
35
36
37
38
39
 
// SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2022, 2024 Alyssa Ross <hi@alyssa.is>

#include "net-util.h"

#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

#include <sys/ioctl.h>

#include <linux/if_tun.h>

int tap_open(char name[static IFNAMSIZ], int flags)
{
	struct ifreq ifr;
	int fd, e;

	if (strnlen(name, IFNAMSIZ) == IFNAMSIZ) {
		errno = ENAMETOOLONG;
		return -1;
	}

	strncpy(ifr.ifr_name, name, IFNAMSIZ - 1);
	ifr.ifr_flags = IFF_TAP|flags;

	if ((fd = open("/dev/net/tun", O_RDWR)) == -1)
		return -1;
	if (ioctl(fd, TUNSETIFF, &ifr) == -1) {
		e = errno;
		close(fd);
		errno = e;
		return -1;
	}

	strncpy(name, ifr.ifr_name, IFNAMSIZ);
	return fd;
}

debug log:

solving 49003e9 ...
found 49003e9 in https://spectrum-os.org/git/spectrum

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).