summaryrefslogtreecommitdiffstats
path: root/tun.c
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-05-11 23:08:19 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-05-11 23:08:19 +0000
commit7a459c9d6b413adb172c079e384b9289178a76d0 (patch)
treeac9a90d6280e22785aaca68db210bf5612ea1b13 /tun.c
parentc02fd4dc76fdf91b3f1eabeff93d23f00efc9cae (diff)
parent8addcc0f6360cc3762e9ef27437ded250e785da3 (diff)
downloadplatform_external_android-clat-7a459c9d6b413adb172c079e384b9289178a76d0.tar.gz
platform_external_android-clat-7a459c9d6b413adb172c079e384b9289178a76d0.tar.bz2
platform_external_android-clat-7a459c9d6b413adb172c079e384b9289178a76d0.zip
Change-Id: I0e5565734f35630e089a6504bb60cbee2f572502
Diffstat (limited to 'tun.c')
-rw-r--r--tun.c29
1 files changed, 3 insertions, 26 deletions
diff --git a/tun.c b/tun.c
index 7ecbf2c..e2f1342 100644
--- a/tun.c
+++ b/tun.c
@@ -21,20 +21,19 @@
#include <linux/if_tun.h>
#include <string.h>
#include <sys/ioctl.h>
-#include <sys/uio.h>
#include <unistd.h>
#include "common.h"
/* function: tun_open
- * tries to open the tunnel device
+ * tries to open the tunnel device in non-blocking mode
*/
int tun_open() {
int fd;
- fd = open("/dev/tun", O_RDWR | O_CLOEXEC);
+ fd = open("/dev/tun", O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (fd < 0) {
- fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
+ fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK | O_CLOEXEC);
}
return fd;
@@ -65,25 +64,3 @@ int tun_alloc(char *dev, int fd, size_t len) {
strlcpy(dev, ifr.ifr_name, len);
return 0;
}
-
-/* function: set_nonblocking
- * sets a filedescriptor to non-blocking mode
- * fd - the filedescriptor
- * returns: 0 on success, -1 on failure
- */
-int set_nonblocking(int fd) {
- int flags = fcntl(fd, F_GETFL);
- if (flags == -1) {
- return flags;
- }
- return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
-}
-
-/* function: send_tun
- * sends a clat_packet to a tun interface
- * fd - the tun filedescriptor
- * out - the packet to send
- * iov_len - the number of entries in the clat_packet
- * returns: number of bytes read on success, -1 on failure
- */
-int send_tun(int fd, clat_packet out, int iov_len) { return writev(fd, out, iov_len); }