diff --git a/conn.go b/conn.go index bb1e2ff..725b22c 100644 --- a/conn.go +++ b/conn.go @@ -71,7 +71,7 @@ func (c *PairedConnection) handleServerMessage() { func (c *PairedConnection) process() { defer c.stop() - conn, err := net.Dial("tcp", settings.RemoteHost) + conn, err := net.Dial("tcp", settings.Remote) if err != nil { display.PrintlnWithTime(color.HiRedString("[x][%d] Couldn't connect to server: %v", c.id, err)) return @@ -100,19 +100,14 @@ func (c *PairedConnection) stop() { } func startListener() error { - listenerPort := settings.LocalPort - conn, err := net.Listen("tcp", fmt.Sprint(settings.LocalHost, ":", settings.LocalPort)) + conn, err := net.Listen("tcp", fmt.Sprintf("%s:%d", settings.LocalHost, settings.LocalPort)) if err != nil { return fmt.Errorf("failed to start listener: %w", err) } - - if listenerPort == 0 { - listenerPort = conn.Addr().(*net.TCPAddr).Port - } - display.PrintfWithTime("Listening on %s...\n", fmt.Sprint(settings.LocalHost, ":", listenerPort)) - defer conn.Close() + display.PrintfWithTime("Listening on %s...\n", conn.Addr().String()) + var connIndex int for { cliConn, err := conn.Accept() @@ -121,7 +116,8 @@ func startListener() error { } connIndex++ - display.PrintlnWithTime(color.HiGreenString("[%d] Accepted from: %s", connIndex, cliConn.RemoteAddr())) + display.PrintlnWithTime(color.HiGreenString("[%d] Accepted from: %s", + connIndex, cliConn.RemoteAddr())) pconn := NewPairedConnection(connIndex, cliConn) go pconn.process() diff --git a/main.go b/main.go index 91c44f6..93aed03 100644 --- a/main.go +++ b/main.go @@ -24,8 +24,8 @@ func main() { flag.Parse() saveSettings(*localHost, *localPort, *remote, *delay, *protocol, *quiet) - if settings.RemoteHost == "" { - fmt.Fprintln(os.Stderr, color.HiRedString("[x] Remote host required")) + if len(settings.Remote) == 0 { + fmt.Fprintln(os.Stderr, color.HiRedString("[x] Remote target required")) flag.PrintDefaults() os.Exit(1) } diff --git a/settings.go b/settings.go index 2d62e08..43277d5 100644 --- a/settings.go +++ b/settings.go @@ -3,15 +3,15 @@ package main import "time" type Settings struct { - RemoteHost string - LocalHost string - LocalPort int - Delay time.Duration - Protocol string - Quiet bool + Remote string + LocalHost string + LocalPort int + Delay time.Duration + Protocol string + Quiet bool } -func saveSettings(localHost string, localPort int, remoteHost string, delay time.Duration, +func saveSettings(localHost string, localPort int, remote string, delay time.Duration, protocol string, quiet bool) { if localHost != "" { settings.LocalHost = localHost @@ -19,8 +19,8 @@ func saveSettings(localHost string, localPort int, remoteHost string, delay time if localPort != 0 { settings.LocalPort = localPort } - if remoteHost != "" { - settings.RemoteHost = remoteHost + if remote != "" { + settings.Remote = remote } settings.Delay = delay settings.Protocol = protocol