#!/bin/ksh #This shellscript is ip_receiver. #Split the standard input into separate files for each IP address and protocol. #The names of the files are /tmp/$$.$ip_address.$protocol #Then feed each file to either tcp_receiver or udp_receiver. #Sample use: tcp_receiver dir0 dir1 dir2 if [[ $# -le 0 ]] then echo $0: needs directory names as command line arguments 1>&2 exit 1 fi cat > /tmp/$$ while [[ -s /tmp/$$ ]] do #Read the three-byte header of the IP datagram. length=`chopoff 1 /tmp/$$` protocol=`chopoff 1 /tmp/$$` ip_address=`chopoff 1 /tmp/$$` #Read the TCP segment that the IP datagram contains. chopoff $((length - 3)) /tmp/$$ >> /tmp/$$.$ip_address.$protocol done rm /tmp/$$ for ((ip_address=0; ip_address < 10; ++ip_address)) { for ((protocol=1; protocol <= 2; ++protocol)) { if [[ -s /tmp/$$.$ip_address.$protocol ]] then if [[ $protocol -eq 1 ]] then tcp_receiver $1 < /tmp/$$.$ip_address.$protocol elif [[ $protocol -eq 2 ]] then udp_receiver $1 < /tmp/$$.$ip_address.$protocol fi rm /tmp/$$.$ip_address.$protocol fi } if [[ $# -le 1 ]] then break fi shift #Let $1 be the next directory given as a command line argument. } exit 0