#!/usr/local/tcl/bin/tclsh7.6 # # $Id: tsoc,v 1.2 1996/10/24 16:31:38 loverso Exp loverso $ # # Make a connection to another host. # # -p use a local privledged port (must be root) # -r use raw more for input (line mode is the default) # These options apply under raw mode: # -i turn off local signals from input (i.e., SIGINTR) # -e enable local echo (required copychan) # foreach a $argv { switch -glob -- $a { -e {set echo 1} -r {set raw 1} -i {set isig 1} -p {set bindpriv 1} -- break -* {puts stderr "Unknown switch $a"} default break } set argv [lrange $argv 1 end] } if [info exists bindpriv] { set priv 1022 while {$priv > 512} { if [catch {eval socket -myport $priv $argv} s] { if [string match "*permission denied*" $s] { puts stderr "Can't get priv port: $s" exit 1 } incr priv -1 } else { break } } if {$priv == 512} { puts stderr "Couldn't get priv port (tried all): $s" exit 1 } puts stderr "Using priv port $priv" } else { set s [eval socket $argv] } set who [fconfigure $s -peername] puts stderr "Connected to [lrange $who 1 end]" fconfigure $s -blocking 0 -buffering none fconfigure stdin -blocking 0 -buffering none fconfigure stdout -buffering none if [catch {package require copychan}] { rename unsupported0 copychan if [info exists echo] { puts stderr "Can't load copychan: echo disabled" unset echo } } fileevent $s readable "copy $s stdout" fileevent stdin readable "copy stdin $s" if [info exists raw] { set cmd {stty -echo -icanon} if [info exists isig] { lappend cmd -isig } eval exec $cmd if [info exists echo] { fileevent stdin readable "copy stdin stdout $s" } } proc copy {s d} { eval copychan $s $d if [eof $s] { puts stderr "EOF on $s" exit 1 } } vwait forever