simplify connForward

This commit is contained in:
octeep 2022-03-28 18:58:13 +01:00 committed by octeep
parent a350089f70
commit 623c172931

10
main.go
View file

@ -7,6 +7,7 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io"
"log" "log"
"math/rand" "math/rand"
"net" "net"
@ -266,18 +267,11 @@ func (c CredentialValidator) Valid(username, password string) bool {
func connForward(bufSize int, from, to net.Conn) { func connForward(bufSize int, from, to net.Conn) {
buf := make([]byte, bufSize) buf := make([]byte, bufSize)
for { _, err := io.CopyBuffer(to, from, buf)
size, err := from.Read(buf)
if err != nil { if err != nil {
to.Close() to.Close()
return return
} }
_, err = to.Write(buf[:size])
if err != nil {
to.Close()
return
}
}
} }
func tcpClientForward(tnet *netstack.Net, target string, conn net.Conn) { func tcpClientForward(tnet *netstack.Net, target string, conn net.Conn) {