From ca5634679c8586f9ebb4a2ec64f11199323b5785 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 18 Jul 2021 19:26:15 +0200 Subject: [PATCH] Throw exception on failure to create tun device --- source/libtun/adapter.d | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/libtun/adapter.d b/source/libtun/adapter.d index 0d8be08..16d3498 100644 --- a/source/libtun/adapter.d +++ b/source/libtun/adapter.d @@ -4,7 +4,7 @@ extern (C) int ioctl(int fd, ulong request, void* data); extern (C) int open(char* path, int flags); import std.stdio; -import core.stdc.stdio; + /** * TUN maintenance routines in `test.c` @@ -22,10 +22,10 @@ public class TUNAdapter private void init() { int tunFD = createTun(cast(char*)"dd", 1); - writeln(tunFD); - writeln(); - writeln(destroyTun(1)); - ioctl(0,0,cast(void*)0); + if(tunFD < 0) + { + throw new TUNException("Error creating tun device"); + } } public void receive(byte[] buffer) @@ -37,4 +37,12 @@ public class TUNAdapter { } +} + +public final class TUNException : Exception +{ + this(string msg) + { + super(msg); + } } \ No newline at end of file