summaryrefslogtreecommitdiffstats
path: root/tun.c
diff options
context:
space:
mode:
Diffstat (limited to 'tun.c')
-rw-r--r--tun.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tun.c b/tun.c
index 406fc2f..7ecbf2c 100644
--- a/tun.c
+++ b/tun.c
@@ -32,9 +32,9 @@
int tun_open() {
int fd;
- fd = open("/dev/tun", O_RDWR);
+ fd = open("/dev/tun", O_RDWR | O_CLOEXEC);
if (fd < 0) {
- fd = open("/dev/net/tun", O_RDWR);
+ fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
}
return fd;
@@ -43,8 +43,10 @@ int tun_open() {
/* function: tun_alloc
* creates a tun interface and names it
* dev - the name for the new tun device
+ * fd - an open fd to the tun device node
+ * len - the length of the buffer pointed to by dev
*/
-int tun_alloc(char *dev, int fd) {
+int tun_alloc(char *dev, int fd, size_t len) {
struct ifreq ifr;
int err;
@@ -60,7 +62,7 @@ int tun_alloc(char *dev, int fd) {
close(fd);
return err;
}
- strcpy(dev, ifr.ifr_name);
+ strlcpy(dev, ifr.ifr_name, len);
return 0;
}