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:
5
main.go
5
main.go
@@ -368,7 +368,10 @@ func main() {
|
|||||||
h := newHandler(cfg)
|
h := newHandler(cfg)
|
||||||
dialTarget := cfg.Broker
|
dialTarget := cfg.Broker
|
||||||
if cfg.BrokerIP != "" {
|
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)
|
brokerURL := fmt.Sprintf("ssl://%s:%d", dialTarget, cfg.Port)
|
||||||
topic := cfg.TopicPrefix + "/#"
|
topic := cfg.TopicPrefix + "/#"
|
||||||
|
|||||||
Reference in New Issue
Block a user