// When present, the IP address of the sender will be anonymized.
// For example, the IP will be anonymized if any of the following
// parameters are present in the payload: &aip=, &aip=0, or
// &aip=1
968460
func (h *Client) AnonymizeIP(anonymizeIP bool) *Client {
	h.anonymizeIP = anonymizeIP
	h.anonymizeIPSet = true
	return h
}
380507
func ParseIPWithPrefix(input string) (addr *net.IPNet, isIpv6 bool, err error) {
	defaultIpv4Mask := net.CIDRMask(32, 32)
	defaultIpv6Mask := net.CIDRMask(128, 128)

	hasPrefix := strings.Contains(input, "/")

	if hasPrefix {
		ip, network, err := net.ParseCIDR(input)
		if err != nil {
			return nil, false, err
		}
		network.IP = ip
		isIpv6, err = IsIPv6(ip.String())
		return network, isIpv6, err
	}

	// Ip prefix was not set
	ip := net.ParseIP(input)
	if ip == nil {
		return nil, false, fmt.Errorf("Unable to parse IP address: %v", input)
	}
	isIpv6, err = IsIPv6(ip.String())
	if err != nil {
		return
	}

	network := net.IPNet{}
	network.IP = ip
	if isIpv6 {
		network.Mask = defaultIpv6Mask
	} else {
		network.Mask = defaultIpv4Mask
	}
	return &network, isIpv6, nil
}
951889
func (c *Client) PrivateAddress(target string) (string, error) {
	var results params.PrivateAddressResults
	p := params.PrivateAddress{Target: target}
	err := c.facade.FacadeCall("PrivateAddress", p, &results)
	return results.PrivateAddress, err
}
835696
func IsOverlappingSubnetv6(inputIPv6Subnet string, existingIPv6Subnet string) bool {
	inputIPv6StartRange, inputIPv6EndRange := getIPv6Range(inputIPv6Subnet)
	existingIPv6StartRange, existingIPv6EndRange := getIPv6Range(existingIPv6Subnet)

	inputStartRange := ipv6ToBigint(inputIPv6StartRange)
	inputEndRange := ipv6ToBigint(inputIPv6EndRange)

	existingStartRange := ipv6ToBigint(existingIPv6StartRange)
	existingEndRange := ipv6ToBigint(existingIPv6EndRange)

	if (existingStartRange.Cmp(inputStartRange) <= 0 && inputStartRange.Cmp(existingEndRange) <= 0) ||
		(existingStartRange.Cmp(inputEndRange) <= 0 && inputEndRange.Cmp(existingEndRange) <= 0) {
		return true
	}

	if (inputStartRange.Cmp(existingStartRange) <= 0 && existingStartRange.Cmp(inputEndRange) <= 0) ||
		(inputStartRange.Cmp(existingEndRange) <= 0 && existingEndRange.Cmp(inputEndRange) <= 0) {
		return true
	}
	return false
}
892208
func (a *MandrillAPI) SenderInfo(address string) (SenderInfo, error) {
	var response SenderInfo
	if address == "" {
		return response, errors.New("address cannot be blank")
	}
	var params map[string]interface{} = make(map[string]interface{})
	params["address"] = address
	err := parseMandrillJson(a, senders_info_endpoint, params, &response)
	return response, err
}
106137
func (api UsersAPI) ValidateEmailAddress(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	label := mux.Vars(r)["label"]
	userMgr := user.NewManager(r)
	lang := r.FormValue("lang")
	if lang == "" {
		lang = organization.DefaultLanguage
	}
	userobj, err := userMgr.GetByName(username)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	email, err := userobj.GetEmailAddressByLabel(label)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	_, err = api.EmailAddressValidationService.RequestValidation(r, username, email.EmailAddress, fmt.Sprintf("https://%s/emailvalidation", r.Host), lang)
	w.WriteHeader(http.StatusNoContent)
}
158433
func IPv6() string {
	size := 16
	ip := make([]byte, size)
	for i := 0; i < size; i++ {
		ip[i] = byte(r.Intn(256))
	}
	return net.IP(ip).To16().String()
}
723389
func getIP(showAddress string) string {
	list := strings.SplitN(showAddress, ":", 2)
	if len(list) != 2 {
		return ""
	}
	return strings.TrimSpace(list[1])
}
806093
func (cidr CIDR) sanitize() (prefixLength int, err error) {
	strCIDR := string(cidr)
	if strCIDR == "" {
		return 0, fmt.Errorf("IP must be specified")
	}

	_, ipnet, err := net.ParseCIDR(strCIDR)
	if err == nil {
		var bits int
		prefixLength, bits = ipnet.Mask.Size()
		if prefixLength == 0 && bits == 0 {
			return 0, fmt.Errorf("CIDR cannot specify non-contiguous mask %s",
				ipnet.Mask.String())
		}
	} else {
		// Try to parse as a fully masked IP or an IP subnetwork
		ip := net.ParseIP(strCIDR)
		if ip == nil {
			return 0, fmt.Errorf("Unable to parse CIDR: %s", err)
		}
	}

	return prefixLength, nil
}
967298
func IsPrivateAddr(a ma.Multiaddr) bool {
	isPrivate := false
	ma.ForEach(a, func(c ma.Component) bool {
		switch c.Protocol().Code {
		case ma.P_IP6ZONE:
			return true
		default:
			return false
		case ma.P_IP4:
			isPrivate = inAddrRange(net.IP(c.RawValue()), Private4)
		case ma.P_IP6:
			isPrivate = inAddrRange(net.IP(c.RawValue()), Private6)
		}
		return false
	})
	return isPrivate
}
122567
func (client *Client) AllocateEipAddress(args *AllocateEipAddressArgs) (EipAddress string, AllocationId string, err error) {
	if args.Bandwidth == 0 {
		args.Bandwidth = 5
	}
	response := AllocateEipAddressResponse{}
	err = client.Invoke("AllocateEipAddress", args, &response)
	if err != nil {
		return "", "", err
	}
	return response.EipAddress, response.AllocationId, nil
}
701125
func AssertCertificateHasIPAddresses(t *testing.T, cert *x509.Certificate, IPAddresses ...net.IP) {
	for _, IPAddress := range IPAddresses {
		found := false
		for _, val := range cert.IPAddresses {
			if val.Equal(IPAddress) {
				found = true
				break
			}
		}

		if !found {
			t.Errorf("cert does not contain IPAddress %s", IPAddress)
		}
	}
}
544499
func flattenNetworkInterfacesPrivateIPAddresses(dtos []*ec2.NetworkInterfacePrivateIpAddress) []string {
	ips := make([]string, 0, len(dtos))
	for _, v := range dtos {
		ip := *v.PrivateIpAddress
		ips = append(ips, ip)
	}
	return ips
}
1902
func (internet Internet) IPv6(v reflect.Value) (interface{}, error) {
	return internet.ipv6(), nil
}
893883
func filterIp(ip string, captureIp captureIp) string {
	switch captureIp {
	case CaptureIpFull:
		return ip
	case CaptureIpAnonymize:
		if strings.Contains(ip, ".") {
			parts := strings.Split(ip, ".")
			parts[len(parts)-1] = "0"
			return strings.Join(parts, ".")
		}
		if strings.Contains(ip, ":") {
			parts := strings.Split(ip, ":")
			if len(parts) > 2 {
				parts = parts[0:3]
				parts = append(parts, "0000:0000:0000:0000:0000")
				return strings.Join(parts, ":")
			}
			return ip
		}
		return ip
	case CaptureIpNone:
		return ""
	default:
		return ""
	}
}
386609
func IdentityTranslator() AddressTranslator {
	return AddressTranslatorFunc(func(addr net.IP, port int) (net.IP, int) {
		return addr, port
	})
}
1158359
func (r *Resolver) RealIP(req *http.Request) string {
	var hdrRealIP string
	if r.XRealIp {
		hdrRealIP = req.Header.Get("X-Real-Ip")
	}

	var hdrForwardedFor string
	if r.XForwardedFor {
		hdrForwardedFor = req.Header.Get("X-Forwarded-For")
	}

	if len(hdrForwardedFor) == 0 && len(hdrRealIP) == 0 {
		return ipAddrFromRemoteAddr(req.RemoteAddr)
	}

	// X-Forwarded-For is potentially a list of addresses separated with ","
	forwarded := sort.StringSlice(strings.Split(hdrForwardedFor, ","))

	// This will ignore the X-Forwarded-For entries matching a load balancer
	// and use the first (from right to left) untrused address as the real
	// ip. This is done to prevent spoofing X-Forwarded-For.
	//
	// For example, let's say you wanted try to spoof your ip to make it
	// look like a request came from an office ip (204.28.121.211). You
	// would make a request like this:
	//
	//   curl https://www.example.com/debug -H "X-Forwarded-For: 204.28.121.211"
	//
	// The load balancer would then tag on the connecting ip, as well as the
	// ip address of the load balancer itself. The application would receive
	// an X-Forwarded-For header like the following:
	//
	//   "X-Forwarded-For": [
	//     "204.28.121.211, 49.228.250.246, 10.128.21.180"
	//   ]
	//
	// This will look at each ip from right to left, and use the first
	// "untrusted" address as the real ip.
	//
	// 1. The first ip, 10.128.21.180, is the loadbalancer ip address and is
	//    considered trusted because it's a LAN cidr.
	// 2. The second ip, 49.228.250.246, is untrusted, so this is determined to
	//    be the real ip address.
	//
	// By doing this, the spoofed ip (204.28.121.211) is ignored.
	reverse(forwarded)

	for _, addr := range forwarded {
		// return first non-local address
		addr = strings.TrimSpace(addr)
		if len(addr) > 0 && !isLocalAddress(addr) {
			return addr
		}
	}

	return hdrRealIP
}