本文整理汇总了Golang中net.IPMask.String方法的典型用法代码示例。如果您正苦于以下问题:Golang IPMask.String方法的具体用法?Golang IPMask.String怎么用?Golang IPMask.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.IPMask
的用法示例。
在下文中一共展示了IPMask.String方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MaskToInt
// 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: getHostOnlyNetwork
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: getHostOnlyNetwork
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: getHostOnlyAdapter
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: SetIP
// 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
}