Compare commits

...

5 Commits

4 changed files with 18 additions and 23 deletions

View File

@ -13,9 +13,9 @@ First add it to your dub-based project via:
dub add libtun
```
### `TUNAdapter`
### `Adapter`
The `TUNAdapter` class provides you with all you need to get started. One can construct a new adapter as follows:
The `Adapter` class provides you with all you need to get started. One can construct a new adapter as follows:
```d
import libtun.adapter;

View File

@ -10,4 +10,13 @@ It appears you canot use PEEK on fd's that are not sockets.
Regardless of whether they implement queuoing or not, it would be nice
if that was allowed. And if tuntap did it. THEN I could make a system
that doesn't allocate something huge and THEN I could go ahead
and also PEEK read.
and also PEEK read.
## TODO
- [ ] Adapter settings
- [ ] `up`/`down` interface
- [ ] Set address on interface
- [ ] For source address selection
- [ ] For possible automatic route addition

View File

@ -1,22 +1,8 @@
module libtun.adapter;
extern (C) int ioctl(int fd, ulong request, void* data);
extern (C) int open(char* path, int flags);
import core.stdc.stdio;
/**
* TUN maintenance routines in `tunctl.c`
* TODO: Use import C here
*/
import libtun.tunctl;
// extern (C) int createTun(char* interfaceName, int iffFlags);
// extern (C) int destroyTun(int fd);
// extern (C) int tunWrite(int fd, char* data, int length);
// extern (C) int tunRead(int fd, char* data, int amount);
public class TUNAdapter
public class Adapter
{
/* Tunnel device descriptor */
private int tunFD;
@ -45,7 +31,7 @@ public class TUNAdapter
tunFD = createTun(cast(char*)interfaceName, 4096|adapterType);
if(tunFD < 0)
{
throw new TUNException("Error creating tun device");
throw new AdapterException("Error creating tun device");
}
/* TODO: Get device MTU and add functions for setting it */
@ -57,7 +43,7 @@ public class TUNAdapter
{
if(isClosed)
{
throw new TUNException("Cannot operate on closed tunnel device");
throw new AdapterException("Cannot operate on closed tunnel device");
}
}
@ -109,7 +95,7 @@ public class TUNAdapter
if(status < 0)
{
throw new TUNException("Read failed");
throw new AdapterException("Read failed");
}
else if(status == 0)
{
@ -149,7 +135,7 @@ public class TUNAdapter
}
public final class TUNException : Exception
public final class AdapterException : Exception
{
this(string msg)
{

View File

@ -8,7 +8,7 @@ import core.thread;
void main()
{
writeln("Edit source/app.d to start your project.");
TUNAdapter adapter = new TUNAdapter("testInterface0");
Adapter adapter = new Adapter("testInterface0");
while(true)
{