env added

This commit is contained in:
Özgür Kesim 2013-07-29 12:34:47 +02:00
parent 975b3a8eee
commit 34bbc146bb

View File

@ -71,9 +71,29 @@ func handleConnection(conn net.Conn) {
cmd.Stdin = conn cmd.Stdin = conn
cmd.Stdout = conn cmd.Stdout = conn
cmd.Stderr = os.Stderr 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 { if err != nil {
log.Println(err) 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()) log.Println("Done with connection", conn.RemoteAddr())
} }