cmd/stunc: support user-specified port (#12469)

Updates tailscale/corp#20689

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited 2024-06-14 09:46:16 -07:00 committed by GitHub
parent 85ad0c276c
commit 9189fe007b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,6 +8,7 @@
"log" "log"
"net" "net"
"os" "os"
"strconv"
"tailscale.com/net/stun" "tailscale.com/net/stun"
) )
@ -15,12 +16,20 @@
func main() { func main() {
log.SetFlags(0) log.SetFlags(0)
if len(os.Args) != 2 { if len(os.Args) < 2 || len(os.Args) > 3 {
log.Fatalf("usage: %s <hostname>", os.Args[0]) log.Fatalf("usage: %s <hostname> [port]", os.Args[0])
} }
host := os.Args[1] 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }