Skip to content

Commit

Permalink
cmd/stunc: support user-specified port (tailscale#12469)
Browse files Browse the repository at this point in the history
Updates tailscale/corp#20689

Signed-off-by: Jordan Whited <jordan@tailscale.com>
  • Loading branch information
jwhited authored Jun 14, 2024
1 parent 85ad0c2 commit 9189fe0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/stunc/stunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ import (
"log"
"net"
"os"
"strconv"

"tailscale.com/net/stun"
)

func main() {
log.SetFlags(0)

if len(os.Args) != 2 {
log.Fatalf("usage: %s <hostname>", os.Args[0])
if len(os.Args) < 2 || len(os.Args) > 3 {
log.Fatalf("usage: %s <hostname> [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)
}
Expand Down

0 comments on commit 9189fe0

Please sign in to comment.