From 8a5910c516af26e52e330d393d393a3a86bbb89b Mon Sep 17 00:00:00 2001 From: Oliver Papst Date: Mon, 18 Aug 2025 21:18:44 +0200 Subject: [PATCH] add IPv6 support to listenip Accept IPv6 addresses in the standard notation. Examples: --listenip=:: --listenip=fd00::1 --- internal/config/config.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index bd99114..c7a73cb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -180,13 +180,20 @@ func InitConfig() (*Config, error) { } // check listenIP and proxyPort - if net.ParseIP(listenIP) == nil { - return nil, fmt.Errorf("invalid IP \"%s\" for listenip", listenIP) - } if proxyPort < 1 || proxyPort > 65535 { - return nil, errors.New("port number has to be between 1 and 65535") + return nil, errors.New("port number has to be between 1 and 65535") + } + ip := net.ParseIP(listenIP) + if ip == nil { + return nil, fmt.Errorf("invalid IP \"%s\" for listenip", listenIP) + } + + // Properly format address for both IPv4 and IPv6 + if ip.To4() == nil { + cfg.ListenAddress = fmt.Sprintf("[%s]:%d", listenIP, proxyPort) + } else { + cfg.ListenAddress = fmt.Sprintf("%s:%d", listenIP, proxyPort) } - cfg.ListenAddress = fmt.Sprintf("%s:%d", listenIP, proxyPort) // parse defaultLogLevel and setup logging handler depending on defaultLogJSON switch strings.ToUpper(logLevel) {