diff --git a/cmd/stunc/stunc.go b/cmd/stunc/stunc.go index 81edb1d24..9743a3300 100644 --- a/cmd/stunc/stunc.go +++ b/cmd/stunc/stunc.go @@ -8,6 +8,7 @@ "log" "net" "os" + "strconv" "tailscale.com/net/stun" ) @@ -15,12 +16,20 @@ func main() { log.SetFlags(0) - if len(os.Args) != 2 { - log.Fatalf("usage: %s ", os.Args[0]) + if len(os.Args) < 2 || len(os.Args) > 3 { + log.Fatalf("usage: %s [port]", os.Args[0]) } host := os.Args[1] + port := "3478" + if len(os.Args) == 3 { + port = os.Args[2] + } + _, err := strconv.ParseUint(port, 10, 16) + if err != nil { + log.Fatalf("invalid port: %v", err) + } - uaddr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(host, "3478")) + uaddr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(host, port)) if err != nil { log.Fatal(err) }