nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #! /bin/bash
2 # source: predialog.sh
3 # Copyright Gerhard Rieger
4 # Published under the GNU General Public License V.2, see file COPYING
5  
6 # This is an example script that shows how to write a script for use with socat
7 # intermediate addresses. it shows a case where an initial dialog on the right
8 # side is performed. afterwards data is just passed in both directions.
9  
10 # uncomment this if you want to analyse which file descriptors are open
11 #filan -s -o+2; sleep 1; echo
12  
13 # these are the "right side" file descriptors provided by socat; 0 and 1 are
14 # the "left side" FDs
15 RINFD=3
16 ROUTFD=4
17  
18 if [ -z "$SOCAT" ]; then
19 if type socat2 >/dev/null 2>&1; then
20 SOCAT=socat2
21 else
22 SOCAT="./socat"
23 fi
24 fi
25  
26 verbose=
27 # parse options
28 SPACES=" "
29 while [ -n "$1" ]; do
30 case "$1" in
31 -v) verbose=1 ;;
32 *) echo "$0: unknown option \"$1\"" >&2; exit -1 ;;
33 esac
34 shift
35 done
36  
37 msg () {
38 [ "$verbose" ] && echo "$0: $1" >&2
39 }
40  
41 # send a request
42 msg "sending request"
43 echo -e "CONNECT 10.0.0.1:80 HTTP/1.0\n" >&4
44  
45 # read reply
46 msg "waiting for reply"
47 read -r <&3
48 case "$REPLY" in
49 "HTTP/1.0 200 OK") ;;
50 *) msg "bad reply \"$REPLY\"" exit 1 ;;
51 esac
52 # skip headers until empty line
53 msg "skipping reply headers"
54 while read -r <&3 && ! [ "$REPLY" = "" ]; do :; done
55  
56 wait
57  
58 msg "starting data transfer"
59 # now just pass traffic in both directions
60 #SOCAT_OPTS="-lu -d -d -d -d"
61 exec $SOCAT $SOCAT_OPTS - "fd:$ROUTFD:$RINFD"