ipv4cidr

package
v0.0.0-...-14a808c Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: MIT Imports: 6 Imported by: 0

README

IPv4 CIDR Manager

The package IPv4CIDR contains utilities to perform the following operations:

  1. Parse a string representing the CIDR block
    • Take a single IP address as input
    • Take a CIDR block in a standard notation where the IP part of the IP/CIDR range is the first IP address in the CIDR block
    • Take a non-standard CIDR block and enable a standardize flag to convert it to the standard notation
  2. Split the CIDR block into two halves
  3. Get the following information from the CIDR block
    • Convert to string
    • Get the IP part of the block representation
    • Get the CIDR mask part of the block representation
    • Get the nth IP address in range
    • Get the netmask
    • Get the size of the CIDR block

To Use

Import the package into your code using:

import "github.com/microsoft/go-cidr-manager/ipv4cidr"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPv4CIDR

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

IPv4CIDR models an IPv4 CIDR range. @field ip uint32: Holds the IP address @field mask uint8: Holds the CIDR mask @field netmask uint32: Holds the netmask for the subnet @field rangeLength uint32: Holds the number of IP addresses in the CIDR range

func NewIPv4CIDR

func NewIPv4CIDR(IP string, standardize bool) (*IPv4CIDR, error)

NewIPv4CIDR instantiates a new IPv4CIDR object and returns it @param IP string: A string representation of CIDR range in the format a.b.c.d/e or a.b.c.d @param standardize bool: If the IP part of the CIDR range is not the first IP in range, then setting this value to "true" will automatically convert it to the first IP in range. If set to "false", a non-standard CIDR will give an error @returns *IPv4CIDR: If the input parameters are valid, returns a pointer to a new IPv4CIDR object @returns error: If the input parameters are invalid, or any processing errors occur, returns the appropriate error back to caller.

func (*IPv4CIDR) GetCIDRRangeLength

func (i *IPv4CIDR) GetCIDRRangeLength() uint32

GetCIDRRangeLength returns the number of IP addresses contained in the CIDR range @returns uint32: Length of the CIDR range

func (*IPv4CIDR) GetIP

func (i *IPv4CIDR) GetIP() string

GetIP returns the IP part of the CIDR range @returns string: String corresponding to the first IP address in CIDR range in format a.b.c.d

func (*IPv4CIDR) GetIPInRange

func (i *IPv4CIDR) GetIPInRange(n uint32, withCIDR bool) (string, error)

GetIPInRange returns the nth IP address in the CIDR block @input n uint32: The value of n, representing the nth IP to return @input withCIDR bool: Flag corresponding to whether to append the CIDR mask with the returned IP or not @returns string: The nth IP address @returns error: If nth IP is out of range of the CIDR block, an error is returned

func (*IPv4CIDR) GetMask

func (i *IPv4CIDR) GetMask() uint8

GetMask returns the mask part of the CIDR range (0-32) @returns uint8: Mask of the CIDR range

func (*IPv4CIDR) GetNetmask

func (i *IPv4CIDR) GetNetmask() string

GetNetmask returns the netmask for the CIDR range @returns string: Netmask of the CIDR range

func (*IPv4CIDR) Split

func (i *IPv4CIDR) Split() (*IPv4CIDR, *IPv4CIDR, error)

Split splits the IPv4CIDR into two IPv4CIDRs of half the size (mask + 1) @returns *IPv4CIDR: The first (lower) block @returns *IPv4CIDR: The second (higher) block @returns error: If CIDR cannot be split further, the appropriate error is returned.

func (*IPv4CIDR) ToString

func (i *IPv4CIDR) ToString() string

ToString converts the IP into its string representation @returns string: String corresponding to the IP address in format a.b.c.d

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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