// HostPort returns the HostPort of the registry URL. If there is no port, then
// it returns just the host.
509636
func (u *DockerRegistryURL) HostPort() string {
	if u.Port == "" {
		return u.Host
	}
	return net.JoinHostPort(u.Host, u.Port)

}
912826
func (u *URI) HostPort() string {
	// XXX: The following is just to make TestHandler_Status; remove it
	if u == nil {
		return ""
	}
	s := fmt.Sprintf("%s:%d", u.Host, u.Port)
	return s
}
767033
func FromNetworkHostPort(nhp network.HostPort) HostPort {
	return HostPort{FromNetworkAddress(nhp.Address), nhp.Port}
}
1164217
func host(in string) string {
	out, err := utils.Host(in)
	if err != nil {
		return in
	}
	return out
}
556948
func (d *Data) HostPort(addr string) error {
	ip, port, err := net.SplitHostPort(addr)
	if err != nil {
		return err
	}
	p, err := strconv.ParseUint(port, 10, 32)
	if err != nil {
		return err
	}
	d.Port = uint32(p)

	if ip := net.ParseIP(ip); ip != nil {
		d.Address = []byte(ip)
		if ip := ip.To4(); ip != nil {
			d.SocketFam = tap.SocketFamily_INET
		} else {
			d.SocketFam = tap.SocketFamily_INET6
		}
		return nil
	}
	return errors.New("not an ip address")
}
791018
func (e ErrPortAlreadyAllocated) IPPort() string {
	return fmt.Sprintf("%s:%d", e.ip, e.port)
}
292022
func (options) HostPort(hostPort string) Option {
	return func(o *options) {
		o.hostPort = hostPort
	}
}
54409
func (a *NetAddr) Host() string {
	host, _, err := net.SplitHostPort(a.Addr)
	if err != nil {
		return a.Addr
	}
	return host
}
184142
func (a *NetAddr) Port(defaultPort int) int {
	_, port, err := net.SplitHostPort(a.Addr)
	if err != nil {
		return defaultPort
	}
	porti, err := strconv.Atoi(port)
	if err != nil {
		return defaultPort
	}
	return porti
}
248615
func (hm *hostportManager) closeHostports(hostportMappings []*PortMapping) error {
	errList := []error{}
	for _, pm := range hostportMappings {
		hp := portMappingToHostport(pm)
		if socket, ok := hm.hostPortMap[hp]; ok {
			klog.V(2).Infof("Closing host port %s", hp.String())
			if err := socket.Close(); err != nil {
				errList = append(errList, fmt.Errorf("failed to close host port %s: %v", hp.String(), err))
				continue
			}
			delete(hm.hostPortMap, hp)
		}
	}
	return utilerrors.NewAggregate(errList)
}
908983
func ParsePort(s string) (p Port, err error) {
	if strings.Contains(s, ":") {
		return portFromHostContainer(s)
	}

	var port int
	port, err = toPort(s)
	if err != nil {
		return
	}
	p.Host = port
	p.Container = port
	return
}
312154
func CaptureHost(hostport string) string {
	host, _, err := net.SplitHostPort(hostport)
	if err != nil {
		return ""
	}
	return host
}
842694
func ParseHostPortAddr(hostport string, defaultPort int) (*NetAddr, error) {
	addr, err := ParseAddr(hostport)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	// port is required but not set
	if defaultPort == -1 && addr.Addr == addr.Host() {
		return nil, trace.BadParameter("missing port in address %q", hostport)
	}
	addr.Addr = fmt.Sprintf("%v:%v", addr.Host(), addr.Port(defaultPort))
	return addr, nil
}
1287820
func (s *SiteInfo) ServerPort() int {
	ps := s.s.PathSpec.BaseURL.URL().Port()
	if ps == "" {
		return 0
	}
	p, err := strconv.Atoi(ps)
	if err != nil {
		return 0
	}
	return p
}
1108521
func splitHostPort(host string) (string, string) {
	ix := strings.LastIndex(host, ":")

	if ix <= strings.LastIndex(host, "]") {
		return host, ""
	}

	name := host[:ix]
	port := host[ix+1:]

	return name, port
}
506409
func (self *ConnectionString) Host(defaults ...string) string {
	if host := self.URI.Host; host != `` {
		return host
	} else if len(defaults) > 0 {
		return defaults[0]
	} else {
		return ``
	}
}
1044614
func hostAddr(addr string) string {
	_, port := splitHostPort(addr)
	if port == "" {
		return addr + ":443"
	}
	return addr
}