2021-07-18 17:46:08 +01:00
|
|
|
module libtun.adapter;
|
|
|
|
|
|
|
|
extern (C) int ioctl(int fd, ulong request, void* data);
|
|
|
|
extern (C) int open(char* path, int flags);
|
|
|
|
|
|
|
|
import std.stdio;
|
2021-07-18 18:26:15 +01:00
|
|
|
|
2021-07-18 17:46:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TUN maintenance routines in `test.c`
|
|
|
|
*/
|
2021-07-18 18:23:16 +01:00
|
|
|
extern (C) int createTun(char* interfaceName, int iffFlags);
|
2021-07-18 17:46:08 +01:00
|
|
|
extern (C) int destroyTun(int fd);
|
|
|
|
|
|
|
|
public class TUNAdapter
|
|
|
|
{
|
|
|
|
this(string interfaceName)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init()
|
|
|
|
{
|
2021-07-18 18:23:16 +01:00
|
|
|
int tunFD = createTun(cast(char*)"dd", 1);
|
2021-07-18 18:26:15 +01:00
|
|
|
if(tunFD < 0)
|
|
|
|
{
|
|
|
|
throw new TUNException("Error creating tun device");
|
|
|
|
}
|
2021-07-18 17:46:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void receive(byte[] buffer)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void send(byte[] buffer)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2021-07-18 18:26:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public final class TUNException : Exception
|
|
|
|
{
|
|
|
|
this(string msg)
|
|
|
|
{
|
|
|
|
super(msg);
|
|
|
|
}
|
2021-07-18 17:46:08 +01:00
|
|
|
}
|