| 36 | } |
| 37 | |
| 38 | func (t *SSHTun) start() (err error) { |
| 39 | log.Info("tunnel for %s (via %s) available at %s ...", |
| 40 | tui.Bold(t.tunnel.Remote.String()), |
| 41 | tui.Dim(t.host), |
| 42 | tui.Bold(t.tunnel.Local.String())) |
| 43 | |
| 44 | if t.listener, err = net.Listen("tcp", t.tunnel.Local.String()); err != nil { |
| 45 | return |
| 46 | } |
| 47 | defer t.listener.Close() |
| 48 | |
| 49 | for { |
| 50 | if conn, err := t.listener.Accept(); err != nil { |
| 51 | log.Error("error while accepting connection: %s", err) |
| 52 | continue |
| 53 | } else { |
| 54 | go t.forward(conn) |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func (t *SSHTun) pipe(writer, reader net.Conn) { |
| 60 | if _, err := io.Copy(writer, reader); err != nil { |