Documentation ¶
Index ¶
- Constants
- Variables
- func ValidIPV4(ipBytes []byte) bool
- type ByIPRanges
- type IPAddress
- func (ip *IPAddress) Equal(other *IPAddress) bool
- func (ip *IPAddress) GreaterThan(other *IPAddress) bool
- func (ip *IPAddress) GreaterThanOrEqual(other *IPAddress) bool
- func (ip *IPAddress) Increment(val *IPNumber) (*IPAddress, error)
- func (ip *IPAddress) LessThan(other *IPAddress) bool
- func (ip *IPAddress) LessThanOrEqual(other *IPAddress) bool
- func (ip *IPAddress) String() string
- func (ip *IPAddress) ToInt() *IPNumber
- func (ip *IPAddress) Version() *Version
- type IPMask
- type IPNetwork
- func (nw *IPNetwork) ContainsAddress(addr *IPAddress) bool
- func (nw *IPNetwork) ContainsSubnetwork(other *IPNetwork) bool
- func (nw *IPNetwork) Equal(other *IPNetwork) bool
- func (nw *IPNetwork) First() *IPAddress
- func (nw *IPNetwork) Last() *IPAddress
- func (nw *IPNetwork) Length() *IPNumber
- func (nw *IPNetwork) LessThan(other *IPNetwork) bool
- func (nw *IPNetwork) Partition(exclude *IPNetwork) *Partition
- func (nw *IPNetwork) PrefixLength() *IPNumber
- func (nw *IPNetwork) String() string
- func (nw *IPNetwork) Subnet(newCIDRPrefix int) ([]*IPNetwork, error)
- type IPNumber
- func (num *IPNumber) Add(v *IPNumber) *IPNumber
- func (num *IPNumber) And(v *IPNumber) *IPNumber
- func (num *IPNumber) Equal(other *IPNumber) bool
- func (num *IPNumber) Exp(v *IPNumber) *IPNumber
- func (num *IPNumber) GreaterThan(other *IPNumber) bool
- func (num *IPNumber) GreaterThanOrEqual(other *IPNumber) bool
- func (num *IPNumber) LessThan(other *IPNumber) bool
- func (num *IPNumber) LessThanOrEqual(other *IPNumber) bool
- func (num *IPNumber) Lsh(v uint) *IPNumber
- func (num *IPNumber) Neg() *IPNumber
- func (num *IPNumber) Sub(v *IPNumber) *IPNumber
- func (num *IPNumber) ToIPAddress() *IPAddress
- type IPRange
- type IPSet
- type Partition
- type Version
Constants ¶
const ( // IP address lengths (bytes). IPv4len = 4 IPv6len = 16 )
Variables ¶
var ( IPv4 = &Version{ number: 4, length: 4, bitLength: IPv4len * 8, max: &IPNumber{ Int: (&big.Int{}).Sub((&big.Int{}).Exp(big.NewInt(2), big.NewInt(32), nil), big.NewInt(1)), }, } IPv6 = &Version{ number: 6, length: 16, bitLength: IPv6len * 8, max: &IPNumber{ Int: (&big.Int{}).Sub((&big.Int{}).Exp(big.NewInt(2), big.NewInt(128), nil), big.NewInt(1)), }, } )
var (
ErrorAddressOutOFBounds = fmt.Errorf("ip number out range of ip-version boundary")
)
Functions ¶
Types ¶
type ByIPRanges ¶
type ByIPRanges []IPRange
Implements sort.Interface for sorting IPRange
func (ByIPRanges) Len ¶
func (rs ByIPRanges) Len() int
func (ByIPRanges) Less ¶
func (rs ByIPRanges) Less(i, j int) bool
func (ByIPRanges) Swap ¶
func (rs ByIPRanges) Swap(i, j int)
type IPAddress ¶
func MinAddress ¶
func (*IPAddress) GreaterThan ¶
func (*IPAddress) GreaterThanOrEqual ¶
func (*IPAddress) Increment ¶
Increment increments the IPAddress by an amount, val, which is of big.Int type.
func (*IPAddress) LessThanOrEqual ¶
type IPMask ¶
type IPNetwork ¶
type IPNetwork struct { Mask *IPMask // contains filtered or unexported fields }
IPNetwork defines an IPAddress network, including version and mask.
func IPRangeToCIDRS ¶
func NewIPNetwork ¶
func (*IPNetwork) ContainsAddress ¶
func (*IPNetwork) ContainsSubnetwork ¶
func (*IPNetwork) PrefixLength ¶
type IPNumber ¶
IPNumber is the integer representation of an IP address
func NewIPNumber ¶
NewIPNumber returns an IPNumber for the passed number.
func (*IPNumber) GreaterThan ¶
GreaterThan compares two IPNumbers, returning true when num is greater than other.
func (*IPNumber) GreaterThanOrEqual ¶
GreaterThanOrEqual compares two IPNumbers, returning true when num is greater than or equal to other.
func (*IPNumber) LessThanOrEqual ¶
func (*IPNumber) ToIPAddress ¶
ToIPAddress convers the given IPNumber object to an IPAddress.
type IPSet ¶
type IPSet []*IPNetwork
IPSet represents an unordered collection of unique IP addresses and subnets. IPAddresses are represented here as iPNetworks with a mask of /32