accept IPv6 server addresses without a port

Append the default port only when the address does not already have
one.
The check looked for any colon, so a bare IPv6 literal such as
2001:db8::1 was treated as already carrying a port and was passed
through unusable, while a bracketed literal without a port never got
one appended.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Brandon McGinty
2026-08-20 14:42:52 -04:00
co-authored by Claude Opus 5
parent ecca0a63ed
commit a564286402
+11 -3
View File
@@ -7,6 +7,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"net"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@@ -188,9 +189,7 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if !strings.Contains(*server, ":") { *server = serverAddress(*server)
*server = (*server + ":64738")
}
// Initialize // Initialize
b := Barnard{ b := Barnard{
@@ -276,6 +275,15 @@ func jitterBufferDuration(milliseconds int) (time.Duration, error) {
} }
} }
// serverAddress appends Mumble's default port unless the address already has
// one. A bracketed or bare IPv6 literal is not a host:port pair.
func serverAddress(address string) string {
if _, port, err := net.SplitHostPort(address); err == nil && port != "" {
return address
}
return net.JoinHostPort(strings.Trim(address, "[]"), "64738")
}
func handle_raw_error(e error) { func handle_raw_error(e error) {
fmt.Fprintf(os.Stderr, "%s\n", e.Error()) fmt.Fprintf(os.Stderr, "%s\n", e.Error())
os.Exit(1) os.Exit(1)