commit d40a715bd6052e4ae1cc06127d77a205b82393f9 Author: Tristan B. Kildaire Date: Sun Jul 18 18:46:08 2021 +0200 Lost my commits Initial commit here (fucking Linux froze) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..253352d --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +.dub +docs.json +__dummy.html +docs/ +/libtun +libtun.so +libtun.dylib +libtun.dll +libtun.a +libtun.lib +libtun-test-* +*.exe +*.o +*.obj +*.lst diff --git a/dub.json b/dub.json new file mode 100644 index 0000000..04e82c4 --- /dev/null +++ b/dub.json @@ -0,0 +1,12 @@ +{ + "authors": [ + "Tristan B. Kildaire" + ], + "copyright": "Copyright © 2021, Tristan B. Kildaire", + "description": "TUN adapter for D", + "license": "GPLv3", + "name": "libtun", + "targetType": "executable", + "preBuildCommands": ["gcc source/libtun/tunctl.c -o tunctl.o -c"], + "lflags": ["tunctl.o"] +} \ No newline at end of file diff --git a/dub.selections.json b/dub.selections.json new file mode 100644 index 0000000..322586b --- /dev/null +++ b/dub.selections.json @@ -0,0 +1,5 @@ +{ + "fileVersion": 1, + "versions": { + } +} diff --git a/source/app.d b/source/app.d new file mode 100644 index 0000000..741a370 --- /dev/null +++ b/source/app.d @@ -0,0 +1,9 @@ +import std.stdio; + +import libtun.adapter; + +void main() +{ + writeln("Edit source/app.d to start your project."); + new TUNAdapter(""); +} diff --git a/source/libtun/adapter.d b/source/libtun/adapter.d new file mode 100644 index 0000000..916934d --- /dev/null +++ b/source/libtun/adapter.d @@ -0,0 +1,40 @@ +module libtun.adapter; + +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` +*/ +extern (C) int createTun(char* interafce); +extern (C) int destroyTun(int fd); + +public class TUNAdapter +{ + this(string interfaceName) + { + init(); + } + + private void init() + { + int tunFD = open(cast(char*)"/dev/net/tun", _F_RDWR); + writeln(tunFD); + writeln(createTun(cast(char*)"")); + writeln(destroyTun(1)); + ioctl(0,0,cast(void*)0); + } + + public void receive(byte[] buffer) + { + + } + + public void send(byte[] buffer) + { + + } +} \ No newline at end of file diff --git a/source/libtun/tunctl.c b/source/libtun/tunctl.c new file mode 100644 index 0000000..cdb0c8d --- /dev/null +++ b/source/libtun/tunctl.c @@ -0,0 +1,32 @@ +/** +* This module is used just to interface between the Linux +* kernel (via GLIBC) such that the tun adpater can be setup +* and destroyed +* +* `int createTun(char* interfaceName)` +* - This creates a tun interface with the provided name +* - and returns the fd +* `int destroyTun(int fd)` +* - This destroys the tun interface given +* +* Once we have the fd everything else can be done in D +* as we just read()/write() on the returned fd we got +* using `createTun` +*/ + +#include +#include +#include + +int createTun(char* interfaceName) +{ + /* TODO: Add all required error checking */ + int tunFD = open("/dev/net/tun", O_RDWR); + return 69; +} + +int destroyTun(int fd) +{ + return 68; +} +