From 9189fe007be1a357aaab09051c736edaf8d3226c Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Fri, 14 Jun 2024 09:46:16 -0700 Subject: [PATCH] cmd/stunc: support user-specified port (#12469) Updates tailscale/corp#20689 Signed-off-by: Jordan Whited --- cmd/stunc/stunc.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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) }