// HostSliceToNetwork converts b to the networking byte order.
167066
func HostSliceToNetwork(b []byte, t reflect.Kind) interface{} {
	switch t {
	case reflect.Uint32:
		if Native != binary.BigEndian {
			return binary.BigEndian.Uint32(reverse(b))
		}
		return binary.BigEndian.Uint32(b)
	case reflect.Uint16:
		if Native != binary.BigEndian {
			return binary.BigEndian.Uint16(reverse(b))
		}
		return binary.BigEndian.Uint16(b)
	default:
		panic(unsupported(t))
	}
}
619465
func isClientCertEnabledForHost(c *Client, host string) bool {
	_, hostSslKeyOk := c.uc.Get("http", fmt.Sprintf("https://%v/", host), "sslKey")
	_, hostSslCertOk := c.uc.Get("http", fmt.Sprintf("https://%v/", host), "sslCert")

	return hostSslKeyOk && hostSslCertOk
}
269431
func (s *BrocadeVCSService) ListBrocadeVcsDeviceNetworks(p *ListBrocadeVcsDeviceNetworksParams) (*ListBrocadeVcsDeviceNetworksResponse, error) {
	resp, err := s.cs.newRequest("listBrocadeVcsDeviceNetworks", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListBrocadeVcsDeviceNetworksResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
713400
func getEndpointInNetwork(name string, n libnetwork.Network) (libnetwork.Endpoint, error) {
	endpointName := strings.TrimPrefix(name, "/")
	return n.EndpointByName(endpointName)
}
1202459
func (m MiddlewareFunc) HostBegsWith(tests ...string) MiddlewareFunc {
	return func(h HandlerFunc) HandlerFunc {
		return func(c *Context) error {
			for _, test := range tests {
				if strings.HasPrefix(c.Request().URL().Host, test) {
					return m(h)(c)
				}
			}
			return h(c)
		}
	}
}
377234
func (c *Cluster) HostWithSerial(serial string) (*Host, bool) {
	if err := c.Update(); err != nil {
		c.logger.Log("level", "error", "message", "error getting the serial number using the internal cache", "stack", err)
		return nil, false
	}
	c.mu.Lock()
	defer c.mu.Unlock()

	if cached, exists := c.hostsCache[strings.ToLower(serial)]; exists {
		return cached.get(), true
	} else {
		return nil, false
	}
}
394161
func (s *TrainingJob) SetEnableNetworkIsolation(v bool) *TrainingJob {
	s.EnableNetworkIsolation = &v
	return s
}
43850
func (b BaseURL) HostURL() string {
	return strings.TrimSuffix(b.String(), b.Path())
}
1350504
func (tracerOptions) HostIPv4(hostIPv4 uint32) TracerOption {
	return func(tracer *Tracer) {
		tracer.hostIPv4 = hostIPv4
	}
}
1475
func (ncc *SeesawNCC) LBInterfaceInit(iface *ncctypes.LBInterface, out *int) error {
	netIface, err := iface.Interface()
	if err != nil {
		return fmt.Errorf("Failed to get network interface: %v", err)
	}
	nodeIface, err := net.InterfaceByName(iface.NodeInterface)
	if err != nil {
		return fmt.Errorf("Failed to get node interface: %v", err)
	}

	if iface.RoutingTableID < 1 || iface.RoutingTableID > 250 {
		return fmt.Errorf("Invalid routing table ID: %d", iface.RoutingTableID)
	}

	vmac, err := net.ParseMAC(vrrpMAC)
	if err != nil {
		return fmt.Errorf("Failed to parse VRRP MAC %q: %v", vrrpMAC, err)
	}

	// The last byte of the VRRP MAC is determined by the VRID.
	vmac[len(vmac)-1] = iface.VRID
	netIface.HardwareAddr = vmac

	log.Infof("Initialising load balancing interface %s - VRID %d (VMAC %s)", iface.Name, iface.VRID, vmac)

	// Ensure interface is down and set VMAC address.
	if err := ifaceFastDown(netIface); err != nil {
		return fmt.Errorf("Failed to down interface: %v", err)
	}
	if err := ifaceSetMAC(netIface); err != nil {
		return fmt.Errorf("Failed to set MAC: %v", err)
	}

	// Remove VLAN interfaces associated with the load balancing interface.
	if err := ifaceFlushVLANs(netIface); err != nil {
		return fmt.Errorf("Failed to flush VLAN interfaces: %v", err)
	}

	// Configure sysctls for load balancing.
	if err := sysctlInitLB(nodeIface, netIface); err != nil {
		return fmt.Errorf("Failed to initialise sysctls: %v", err)
	}

	// Flush existing IP addresses and add cluster VIPs.
	if err := ifaceFlushIPAddr(netIface); err != nil {
		return fmt.Errorf("Failed to flush IP addresses: %v", err)
	}

	if iface.ClusterVIP.IPv4Addr != nil {
		if err := addClusterVIP(iface, netIface, nodeIface, iface.ClusterVIP.IPv4Addr); err != nil {
			return fmt.Errorf("Failed to add IPv4 cluster VIP: %v", err)
		}
	}
	if iface.ClusterVIP.IPv6Addr != nil {
		if err := addClusterVIP(iface, netIface, nodeIface, iface.ClusterVIP.IPv6Addr); err != nil {
			return fmt.Errorf("Failed to add IPv6 cluster VIP: %v", err)
		}
	}

	// Initialise iptables rules.
	if err := iptablesInit(iface.ClusterVIP); err != nil {
		return err
	}

	// Setup dummy interface.
	dummyIface, err := net.InterfaceByName(iface.DummyInterface)
	if err != nil {
		return fmt.Errorf("Failed to get dummy interface: %v", err)
	}
	if err := ifaceFastDown(dummyIface); err != nil {
		return fmt.Errorf("Failed to down dummy interface: %v", err)
	}
	if err := ifaceFlushIPAddr(dummyIface); err != nil {
		return fmt.Errorf("Failed to flush dummy interface: %v", err)
	}
	if err := ifaceUp(dummyIface); err != nil {
		return fmt.Errorf("Failed to up dummy interface: %v", err)
	}

	return nil
}
822847
func SplitNetworkInTwo(network *net.IPNet) (*net.IPNet, *net.IPNet) {
	size, _ := network.Mask.Size()
	newMask := net.CIDRMask(size+1, 8*len(network.IP))

	ip2 := SliceSetOne(net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, uint(size))
	ip2 = SliceOr(network.IP, ip2)

	return &net.IPNet{IP: network.IP, Mask: newMask}, &net.IPNet{IP: ip2, Mask: newMask}
}
889860
func isNetworkOrHostDown(err error) bool {
	if err == nil {
		return false
	}
	switch err.(type) {
	case *net.DNSError, *net.OpError, net.UnknownNetworkError:
		return true
	case *url.Error:
		// For a URL error, where it replies back "connection closed"
		if strings.Contains(err.Error(), "Connection closed by foreign host") {
			return true
		}
		return true
	default:
		if strings.Contains(err.Error(), "net/http: TLS handshake timeout") {
			// If error is - tlsHandshakeTimeoutError,.
			return true
		} else if strings.Contains(err.Error(), "i/o timeout") {
			// If error is - tcp timeoutError.
			return true
		} else if strings.Contains(err.Error(), "connection timed out") {
			// If err is a net.Dial timeout.
			return true
		} else if strings.Contains(err.Error(), "net/http: HTTP/1.x transport connection broken") {
			return true
		}
	}
	return false
}
1318372
func (s *NetworkService) GetNetscalerLoadBalancerNetworkID(keyword string, lbdeviceid string, opts ...OptionFunc) (string, int, error) {
	p := &ListNetscalerLoadBalancerNetworksParams{}
	p.p = make(map[string]interface{})

	p.p["keyword"] = keyword
	p.p["lbdeviceid"] = lbdeviceid

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return "", -1, err
		}
	}

	l, err := s.ListNetscalerLoadBalancerNetworks(p)
	if err != nil {
		return "", -1, err
	}

	if l.Count == 0 {
		return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l)
	}

	if l.Count == 1 {
		return l.NetscalerLoadBalancerNetworks[0].Id, l.Count, nil
	}

	if l.Count > 1 {
		for _, v := range l.NetscalerLoadBalancerNetworks {
			if v.Name == keyword {
				return v.Id, l.Count, nil
			}
		}
	}
	return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l)
}
734149
func (c *Cluster) HostWithInternalAddr(ipAddr net.IP) (*Host, bool) {
	if err := c.Update(); err != nil {
		c.logger.Log("level", "error", "message", "error getting the ip address using the internal cache", "stack", err)
		return nil, false
	}
	c.mu.Lock()
	defer c.mu.Unlock()

	if cached, exists := c.hostByInternalAddr[ipAddr.String()]; exists {
		return cached.get(), true
	} else {
		return nil, false
	}
}
1348833
func (h *Host) IPv4Net() *net.IPNet {
	return &net.IPNet{IP: h.IPv4Addr, Mask: h.IPv4Mask}
}
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")
}
68346
func (a *AddrManager) HostToNetAddress(host string, port uint16, services wire.ServiceFlag) (*wire.NetAddress, error) {
	// Tor address is 16 char base32 + ".onion"
	var ip net.IP
	if len(host) == 22 && host[16:] == ".onion" {
		// go base32 encoding uses capitals (as does the rfc
		// but Tor and bitcoind tend to user lowercase, so we switch
		// case here.
		data, err := base32.StdEncoding.DecodeString(
			strings.ToUpper(host[:16]))
		if err != nil {
			return nil, err
		}
		prefix := []byte{0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43}
		ip = net.IP(append(prefix, data...))
	} else if ip = net.ParseIP(host); ip == nil {
		ips, err := a.lookupFunc(host)
		if err != nil {
			return nil, err
		}
		if len(ips) == 0 {
			return nil, fmt.Errorf("no addresses found for %s", host)
		}
		ip = ips[0]
	}

	return wire.NewNetAddressIPPort(ip, port, services), nil
}