Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Inspect = func(addr string) (*Parameters, error) { ip, network, err := ParseAddr(addr) if err != nil { return nil, err } n := &Parameters{} ifParams, ifNet, err := lookupInInterfaces(ip) if err != nil { return nil, err } if ifNet != nil { network = ifNet n = ifParams } if network == nil { ipnet := &net.IPNet{ IP: ip, Mask: ip.DefaultMask(), } _, network, err = net.ParseCIDR(ipnet.String()) if err != nil { return nil, fmt.Errorf("failed determining address of network from %s: %w", addr, err) } } n.IP = network.IP.String() n.Netmask = net.IP(network.Mask).String() n.Prefix, _ = network.Mask.Size() n.CIDR = network.String() n.IsPrivate = network.IP.IsPrivate() networkIP := binary.BigEndian.Uint32(network.IP) networkMask := binary.BigEndian.Uint32(network.Mask) broadcastIP := (networkIP & networkMask) | (networkMask ^ 0xffffffff) broadcast := make(net.IP, 4) binary.BigEndian.PutUint32(broadcast, broadcastIP) n.Broadcast = broadcast.String() gateway := net.ParseIP(n.Gateway).To4() if gateway == nil { gateway = make(net.IP, 4) binary.BigEndian.PutUint32(gateway, networkIP+1) n.Gateway = gateway.String() } gatewayIP := binary.BigEndian.Uint32(gateway) min := make(net.IP, 4) binary.BigEndian.PutUint32(min, gatewayIP+1) n.ClientMin = min.String() max := make(net.IP, 4) binary.BigEndian.PutUint32(max, broadcastIP-1) n.ClientMax = max.String() return n, nil }
Inspect initialises IPv4 network parameters struct from given address addr. addr can be single address (like "192.168.17.42"), network address (like "192.168.17.0") or in CIDR form (like "192.168.17.42/24 or "192.168.17.0/24"). If addr belongs to network of local network interface, parameters will also contain info about that network interface.
Functions ¶
func IsBuiltinQEMU ¶ added in v1.30.0
IsBuiltinQEMU returns if network is builtin or the legacy value user.
Types ¶
type Parameters ¶
type Parameters struct { IP string // IP address of network Netmask string // dotted-decimal format ('a.b.c.d') Prefix int // network prefix length (number of leading ones in network mask) CIDR string // CIDR format ('a.b.c.d/n') Gateway string // taken from network interface address or assumed as first network IP address from given addr ClientMin string // first available client IP address after gateway ClientMax string // last available client IP address before broadcast Broadcast string // last network IP address IsPrivate bool // whether the IP is private or not Interface // contains filtered or unexported fields }
Parameters contains main network parameters.
func FreeSubnet ¶
func FreeSubnet(startSubnet string, step, tries int) (*Parameters, error)
FreeSubnet will try to find free private network beginning with startSubnet, incrementing it in steps up to number of tries.
Click to show internal directories.
Click to hide internal directories.