diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2003-02-06 12:21:49 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2003-02-06 12:21:49 +0000 |
commit | 5c1f3b65a6f5abeae8459f41adb8fd2316971515 (patch) | |
tree | 21a82daa1abab96c967d731c7afe2a3a2bd07fff /Functions/TCP/tcp_proxy | |
parent | 809ab19dff75185a805b4cbb31a6b89f225167f4 (diff) | |
download | zsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.tar.gz zsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.tar.xz zsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.zip |
18202: New TCP function system plus small error message change in ztcp.
Diffstat (limited to 'Functions/TCP/tcp_proxy')
-rw-r--r-- | Functions/TCP/tcp_proxy | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Functions/TCP/tcp_proxy b/Functions/TCP/tcp_proxy new file mode 100644 index 000000000..3f19bd3de --- /dev/null +++ b/Functions/TCP/tcp_proxy @@ -0,0 +1,31 @@ +# Listen on the given port and for every connection, start a new +# command (defaults to $SHELL) in the background on the accepted fd. +# WARNING: this can leave your host open to the universe. For use +# in a restricted fashion on a secure network. +# +# Remote logins are much more efficient... + +local TCP_LISTEN_FD +trap '[[ -n $TCP_LISTEN_FD ]] && ztcp -c $TCP_LISTEN_FD; return 1' \ + HUP INT TERM EXIT PIPE + +if [[ $1 != <-> ]]; then + print "Usage: $0 port [cmd args... ]" >&2 + return 1 +fi + +integer port=$1 +shift +ztcp -l $port || return 1 +TCP_LISTEN_FD=$REPLY + +(( $# )) || set -- ${SHELL:-zsh} +local cmd=$1 +shift + +while ztcp -a $TCP_LISTEN_FD; do + # hack to expand aliases without screwing up arguments + eval $cmd '$* <&$REPLY >&$REPLY 2>&$REPLY &' + # Close the session fd; we don't need it here any more. + ztcp -c $REPLY +done |