diff options
| author | Dave Cheney <dave@cheney.net> | 2012-04-26 20:37:06 +1000 |
|---|---|---|
| committer | Dave Cheney <dave@cheney.net> | 2012-04-26 20:37:06 +1000 |
| commit | b333fd1d05df0831a43bd3138e35c61dc0f49cc0 (patch) | |
| tree | 29ba7562c40b0cb88003c83dc1ff01f7458a9f44 /ssh/example_test.go | |
| parent | bcdd6a2fd3e36323c71ab4c80588f4e48e8a3678 (diff) | |
| download | go-x-crypto-b333fd1d05df0831a43bd3138e35c61dc0f49cc0.tar.xz | |
go.crypto/ssh: add support for remote tcpip forwarding
Add support for server (remote) forwarded tcpip channels.
See RFC4254 Section 7.1
R=gustav.paul, jeff, agl, lieqiewang
CC=golang-dev
https://golang.org/cl/6038047
Diffstat (limited to 'ssh/example_test.go')
| -rw-r--r-- | ssh/example_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ssh/example_test.go b/ssh/example_test.go index ea772c2..c8a2de8 100644 --- a/ssh/example_test.go +++ b/ssh/example_test.go @@ -8,6 +8,8 @@ import ( "bytes" "fmt" "io/ioutil" + "log" + "net/http" "code.google.com/p/go.crypto/ssh/terminal" ) @@ -120,3 +122,30 @@ func ExampleDial() { } fmt.Println(b.String()) } + +func ExampleClientConn_Listen() { + config := &ClientConfig{ + User: "username", + Auth: []ClientAuth{ + ClientAuthPassword(password("password")), + }, + } + // Dial your ssh server. + conn, err := Dial("tcp", "localhost:22", config) + if err != nil { + log.Fatalf("unable to connect: %s", err) + } + defer conn.Close() + + // Request the remote side to open port 8080 on all interfaces. + l, err := conn.Listen("tcp", "0.0.0.0:8080") + if err != nil { + log.Fatalf("unable to register tcp forward: %v", err) + } + defer l.Close() + + // Serve HTTP with your SSH server acting as a reverse proxy. + http.Serve(l, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { + fmt.Fprintf(resp, "Hello world!\n") + })) +} |
