Fix IPv6 zone ID encoding in broker URL

The zone identifier in fe80::%eth0 must be percent-encoded as %25
in a URL so Go's url.Parse accepts it. Without this, paho.mqtt.golang
silently drops the broker and reports "no servers defined to connect to".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 07:43:45 +02:00
parent 2dcfaeacb7
commit d82945098b

View File

@@ -368,7 +368,10 @@ func main() {
h := newHandler(cfg)
dialTarget := cfg.Broker
if cfg.BrokerIP != "" {
dialTarget = "[" + cfg.BrokerIP + "]"
// URL-encode the zone ID separator so Go's url.Parse accepts it.
// net.Dial receives the unescaped form and handles the zone correctly.
encodedIP := strings.ReplaceAll(cfg.BrokerIP, "%", "%25")
dialTarget = "[" + encodedIP + "]"
}
brokerURL := fmt.Sprintf("ssl://%s:%d", dialTarget, cfg.Port)
topic := cfg.TopicPrefix + "/#"