// joinHostPort returns the host:port form of an address, for use with a
// transport.
965592
func joinHostPort(host string, port uint16) string {
	return net.JoinHostPort(host, strconv.Itoa(int(port)))
}
577211
func (c *Client) APIHostPorts() (result params.APIHostPortsResult, err error) {
	if err := c.checkCanWrite(); err != nil {
		return result, err
	}

	var servers [][]network.HostPort
	if servers, err = c.api.stateAccessor.APIHostPortsForClients(); err != nil {
		return params.APIHostPortsResult{}, err
	}
	result.Servers = params.FromNetworkHostsPorts(servers)
	return result, nil
}
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")
}
802162
func EnsureHostPort(address string) (string, error) {
	// make sure we ensure a schema, otherwise somewhere:8443 can return a
	// the following //:8443/somewhere
	uri, err := url.Parse(EnsureHTTPS(address))
	if err != nil {
		return "", errors.Trace(err)
	}
	if uri.Port() == "" {
		uri.Host = fmt.Sprintf("%s:%d", uri.Host, defaultPort)
	}
	return uri.String(), nil
}
328397
func restAddPort(w *rest.ResponseWriter, r *rest.Request, ctx *requestContext) {
	glog.V(1).Infof("Add PORT with %s %#v", r.URL.Path, r)

	serviceid, application, port, err := getPortContext(r)
	if err != nil {
		err := fmt.Errorf("Error removing port from service (%s): %v", serviceid, err)
		glog.Error(err)
		restServerError(w, err)
		return
	}

	var request endpointRequest
	err = r.DecodeJsonPayload(&request)
	if err != nil {
		restBadRequest(w, err)
		return
	}

	glog.V(0).Infof("Add PORT with %s %#v", r.URL.Path, r)

	facade := ctx.getFacade()
	dataCtx := ctx.getDatastoreContext()

	_, err = facade.AddPublicEndpointPort(dataCtx, serviceid, application,
		port, request.UseTLS, request.Protocol, true, true)
	if err != nil {
		glog.Errorf("Error adding port to service (%s): %v", request.ServiceName, err)
		restServerError(w, err)
		return
	}

	glog.V(2).Infof("Port (%s) added to service (%s), UseTLS=%s, protocol=%s",
		port, request.ServiceName, request.UseTLS, request.Protocol)

	restSuccess(w)
}
857974
func (n *Node) Address() string {
	return joinHostPort(n.Addr.String(), n.Port)
}
617224
func HostPort(s, defaultPort string) (string, error) {
	addr, port, err := net.SplitHostPort(s)
	if port == "" {
		port = defaultPort
	}
	if err != nil {
		if net.ParseIP(s) == nil {
			return "", fmt.Errorf("must specify an IP address: `%s'", s)
		}
		return net.JoinHostPort(s, port), nil
	}

	if net.ParseIP(addr) == nil {
		return "", fmt.Errorf("must specify an IP address: `%s'", addr)
	}
	return net.JoinHostPort(addr, port), nil
}
1004893
func (hm *hostportManager) openHostports(podPortMapping *PodPortMapping) (map[hostport]closeable, error) {
	var retErr error
	ports := make(map[hostport]closeable)
	for _, pm := range podPortMapping.PortMappings {
		if pm.HostPort <= 0 {
			continue
		}

		// We do not open host ports for SCTP ports, as we agreed in the Support of SCTP KEP
		if pm.Protocol == v1.ProtocolSCTP {
			continue
		}

		hp := portMappingToHostport(pm)
		socket, err := hm.portOpener(&hp)
		if err != nil {
			retErr = fmt.Errorf("cannot open hostport %d for pod %s: %v", pm.HostPort, getPodFullName(podPortMapping), err)
			break
		}
		ports[hp] = socket
	}

	// If encounter any error, close all hostports that just got opened.
	if retErr != nil {
		for hp, socket := range ports {
			if err := socket.Close(); err != nil {
				klog.Errorf("Cannot clean up hostport %d for pod %s: %v", hp.port, getPodFullName(podPortMapping), err)
			}
		}
		return nil, retErr
	}
	return ports, nil
}
271375
func UniqueHostPorts(hostPorts []HostPort) []HostPort {
	results := make([]HostPort, 0, len(hostPorts))

	seen := make(map[HostPort]bool, len(hostPorts))
	for _, hostPort := range hostPorts {
		if seen[hostPort] {
			continue
		}

		seen[hostPort] = true
		results = append(results, hostPort)
	}

	return results
}
1337629
func initAPIHostPorts(c agent.ConfigSetter, st *state.State, addrs []network.Address, apiPort int) error {
	hostPorts := network.AddressesWithPort(addrs, apiPort)
	return st.SetAPIHostPorts([][]network.HostPort{hostPorts})
}
1201182
func (b *Builder) HostPort(addr string) *Builder {
	ip, port, err := net.SplitHostPort(addr)
	if err != nil {
		b.err = err
		return b
	}
	p, err := strconv.ParseUint(port, 10, 32)
	if err != nil {
		b.err = err
		return b
	}
	b.Port = uint32(p)

	if ip := net.ParseIP(ip); ip != nil {
		b.Address = []byte(ip)
		if ip := ip.To4(); ip != nil {
			b.SocketFam = tap.SocketFamily_INET
		} else {
			b.SocketFam = tap.SocketFamily_INET6
		}
		return b
	}
	b.err = errors.New("not an ip address")
	return b
}
261003
func (h *Host) HTTPTransport() http.RoundTripper {
	if h.transport == nil {
		return http.DefaultTransport
	}
	return h.transport
}
731147
func NetworkHostsPorts(hpm [][]HostPort) [][]network.HostPort {
	nhpm := make([][]network.HostPort, len(hpm))
	for i, hps := range hpm {
		nhpm[i] = NetworkHostPorts(hps)
	}
	return nhpm
}
621702
func HostPortsByHost(hostports []string) (hostMap map[string][]string) {
	hostMap = make(map[string][]string)
	for _, hostport := range hostports {
		host := CaptureHost(hostport)
		if host != "" {
			hostMap[host] = append(hostMap[host], hostport)
		}
	}
	return
}
575772
func (w *pgWorker) apiServerHostPorts() map[string][]network.HostPort {
	servers := make(map[string][]network.HostPort)
	for _, m := range w.machineTrackers {
		hostPorts := network.AddressesWithPort(m.Addresses(), w.config.APIPort)
		if len(hostPorts) == 0 {
			continue
		}
		servers[m.Id()] = hostPorts
	}
	return servers
}
1262153
func SplitHostPort(addr string) (host string, port int, err error) {
	h, p, err := net.SplitHostPort(addr)
	if err != nil {
		return "", -1, err
	}
	if p == "" {
		return "", -1, &net.AddrError{Err: "missing port in address", Addr: addr}
	}

	pi, err := strconv.Atoi(p)
	if err != nil {
		return "", -1, err
	}
	return h, pi, nil
}
683827
func mustSplitHostPort(hostPort string) (host, port string) {
	host, port, err := net.SplitHostPort(hostPort)
	// Strip off IPv6 zone information.
	if i := strings.Index(host, "%"); i > -1 {
		host = host[:i]
	}
	logger.FatalIf(err, "Unable to split host port %s", hostPort)
	return host, port
}