#!/bin/ksh #This shellscript is ip_sender. #Read input from all the programs in the directories given as command line #arguments. The name of each directory begins with a decimal digit giving that #directory's "IP address". # #Split the input into "IP datagrams" of at most 9 bytes each. #The first three bytes will be decimal digits. #The first byte is the total length of the datagram (at most 9). #The second byte is the protocol number (1 for TCP, 2 for UDP). #The third byte is the "IP address" (read from the directory's name). #The remaining 6 bytes are a TCP segment. # #Sample use: ip_sender 0_senderhost 1_senderhost if [[ $# -eq 0 ]] then echo $0: needs directory names as command line arguments 1>&2 exit 1 fi for host do if [[ ! -d $host ]] then echo $0: command line argument $host must be a directory 1>&2 exit 2 fi ip_address=`echo $host | sed 's/\(.\).*/\1/'` for prog in $host/* do if [[ $prog == *_tcp ]] then protocol=1 tcp_sender $prog > /tmp/$$ elif [[ $prog == *_udp ]] then protocol=2 udp_sender $prog > /tmp/$$ else echo $0: $prog must end with protocol name 1>&2 exit 2 fi while [[ -s /tmp/$$ ]] do chopoff 6 /tmp/$$ > /tmp/$$.data length=`wc -c < /tmp/$$.data` let length+=3 #Output the three-byte IP header. #The '\c' tells echo not to output a newline. echo $length'\c' echo $protocol'\c' echo $ip_address'\c' cat /tmp/$$.data rm /tmp/$$.data done rm /tmp/$$ done done exit 0