#!/system/bin/sh
# Using tap interface and iptables network for portable qemu on android
# Author: felonwan@gmail.com
# Modified: 10-25-2014

#create tun/tap device
if [ ! -e /dev/net/tun ]; then
  mkdir -p /dev/net
  busybox mknod /dev/net/tun c 10 200
  chmod 600 /dev/net/tun
fi

# create and configure virtual tap0 interface
./tunctl -t tap0
ifconfig tap0 192.168.0.1 netmask 255.255.255.0 up

# use iptables to forward data
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -s 192.168.0.0/24 -j MASQUERADE