#!/bin/sh

# Shall the CIRCLE_BRIDGE be deprecated and be replaced by something different?

ip=$(ifconfig $CIRCLE_BRIDGE | awk '/inet addr:/{print substr($2,6);}')
linklocalip6=$(ifconfig $CIRCLE_BRIDGE | awk '$4 == "Scope:Link" {print substr($3,1);}' | cut -d "/" -f 1)

max_ttl="--max-ttl=1"
port="--port=$CIRCLE_DNSMASQ_PORT"
server_ips="--server=$ip#53 --server=$linklocalip6#53"
host_file="-H $CIRCLE_TMP/circle_hosts"
pid_file="--pid-file=$CIRCLE_TMP/dnsmasq.pid"
dnsmasq_opts="--cache-size=500 --user=root -k -R"

exec $CIRCLE_ROOT/dnsmasq -C "" $max_ttl $port $server_ips $host_file $pid_file $dnsmasq_opts
