// RealIPAddress プランに応じて外部向けIPアドレスを返す
//
// Standard: IPAddress1
// Other: VirtualIPAddress
349661
func (v *VPCRouter) RealIPAddress(index int) (string, int) {
	if !v.HasInterfaces() {
		return "", -1
	}
	for i, nic := range v.Settings.Router.Interfaces {
		if i == index {
			if index > 0 && nic == nil {
				return "", -1
			}

			if index == 0 && v.IsStandardPlan() {
				return v.Interfaces[0].IPAddress, v.Interfaces[0].Switch.Subnet.NetworkMaskLen
			}

			nwMask := nic.NetworkMaskLen
			if index == 0 {
				nwMask = v.Interfaces[0].Switch.Subnet.NetworkMaskLen
			}

			if v.IsStandardPlan() {
				return nic.IPAddress[0], nwMask
			}
			return nic.VirtualIPAddress, nwMask
		}
	}
	return "", -1
}
1175973
func firstIPv4Addr(addrs []net.Addr) (net.IP, error) {
	for _, a := range addrs {
		if a.Network() != "ip+net" {
			continue
		}

		ip, _, err := net.ParseCIDR(a.String())
		if err != nil {
			return nil, err
		}

		// "If ip is not an IPv4 address, To4 returns nil."
		// Reference: http://golang.org/pkg/net/#IP.To4
		if ip4 := ip.To4(); ip4 != nil {
			return ip4, nil
		}
	}

	return nil, nil
}
814102
func IPAddrToSockaddr(addr *net.IPAddr) Sockaddr {
	return IPAndZoneToSockaddr(addr.IP, addr.Zone)
}
650910
func (g *Cloud) GetRegionAddressByIP(region, ipAddress string) (*compute.Address, error) {
	ctx, cancel := cloud.ContextWithCallTimeout()
	defer cancel()

	mc := newAddressMetricContext("list", region)
	addrs, err := g.c.Addresses().List(ctx, region, filter.Regexp("address", ipAddress))

	mc.Observe(err)
	if err != nil {
		return nil, err
	}

	if len(addrs) > 1 {
		klog.Warningf("More than one addresses matching the IP %q: %v", ipAddress, addrNames(addrs))
	}
	for _, addr := range addrs {
		if addr.Address == ipAddress {
			return addr, nil
		}
	}
	return nil, makeGoogleAPINotFoundError(fmt.Sprintf("Address with IP %q was not found in region %q", ipAddress, region))
}
780847
func myIpAddress() otto.Value {
	hostname, err := os.Hostname()

	if err != nil {
		return otto.UndefinedValue()
	}

	address := dnsResolve(hostname)

	if value, err := otto.ToValue(address); err == nil {
		return value
	}

	return otto.UndefinedValue()
}
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
}
1115377
func (s *NetworkInterface) SetIpv4Address(v string) *NetworkInterface {
	s.Ipv4Address = &v
	return s
}
1322697
func (s *Switch) GetDefaultIPAddressesForVPCRouter() (string, string, string, error) {

	if s.Subnets == nil || len(s.Subnets) < 1 {
		return "", "", "", fmt.Errorf("switch[%d].Subnets is nil", s.ID)
	}

	baseAddress := net.ParseIP(s.Subnets[0].IPAddresses.Min).To4()
	address1 := net.IPv4(baseAddress[0], baseAddress[1], baseAddress[2], baseAddress[3]+1)
	address2 := net.IPv4(baseAddress[0], baseAddress[1], baseAddress[2], baseAddress[3]+2)

	return baseAddress.String(), address1.String(), address2.String(), nil
}
931123
func (ipv4 IPv4Addr) NetworkAddress() IPv4Network {
	return IPv4Network(uint32(ipv4.Address) & uint32(ipv4.Mask))
}
234586
func (s *HealthCheckObservation) SetIPAddress(v string) *HealthCheckObservation {
	s.IPAddress = &v
	return s
}
271221
func GetIPAddress() (ip string, err error) {
	ip, err = getIPAddrFromOutGoingConnection()
	switch {
	case err != nil:
		return "", err
	case err == nil && strings.HasPrefix(ip, "127"):
		return "", fmt.Errorf("unable to identify local ip address")
	default:
		return ip, err
	}
}
1324297
func (s *MountTargetDescription) SetIpAddress(v string) *MountTargetDescription {
	s.IpAddress = &v
	return s
}
1149563
func (g *GuestInfo) IpAddress(vm *object.VirtualMachine) (string, error) {
	ctx := context.TODO()
	const any = "0.0.0.0"
	var mvm mo.VirtualMachine

	pc := property.DefaultCollector(g.c)
	err := pc.RetrieveOne(ctx, vm.Reference(), []string{"runtime.host", "config.uuid"}, &mvm)
	if err != nil {
		return "", err
	}

	h, err := g.hostInfo(mvm.Runtime.Host)
	if err != nil {
		return "", err
	}

	// Normalize uuid, esxcli and mo.VirtualMachine have different formats
	uuid := strings.Replace(mvm.Config.Uuid, "-", "", -1)

	if wid, ok := h.wids[uuid]; ok {
		res, err := h.Run([]string{"network", "vm", "port", "list", "--world-id", wid})
		if err != nil {
			return "", err
		}

		for _, val := range res.Values {
			if ip, ok := val["IPAddress"]; ok {
				if ip[0] != any {
					return ip[0], nil
				}
			}
		}
	}

	return any, nil
}
645251
func (s *Instance) SetIpAddress(v string) *Instance {
	s.IpAddress = &v
	return s
}
1177400
func (s *SetIpAddressTypeInput) SetIpAddressType(v string) *SetIpAddressTypeInput {
	s.IpAddressType = &v
	return s
}
1176888
func (internet Internet) MacAddress(v reflect.Value) (interface{}, error) {
	return internet.macAddress(), nil
}
988907
func (s *InstanceAccess) SetIpAddress(v string) *InstanceAccess {
	s.IpAddress = &v
	return s
}