#!/bin/sh
# -*- mode: sh; tab-width: 8; coding: utf-8-unix -*-
# https://unix.stackexchange.com/questions/293304/using-netcat-for-port-forwarding

prog=$( basename $0 .bash )
PREFIX=/usr/local
ROLE=proxy
. /usr/local/bin/usr_local_tput.bash || exit 2

netstat -nlpe4 | grep -q 127.0.0.1:53 && {
    ERROR 127.0.0.1:53 already bound
    exit 1
}

MODE=$( /usr/local/bin/proxy_ping_lib.bash proxy_ping_mode )

if [ "$MODE" = tor -o "$MODE" = gateway -o "$MODE" = selektor ] ; then
    socat -L/run/socat.lck udp-l:53,bind=127.0.0.1,fork,reuseaddr udp:127.0.0.1:9053 >/dev/null
elif a[ "$MODE" = whonix  ] ; then
    socat -L/run/socat.lck udp-l:53,bind=127.0.0.1,fork,reuseaddr udp:10.0.2.2:9053 >/dev/null
fi

