#!/bin/ksh #This shellscript is udp_receiver. #Split the standard input into separate files for each port number. #The names of the files are /tmp/$$.$port #Then feed each file to the correct program in the directory given as a #command line argument. #Sample use: udp_receiver 0_receiverhost if [[ $# -ne 1 ]] then echo $0: needs one directory name as a command line argument 1>&2 exit 1 fi cat > /tmp/$$ while [[ -s /tmp/$$ ]] do #Read the two-byte TCP header. length=`chopoff 1 /tmp/$$` port=`chopoff 1 /tmp/$$` #Demultiplex: write the UDP packet to the file for that port number. chopoff $((length - 2)) /tmp/$$ >> /tmp/$$.$port done rm /tmp/$$ for prog in $1/* do port=`echo ${prog##*/} | sed 's/\(.\).*/\1/'` if [[ -s /tmp/$$.$port ]] then $prog < /tmp/$$.$port fi done exit 0