diff --git a/source/libtun/adapter.d b/source/libtun/adapter.d index e4806df..c528a2f 100644 --- a/source/libtun/adapter.d +++ b/source/libtun/adapter.d @@ -55,6 +55,7 @@ public class TUNAdapter { sanityCheck(); + /* TODO: Get device MTU and add functions for setting it */ ushort mtu = cast(ushort)-1; /* Temporary scratchpad buffer */ @@ -75,7 +76,7 @@ public class TUNAdapter if(status < 0) { - + throw new TUNException("Read failed"); } else if(status == 0) { @@ -103,6 +104,16 @@ public class TUNAdapter tunWrite(tunFD, cast(char*)buffer.ptr, cast(int)buffer.length); } + + public void close() + { + int status = destroyTun(tunFD); + + if(status) + { + throw new TUNException("Closing tun interface failed"); + } + } } public final class TUNException : Exception diff --git a/source/libtun/tunctl.c b/source/libtun/tunctl.c index e8f7442..e48cdb1 100644 --- a/source/libtun/tunctl.c +++ b/source/libtun/tunctl.c @@ -50,7 +50,7 @@ int createTun(char* interfaceName, int iffFlags) int destroyTun(int fd) { - return 68; + return close(fd); } int tunWrite(int fd, char* data, int length)