// getOurIP returns a best guess at what the local IP is.
435255
func getOurIP() (ip string, err error) {
	hostname, err := os.Hostname()
	if err != nil {
		return
	}
	return net.LookupCNAME(hostname)
}
124359
func (pc peerConn) RemoteIP() net.IP {
	if pc.ip != nil {
		return pc.ip
	}

	host, _, err := net.SplitHostPort(pc.conn.RemoteAddr().String())
	if err != nil {
		panic(err)
	}

	ips, err := net.LookupIP(host)
	if err != nil {
		panic(err)
	}

	pc.ip = ips[0]

	return pc.ip
}
1024638
func RealIP(req *http.Request) string {
	ip, ok := req.Context().Value(realIPKey).(string)
	if !ok {
		// Fallback to a secure resolver.
		return DefaultResolver.RealIP(req)
	}
	return ip
}
1164896
func copyIP(src net.IP) net.IP {
	return net.IP(copyBytes(src))
}
1036198
func (c Context) ServerIP() string {
	addrs, err := networkInterfacesFn()
	if err != nil {
		return ""
	}

	for _, address := range addrs {
		// Validate the address and check if it's not a loopback
		if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil || ipnet.IP.To16() != nil {
				return ipnet.IP.String()
			}
		}
	}

	return ""
}
966226
func (mg *MailgunImpl) GetIP(ctx context.Context, ip string) (IPAddress, error) {
	r := newHTTPRequest(generatePublicApiUrl(mg, ipsEndpoint) + "/" + ip)
	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())
	var resp IPAddress
	err := getResponseFromJSON(ctx, r, &resp)
	return resp, err
}
251410
func GetIPFamily(ip net.IP) int {
	if len(ip) <= net.IPv4len {
		return FAMILY_V4
	}
	if ip.To4() != nil {
		return FAMILY_V4
	}
	return FAMILY_V6
}
660266
func (vm *VM) GetIPs() ([]net.IP, error) {
	s, err := vm.getService()
	if err != nil {
		return nil, err
	}

	return s.getIPs()
}
575046
func GetIpv6() (bool, error) {
	if initVersionError != nil {
		return false, initVersionError
	}
	if initContextError != nil {
		return false, initContextError
	}
	return defaultCtx.GetIpv6()
}
807780
func (fw *FirewallSSO) getSourceIp(ctx context.Context) net.IP {
	managementNetwork := pfconfigdriver.Config.Interfaces.ManagementNetwork

	if managementNetwork.Vip != "" {
		return net.ParseIP(managementNetwork.Vip)
	} else {
		return net.ParseIP(managementNetwork.Ip)
	}
}
542372
func (vm *VM) GetIPs() ([]net.IP, error) {
	var ips []net.IP
	if err := vm.Update(); err != nil {
		return nil, err
	}
	for _, ip := range vm.Droplet.Networks.V4 {
		ips = append(ips, net.ParseIP(ip.IPAddress))
	}
	for _, ip := range vm.Droplet.Networks.V6 {
		ips = append(ips, net.ParseIP(ip.IPAddress))
	}
	return ips, nil
}
343920
func getLocalIPs() (ips []string) {
	ips = make([]string, 0, 6)

	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return
	}

	for _, addr := range addrs {
		ip, _, err := net.ParseCIDR(addr.String())
		if err != nil {
			continue
		}
		ips = append(ips, ip.String())
	}
	return
}
530046
func (ip *Interpreter) get(args []string) {
	val, err := ip.Backend.GetUserData(args[0], args[1])
	if err == nil {
		ip.Write(val)
	}
	ip.simpleResponder(err)
}
611077
func GetPodIP(execer utilexec.Interface, nsenterPath, netnsPath, interfaceName string) (net.IP, error) {
	ip, err := getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, "-4")
	if err != nil {
		// Fall back to IPv6 address if no IPv4 address is present
		ip, err = getOnePodIP(execer, nsenterPath, netnsPath, interfaceName, "-6")
	}
	if err != nil {
		return nil, err
	}

	return ip, nil
}
1091351
func defaultIP(ips []net.IP) []net.IP {
	if len(ips) <= 1 {
		return ips
	}
	v6 := -1
	for i, ip := range ips {
		if ipLen := len(ip); ipLen == net.IPv4len {
			return ips[i : i+1]
		} else if v6 == -1 && ipLen == net.IPv6len {
			v6 = i
		}
	}
	if v6 == -1 {
		return nil // shouldn't ever happen
	}
	return ips[v6 : v6+1]
}
412186
func (f *Facade) GetHostByIP(ctx datastore.Context, hostIP string) (*host.Host, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.GetHostByIP"))
	return f.hostStore.GetHostByIP(ctx, hostIP)
}
778692
func RemoteIP(r *http.Request) string {
	addr := RemoteAddr(r)

	// Try parsing it as "IP:port"
	if ip, _, err := net.SplitHostPort(addr); err == nil {
		return ip
	}

	return addr
}