// IP returns the destination IP address for a given address family.
5441
func (d *Destination) IP(af AF) net.IP {
	switch af {
	case IPv4:
		return d.Backend.IPv4Addr
	case IPv6:
		return d.Backend.IPv6Addr
	}
	return nil
}
1308645
func NewIP(nip net.IP) IP {
	var ip IP
	copy(ip[:], nip.To16())
	return ip
}
1352966
func (n *Node) Address() string {
	if n.address == "" {
		n.address = nodeAddressString(n.ip, n.port)
	}

	return n.address
}
1117385
func IPDiff(ip, ip2 net.IP) int {
	ip, ip2 = makeNilZero(ip, ip2)
	ip, ip2 = makeSameLength(ip, ip2)
	o := 1
	if IPBefore(ip, ip2) {
		ip, ip2 = ip2, ip
		o = -1
	}
	ri := 0
	il := len(ip) - 1 // last element in ip
	for i := range ip {
		r := il - i // loop in reverse order
		ri = ri + ((int(ip[r] - ip2[r])) << (uint(8*i) & 0xff))
	}
	return ri * o
}
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
}
39968
func RemoteIP(ipLookups []string, r engine.Request) string {

	for _, lookup := range ipLookups {
		if lookup == "RemoteAddr" {
			return ipAddrFromRemoteAddr(r.RemoteAddress())
		}
		if lookup == "X-Forwarded-For" {
			if forwardedFor := r.Header().Get("X-Forwarded-For"); len(forwardedFor) > 0 {
				// X-Forwarded-For is potentially a list of addresses separated with ","
				return strings.TrimSpace(strings.SplitN(forwardedFor, ",", 2)[0])
			}
		}
		if lookup == "X-Real-IP" {
			if realIP := r.Header().Get("X-Real-IP"); len(realIP) > 0 {
				return realIP
			}
		}
	}

	return ""
}
999384
func (r *Request) IP() string {
	ip, _, err := net.SplitHostPort(r.W.RemoteAddr().String())
	if err != nil {
		return r.W.RemoteAddr().String()
	}
	return ip
}
640175
func interfaceByIP(ip string) (string, int, error) {
	ifaces, err := netInterfaces()
	if err != nil {
		return "", 0, err
	}

	for _, iface := range ifaces {
		ifaceIP, mask, err := ipByInterface(iface.Name)
		if err == nil && ip == ifaceIP {
			return iface.Name, mask, nil
		}
	}

	return "", 0, fmt.Errorf("no matching interface found for IP %s", ip)
}
663078
func (k EndpointKey) ToIP() net.IP {
	switch k.Family {
	case EndpointKeyIPv4:
		return k.IP[:4]
	case EndpointKeyIPv6:
		return k.IP[:]
	}
	return nil
}
998047
func IsIP(ip string) bool {
	if m, _ := regexp.MatchString(ipRegexp, ip); !m {
		return false
	}

	return true
}
46121
func (c *Client) IPs() (IPAddrs, error) {
	resp, err := c.Get("/public-ip-list", nil)
	if err != nil {
		return nil, err
	}

	var m map[string][]string
	if err := decodeJSON(&m, resp.Body); err != nil {
		return nil, err
	}
	return IPAddrs(m["addresses"]), nil
}
919538
func (c *CIDR) FirstIP() net.IP {
	var ip net.IP
	for ip = IncIP(c.ip.Mask(c.ipnet.Mask)); c.ipnet.Contains(ip); IncIP(ip) {
		break
	}
	return ip
}
1184449
func (r *Request) Family() int {
	var a net.IP
	ip := r.W.RemoteAddr()
	if i, ok := ip.(*net.UDPAddr); ok {
		a = i.IP
	}
	if i, ok := ip.(*net.TCPAddr); ok {
		a = i.IP
	}

	if a.To4() != nil {
		return 1
	}
	return 2
}
15276
func (h *HTTPBin) IP(w http.ResponseWriter, r *http.Request) {
	body, _ := json.Marshal(&ipResponse{
		Origin: getOrigin(r),
	})
	writeJSON(w, body, http.StatusOK)
}
1193
func (b IPv6) DestinationAddress() tcpip.Address {
	return tcpip.Address(b[v6DstAddr : v6DstAddr+IPv6AddressSize])
}
1136627
func (ctx *Context) IP() string {
	proxy := []string{}
	if ips := ctx.Req().Header.Get("X-Forwarded-For"); ips != "" {
		proxy = strings.Split(ips, ",")
	}
	if len(proxy) > 0 && proxy[0] != "" {
		return proxy[0]
	}
	ip := strings.Split(ctx.Req().RemoteAddr, ":")
	if len(ip) > 0 {
		if ip[0] != "[" {
			return ip[0]
		}
	}
	return "127.0.0.1"
}
125424
func (vm VirtualMachine) IP() *net.IP {
	nic := vm.DefaultNic()
	if nic != nil {
		ip := nic.IPAddress
		return &ip
	}

	return nil
}