From 34bbc146bb7df8cdec9bceb75f00d29301164d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Mon, 29 Jul 2013 12:34:47 +0200 Subject: [PATCH] env added --- tlsserver.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tlsserver.go b/tlsserver.go index b414848..3022f0e 100644 --- a/tlsserver.go +++ b/tlsserver.go @@ -71,9 +71,29 @@ func handleConnection(conn net.Conn) { cmd.Stdin = conn cmd.Stdout = conn cmd.Stderr = os.Stderr - err := cmd.Run() + + // prepare environment according to tcp-environ(5) + lh, lp, err := net.SplitHostPort(conn.LocalAddr().String()) if err != nil { log.Println(err) + return + } + rh, rp, err := net.SplitHostPort(conn.LocalAddr().String()) + if err != nil { + log.Println(err) + return + } + cmd.Env = make([]string,0) + cmd.Env = append(cmd.Env, "PATH="+os.Getenv("PATH")) + cmd.Env = append(cmd.Env, "PROTO=TCP") + cmd.Env = append(cmd.Env, "TCPLOCALIP="+lh) + cmd.Env = append(cmd.Env, "TCPLOCALPORT="+lp) + cmd.Env = append(cmd.Env, "TCPREMOTEIP="+rh) + cmd.Env = append(cmd.Env, "TCPREMOTEPORT="+rp) + + err = cmd.Run() + if err != nil { + log.Println("after Run: ", err) } log.Println("Done with connection", conn.RemoteAddr()) }