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()) }