sshpiper/sshpiperd/utils/common.go
Donatas Abraitis f14ff4278b
Print SSH upstream in brackets to distinguish port properly (#84)
Before:
```
% sshpiperd pipe list
donatas -> root@2a02:4231:face:1001:1610:931c:2980:9d9d:22
```

After:
```
% sshpiperd pipe list
donatas -> root@[2a02:4231:face:1001:1610:931c:2980:9d9d]:22
```
2022-03-28 23:53:19 -07:00

17 lines
231 B
Go

package utils
import (
"fmt"
"net"
"strings"
)
func FormatIPAddress(host string) string {
ip4 := net.ParseIP(host).To4()
if ip4 != nil || !strings.Contains(host, ":") {
return host
}
return fmt.Sprintf("[%s]", host)
}