Пример #1
0
// MaskToInt converts net.IPMask to integer.
// TODO Not strictly firewall method, maybe put in different place.
func MaskToInt(mask net.IPMask) (uint64, error) {
	var imask uint64
	m, err := strconv.ParseInt(mask.String(), 16, 64)
	imask = uint64(m)
	if err != nil {
		return 0, err
	}
	return imask, nil
}
Пример #2
0
func getHostOnlyNetwork(nets map[string]*hostOnlyNetwork, hostIP net.IP, netmask net.IPMask) *hostOnlyNetwork {
	for _, n := range nets {
		// Second part of this conditional handles a race where
		// VirtualBox returns us the incorrect netmask value for the
		// newly created interface.
		if hostIP.Equal(n.IPv4.IP) &&
			(netmask.String() == n.IPv4.Mask.String() || n.IPv4.Mask.String() == buggyNetmask) {
			return n
		}
	}

	return nil
}
Пример #3
0
func getHostOnlyNetwork(hostIP net.IP, netmask net.IPMask) (*hostOnlyNetwork, error) {
	nets, err := listHostOnlyNetworks()
	if err != nil {
		return nil, err
	}
	for _, n := range nets {
		if hostIP.Equal(n.IPv4.IP) &&
			netmask.String() == n.IPv4.Mask.String() {
			return n, nil
		}
	}
	return nil, nil
}
Пример #4
0
func getHostOnlyAdapter(nets map[string]*hostOnlyNetwork, hostIP net.IP, netmask net.IPMask) *hostOnlyNetwork {
	for _, n := range nets {
		// Second part of this conditional handles a race where
		// VirtualBox returns us the incorrect netmask value for the
		// newly created adapter.
		if hostIP.Equal(n.IPv4.IP) &&
			(netmask.String() == n.IPv4.Mask.String() || n.IPv4.Mask.String() == buggyNetmask) {
			log.Debugf("Found: %s", n.Name)
			return n
		}
	}

	log.Debug("Not found")
	return nil
}
Пример #5
0
// Sets the IP for the interface. Superuser authentication is required.
func (self IFConfig) SetIP(interfaceName string,
	ipAddress net.IP, netMask net.IPMask) error {
	logger.Debug("IFConfig: Setting the IP and Netmask")

	if !authorized() {
		return ErrAuthRequired
	}

	cmd := exec.Command("sudo", "ifconfig", interfaceName, ipAddress.String(),
		"netmask", netMask.String())
	logger.Debug("Command Start: %v", cmd.Args)
	out, err := cmd.CombinedOutput()
	if err != nil {
		logger.Error("Command Error: %v : %v", err, limitText(out))
		return err
	}
	logger.Debug("Command Return: %v", limitText(out))

	return nil
}