Skip to content

Commit bfce9b6

Browse files
authored
Merge pull request #58 from op3/listenip-ipv6-support
Add IPv6 support to listenip
2 parents 133c411 + 8a5910c commit bfce9b6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

internal/config/config.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,20 @@ func InitConfig() (*Config, error) {
180180
}
181181

182182
// check listenIP and proxyPort
183-
if net.ParseIP(listenIP) == nil {
184-
return nil, fmt.Errorf("invalid IP \"%s\" for listenip", listenIP)
185-
}
186183
if proxyPort < 1 || proxyPort > 65535 {
187-
return nil, errors.New("port number has to be between 1 and 65535")
184+
return nil, errors.New("port number has to be between 1 and 65535")
185+
}
186+
ip := net.ParseIP(listenIP)
187+
if ip == nil {
188+
return nil, fmt.Errorf("invalid IP \"%s\" for listenip", listenIP)
189+
}
190+
191+
// Properly format address for both IPv4 and IPv6
192+
if ip.To4() == nil {
193+
cfg.ListenAddress = fmt.Sprintf("[%s]:%d", listenIP, proxyPort)
194+
} else {
195+
cfg.ListenAddress = fmt.Sprintf("%s:%d", listenIP, proxyPort)
188196
}
189-
cfg.ListenAddress = fmt.Sprintf("%s:%d", listenIP, proxyPort)
190197

191198
// parse defaultLogLevel and setup logging handler depending on defaultLogJSON
192199
switch strings.ToUpper(logLevel) {

0 commit comments

Comments
 (0)