#!/bin/bash
usage="Usage: $0 tcpport udpport"
tcpport=${1?$usage}
udpport=${2?$usage}
fifo_parent=$(mktemp --tmpdir=/tmp -d tcptoudp.XXXX)
fifo=$fifo_parent/fifo
mkfifo $fifo
[[ ! -p $fifo || ! -r $fifo || ! -w $fifo ]] && { echo 'Fifo could not be made or does not have the right perms'; exit 1; }
echo 'starting nc'
nc -l $tcpport < $fifo | nc -u 127.0.0.1 $udpport > $fifo
echo 'cleaning up'
rm -f $fifo
rmdir $fifo_parent

