mirror of https://github.com/deavmi/libtun.git
Lost my commits
Initial commit here (fucking Linux froze)
This commit is contained in:
commit
d40a715bd6
|
@ -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
|
|
@ -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"]
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"fileVersion": 1,
|
||||||
|
"versions": {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
import libtun.adapter;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
writeln("Edit source/app.d to start your project.");
|
||||||
|
new TUNAdapter("");
|
||||||
|
}
|
|
@ -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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue