summaryrefslogtreecommitdiff
path: root/src/inet.c
diff options
context:
space:
mode:
authorGustavo F. Padovan <padovan@profusion.mobi>2011-04-20 14:41:20 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2011-04-20 15:18:57 +0200
commit86f7f6daaa4d05428e73ba5417bd0a5b4970ed32 (patch)
tree179afff495c146a6e01d9ffe00e37c7d4bc9e35d /src/inet.c
parent55e275762c011595ed1d106bbb3867be415a8a07 (diff)
downloadconnman-86f7f6daaa4d05428e73ba5417bd0a5b4970ed32.tar.gz
connman-86f7f6daaa4d05428e73ba5417bd0a5b4970ed32.tar.bz2
connman-86f7f6daaa4d05428e73ba5417bd0a5b4970ed32.zip
tethering: Add support to create private networks TUN interface
Diffstat (limited to 'src/inet.c')
-rw-r--r--src/inet.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/inet.c b/src/inet.c
index 5e5d9cc8..ec2dc520 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -40,6 +40,8 @@
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/icmp6.h>
+#include <fcntl.h>
+#include <linux/if_tun.h>
#include "connman.h"
@@ -1265,6 +1267,40 @@ done:
return err;
}
+int connman_inet_create_tunnel(char **iface)
+{
+ struct ifreq ifr;
+ int i, fd;
+
+ fd = open("/dev/net/tun", O_RDWR);
+ if (fd < 0) {
+ i = -errno;
+ connman_error("Failed to open /dev/net/tun: %s",
+ strerror(errno));
+ return i;
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
+
+ for (i = 0; i < 256; i++) {
+ sprintf(ifr.ifr_name, "tun%d", i);
+
+ if (!ioctl(fd, TUNSETIFF, (void *)&ifr))
+ break;
+ }
+
+ if (i == 256) {
+ connman_error("Failed to find available tun device");
+ close(fd);
+ return -ENODEV;
+ }
+
+ *iface = g_strdup(ifr.ifr_name);
+
+ return fd;
+}
+
struct rs_cb_data {
GIOChannel *channel;
__connman_inet_rs_cb_t callback;