// RouteDefaultIPv4 returns the default route for IPv4 traffic.
346502
func (ncc *SeesawNCC) RouteDefaultIPv4(unused int, gateway *net.IP) error {
	ip, err := routeDefaultIPv4()
	if err != nil {
		return err
	}
	if gateway != nil {
		*gateway = make(net.IP, len(ip))
		copy(*gateway, ip)
	}
	return nil
}
178114
func (ri routeInfo) GetDefaultInterfaceName() (string, error) {
	ifNameOut, err := exec.Command(cmds["netstat"][0], cmds["netstat"][1:]...).Output()
	if err != nil {
		return "", err
	}

	ipconfigOut, err := exec.Command(cmds["ipconfig"][0], cmds["ipconfig"][1:]...).Output()
	if err != nil {
		return "", err
	}

	ifName, err := parseDefaultIfNameWindows(string(ifNameOut), string(ipconfigOut))
	if err != nil {
		return "", err
	}

	return ifName, nil
}
1309557
func parseDefaultIfNameFromRoute(routeOut string) (string, error) {
	lines := strings.Split(routeOut, "\n")
	for _, line := range lines {
		kvs := strings.SplitN(line, ":", 2)
		if len(kvs) != 2 {
			continue
		}

		if strings.TrimSpace(kvs[0]) == "interface" {
			ifName := strings.TrimSpace(kvs[1])
			return ifName, nil
		}
	}

	return "", errors.New("No default interface found")
}
476371
func (s *NATService) NewCreateIpForwardingRuleParams(ipaddressid string, protocol string, startport int) *CreateIpForwardingRuleParams {
	p := &CreateIpForwardingRuleParams{}
	p.p = make(map[string]interface{})
	p.p["ipaddressid"] = ipaddressid
	p.p["protocol"] = protocol
	p.p["startport"] = startport
	return p
}
105883
func defaultRouteParams(a *design.ActionDefinition) *design.AttributeDefinition {
	r := a.Routes[0]
	params := r.Params()
	o := make(design.Object, len(params))
	nz := make(map[string]bool, len(params))
	pparams := a.PathParams()
	for _, p := range params {
		o[p] = pparams.Type.ToObject()[p]
		nz[p] = true
	}
	return &design.AttributeDefinition{Type: o, NonZeroAttributes: nz}
}
153168
func (s *CreateStageOutput) SetDefaultRouteSettings(v *RouteSettings) *CreateStageOutput {
	s.DefaultRouteSettings = v
	return s
}
214079
func (_class VIFClass) GetIpv4ConfigurationMode(sessionID SessionRef, self VIFRef) (_retval VifIpv4ConfigurationMode, _err error) {
	_method := "VIF.get_ipv4_configuration_mode"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVIFRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertEnumVifIpv4ConfigurationModeToGo(_method + " -> ", _result.Value)
	return
}
439847
func DefaultIP() string {
	addrs, err := netInterfaceAddrs()
	if err == nil {
		for _, addr := range addrs {
			if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
				if ip.IP.To4() != nil {
					return ip.IP.String()
				}
			}
		}
	}

	return ""
}
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
}
6199
func DecimalToIPv4(addr uint32) net.IP {
	bytes := make([]byte, 4)
	binary.BigEndian.PutUint32(bytes, addr)
	return net.IP(bytes)
}
369564
func (s *NATService) GetIpForwardingRuleByID(id string, opts ...OptionFunc) (*IpForwardingRule, int, error) {
	p := &ListIpForwardingRulesParams{}
	p.p = make(map[string]interface{})

	p.p["id"] = id

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

	l, err := s.ListIpForwardingRules(p)
	if err != nil {
		if strings.Contains(err.Error(), fmt.Sprintf(
			"Invalid parameter id value=%s due to incorrect long value format, "+
				"or entity does not exist", id)) {
			return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
		}
		return nil, -1, err
	}

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

	if l.Count == 1 {
		return l.IpForwardingRules[0], l.Count, nil
	}
	return nil, l.Count, fmt.Errorf("There is more then one result for IpForwardingRule UUID: %s!", id)
}
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]
}
735742
func (ipv4 IPv4Addr) NetIPMask() *net.IPMask {
	ipv4Mask := net.IPMask{}
	ipv4Mask = make(net.IPMask, IPv4len)
	binary.BigEndian.PutUint32(ipv4Mask, uint32(ipv4.Mask))
	return &ipv4Mask
}
695652
func IPRangeFromIP(ip net.IP) IPRange {
	return IPRange{Start: ip, End: ip}
}
1259757
func (ri routeInfo) GetDefaultInterfaceName() (string, error) {
	out, err := exec.Command(ri.cmds["ip"][0], ri.cmds["ip"][1:]...).Output()
	if err != nil {
		return "", err
	}

	var ifName string
	if ifName, err = parseDefaultIfNameFromIPCmd(string(out)); err != nil {
		return "", errors.New("No default interface found")
	}
	return ifName, nil
}
1262880
func ConvertIPv4InIPv6Network(network, ip string) (*net.IPNet, error) {
	// parse original network
	_, pNet1, err := net.ParseCIDR(network)
	if err != nil {
		return nil, err
	}

	// create an empty network
	_, pNet2, err := net.ParseCIDR("0::/63")
	if err != nil {
		return nil, err
	}

	// set 2 last bytes in new network
	ip2 := net.ParseIP(ip)
	pNet2.IP[0] = ip2[14]
	pNet2.IP[1] = ip2[15]

	// we shift network to follow the first ip
	shift, _ := pNet1.Mask.Size()
	pNet2.IP = SliceShiftRight(pNet2.IP, uint(shift))

	// return the OR of joined network
	return IPNetOr(pNet1, pNet2), nil
}
1338576
func IPv4() string {
	size := 4
	ip := make([]byte, size)
	for i := 0; i < size; i++ {
		ip[i] = byte(r.Intn(256))
	}
	return net.IP(ip).To4().String()
}