cidr

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cidr calculates CIDR network

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AscSortCIDRs

func AscSortCIDRs(cs []*CIDR)

AscSortCIDRs sort cidr slice order by ip,mask asc

func Compare

func Compare(a, b net.IP) int

Compare returns an integer comparing two ip The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func CompareCIDR

func CompareCIDR(a, b *CIDR) int

CompareCIDR returns an integer comparing two CIDR The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func DecrIP

func DecrIP(ip net.IP)

DecrIP ip decrease

func DescSortCIDRs

func DescSortCIDRs(cs []*CIDR)

DescSortCIDRs sort cidr slice order by ip,mask desc

func IncrIP

func IncrIP(ip net.IP)

IncrIP ip increase

Types

type CIDR

type CIDR struct {
	// contains filtered or unexported fields
}

CIDR https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing

func ParseCIDR

func ParseCIDR(s string) (*CIDR, error)

ParseCIDR parses s as a CIDR notation IP address and mask length, like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291

func SuperNetting

func SuperNetting(ns []string) (*CIDR, error)

SuperNetting merge network segments, must be contiguous

func (CIDR) Broadcast

func (c CIDR) Broadcast() string

Broadcast returns broadcast of the CIDR

func (CIDR) CIDR

func (c CIDR) CIDR() string

CIDR returns the CIDR string. If the IP prefix of the input CIDR string is inaccurate, it returns the string which be corrected by the mask length. For example, "192.0.2.10/24" return "192.0.2.0/24"

func (CIDR) Contains

func (c CIDR) Contains(ip string) bool

Contains reports whether the CIDR includes ip

func (CIDR) Equal

func (c CIDR) Equal(ns string) bool

Equal reports whether cidr and ns are the same CIDR

func (CIDR) ForEachIP

func (c CIDR) ForEachIP(iterator func(ip string) error) error

ForEachIP iterate through each ip in the CIDR

func (CIDR) ForEachIPBeginWith

func (c CIDR) ForEachIPBeginWith(beginIP string, iterator func(ip string) error) error

ForEachIPBeginWith begin with specified ip, iterate through each ip in the CIDR

func (CIDR) IP

func (c CIDR) IP() string

IP returns the original IP prefix of the input CIDR

func (CIDR) IPCount

func (c CIDR) IPCount() *big.Int

IPCount returns ip total of the CIDR

func (CIDR) IPRange

func (c CIDR) IPRange() (begin, end string)

IPRange returns begin and end ip of the CIDR

func (CIDR) IsIPv4

func (c CIDR) IsIPv4() bool

IsIPv4 reports whether the CIDR is IPv4

func (CIDR) IsIPv6

func (c CIDR) IsIPv6() bool

IsIPv6 reports whether the CIDR is IPv6

func (CIDR) Mask

func (c CIDR) Mask() string

Mask returns mask of the CIDR

func (CIDR) MaskSize

func (c CIDR) MaskSize() (ones, bits int)

MaskSize returns the number of leading ones and total bits in the CIDR mask

func (CIDR) Network

func (c CIDR) Network() string

Network returns network of the CIDR

func (CIDR) String

func (c CIDR) String() string

String returns the CIDR string. If the IP prefix of the input CIDR string is inaccurate, it returns the string which be corrected by the mask length. For example, "192.0.2.10/24" return "192.0.2.0/24"

func (CIDR) SubNetting

func (c CIDR) SubNetting(method, num int) ([]*CIDR, error)

SubNetting split network segment based on the number of hosts or subnets

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL