func ensurePort(addr string, port int) string {
	if strings.HasPrefix(addr, "[") {
		if strings.LastIndex(addr, ":") <= strings.LastIndex(addr, "]") {
			return addr + ":" + strconv.Itoa(port)
		}
		return addr
	}
	switch strings.Count(addr, ":") {
	case 0:
		return addr + ":" + strconv.Itoa(port)
	case 1:
		return addr
	default:
		return "[" + addr + "]:" + strconv.Itoa(port)
	}
}
ensurePort adds a port to an address if none are provided.
It handles both IPV4 and IPV6 addresses.
package xmpp
import (
	"strconv"
	"strings"
)