修改adress.go的convPort方法,支持IPv6地址之间建立连接。 (#248)

monapi:
  http: '[::]:5800'
  address:
  - '[::1]'
This commit is contained in:
杨善阳 2020-07-20 09:58:03 +08:00 committed by GitHub
parent 520dda70c0
commit b63c4e510c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -40,7 +40,11 @@ func GetRPCPort(mod string) int {
}
func convPort(module, listen, portType string) int {
port, err := strconv.Atoi(strings.Split(listen, ":")[1])
splitChar := ":"
if IsIPv6(listen) {
splitChar = "]:"
}
port, err := strconv.Atoi(strings.Split(listen, splitChar)[1])
if err != nil {
fmt.Printf("%s.%s invalid", module, portType)
os.Exit(1)
@ -127,3 +131,8 @@ func getConf() string {
os.Exit(1)
return ""
}
func IsIPv6(address string) bool {
return strings.Count(address,":") >=2
}