second commit
This commit is contained in:
@ -17,8 +17,8 @@ class TunDevice(
|
|||||||
output = FileOutputStream(fd)
|
output = FileOutputStream(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openTun(name: String): java.io.FileDescriptor {
|
private fun openTun(name: String): FileDescriptor {
|
||||||
val fd = java.io.FileDescriptor()
|
val fd = FileDescriptor()
|
||||||
|
|
||||||
val tun = RandomAccessFile("/dev/net/tun", "rw")
|
val tun = RandomAccessFile("/dev/net/tun", "rw")
|
||||||
val field = tun.javaClass.getDeclaredField("fd")
|
val field = tun.javaClass.getDeclaredField("fd")
|
||||||
|
|||||||
22
src/main/tun.c
Normal file
22
src/main/tun.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/if_tun.h>
|
||||||
|
#include <linux/if.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int create_tun(char *dev) {
|
||||||
|
struct ifreq ifr;
|
||||||
|
int fd = open("/dev/net/tun", O_RDWR);
|
||||||
|
|
||||||
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
|
|
||||||
|
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
|
||||||
|
strcpy(ifr.ifr_name, dev);
|
||||||
|
|
||||||
|
ioctl(fd, TUNSETIFF, &ifr);
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// gcc -shared -o libtun.so -fPIC src/main/tun.c
|
||||||
Reference in New Issue
Block a user