Lost my commits

Initial commit here (fucking Linux froze)
This commit is contained in:
Tristan B. Velloza Kildaire 2021-07-18 18:46:08 +02:00
commit d40a715bd6
6 changed files with 113 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@ -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

12
dub.json Normal file
View File

@ -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"]
}

5
dub.selections.json Normal file
View File

@ -0,0 +1,5 @@
{
"fileVersion": 1,
"versions": {
}
}

9
source/app.d Normal file
View File

@ -0,0 +1,9 @@
import std.stdio;
import libtun.adapter;
void main()
{
writeln("Edit source/app.d to start your project.");
new TUNAdapter("");
}

40
source/libtun/adapter.d Normal file
View File

@ -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)
{
}
}

32
source/libtun/tunctl.c Normal file
View File

@ -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<linux/if.h>
#include<linux/if_tun.h>
#include<fcntl.h>
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;
}