// FromNetworkPort is a convenience helper to create a parameter
// out of the network type, here for Port.
960473
func FromNetworkPort(p corenetwork.Port) Port {
	return Port{
		Protocol: p.Protocol,
		Number:   p.Number,
	}
}
992080
func (fp *ForwardProxy) connectPortIsAllowed(port string) bool {
	portInt, err := strconv.Atoi(port)
	if err != nil {
		return false
	}
	if portInt <= 0 || portInt > 65535 {
		return false
	}
	if len(fp.whitelistedPorts) == 0 {
		return true
	}
	isAllowed := false
	for _, p := range fp.whitelistedPorts {
		if p == portInt {
			isAllowed = true
			break
		}
	}
	return isAllowed
}
144888
func (o *Subnet) CreateVPort(child *VPort) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
230116
func (t *TransportPort) FromString(s string) error {
	ps := strings.Split(s, "/")
	if len(ps) == 2 {
		t.Proto = ParseProtocol(ps[0])
		if p, err := strconv.ParseUint(ps[1], 10, 16); err == nil {
			t.Port = uint16(p)
			return nil
		}
	}
	return BadRequestErrorf("invalid format for transport port: %s", s)
}
695670
func (s *Service) GetPort(application, portAddr string) *servicedefinition.Port {
	if s.Endpoints != nil {
		//find the matching endpoint
		for i := range s.Endpoints {
			ep := &s.Endpoints[i]

			if ep.Application == application && ep.Purpose == "export" {
				portAddrLower := strings.ToLower(portAddr)
				for _, port := range ep.PortList {
					if strings.ToLower(port.PortAddr) == portAddrLower {
						return &port
					}
				}
			}
		}
	}

	return nil
}
1336400
func NewNSPort() *NSPort {

	return &NSPort{
		NATTraversal:    "NONE",
		VLANRange:       "0-4094",
		ShuntPort:       false,
		EnableNATProbes: true,
		Speed:           "AUTONEGOTIATE",
		TrafficThroughUBROnly: false,
		Mtu: 1500,
	}
}
859448
func findRequestedNodePort(port int, servicePorts []api.ServicePort) int {
	for i := range servicePorts {
		servicePort := servicePorts[i]
		if port == int(servicePort.Port) && servicePort.NodePort != 0 {
			return int(servicePort.NodePort)
		}
	}
	return 0
}
731147
func NetworkHostsPorts(hpm [][]HostPort) [][]network.HostPort {
	nhpm := make([][]network.HostPort, len(hpm))
	for i, hps := range hpm {
		nhpm[i] = NetworkHostPorts(hps)
	}
	return nhpm
}
1111797
func (service *VboxPortType) INetworkAdaptergetInternalNetwork(request *INetworkAdaptergetInternalNetwork) (*INetworkAdaptergetInternalNetworkResponse, error) {
	response := new(INetworkAdaptergetInternalNetworkResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
256003
func NewNetAddressIPPort(ip net.IP, port uint16) *NetAddress {
	return &NetAddress{
		IP:   ip,
		Port: port,
	}
}
427540
func (service *VboxPortType) INetworkAdaptersetNATNetwork(request *INetworkAdaptersetNATNetwork) (*INetworkAdaptersetNATNetworkResponse, error) {
	response := new(INetworkAdaptersetNATNetworkResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
1361642
func parsePort(network, port string) (int, error) {
	p, i, ok := dtoi(port, 0)
	if !ok || i != len(port) {
		var err error
		p, err = net.LookupPort(network, port)
		if err != nil {
			return 0, err
		}
	}
	if p < 0 || p > 0xFFFF {
		return 0, &net.AddrError{"invalid port", port}
	}
	return p, nil
}
1019160
func (service *VboxPortType) INATNetworkgetNetwork(request *INATNetworkgetNetwork) (*INATNetworkgetNetworkResponse, error) {
	response := new(INATNetworkgetNetworkResponse)
	err := service.client.Call("", request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
200523
func fromNetworkAddress(netAddr network.Address, origin Origin) address {
	return address{
		Value:       netAddr.Value,
		AddressType: string(netAddr.Type),
		Scope:       string(netAddr.Scope),
		Origin:      string(origin),
		SpaceName:   string(netAddr.SpaceName),
	}
}
170745
func (ns Networks) Port(label string) (string, int) {
	for _, n := range ns {
		for _, p := range n.ReservedPorts {
			if p.Label == label {
				return n.IP, p.Value
			}
		}
		for _, p := range n.DynamicPorts {
			if p.Label == label {
				return n.IP, p.Value
			}
		}
	}
	return "", 0
}
1220786
func (s *DeviceiSCSIAttributes) SetNetworkInterfacePort(v int64) *DeviceiSCSIAttributes {
	s.NetworkInterfacePort = &v
	return s
}
742421
func NetworkHostPorts(hps []HostPort) []network.HostPort {
	nhps := make([]network.HostPort, len(hps))
	for i, hp := range hps {
		nhps[i] = hp.NetworkHostPort()
	}
	return nhps
}