IP address and prefix types.
This module provides definitions of a variety of IP address types used throughout the SDK, including an IPv4 or IPv6 address, an IP prefix (a network address with a prefix length), and an IP address and mask. IPv4 and IPv6 are supported by each of these types, so there are no separate classes for each address family. For example, the eos::ip_addr_t IP address type has an af() accessor to inspect the address family.
Utility functions are provided to parse or validate string format IP addresses and CIDR-style IP prefixes.
Some examples of the manipulations available are as follows, see the function descriptions for more information.
// Constructs an IPv4 address from a string. Must be a valid IP. eos::ip_addr_t v4("1.2.3.4"); // Constructs an IPv6 address from a string. eos::ip_addr_t v6("dead:beef::1"); // Parses and validates an IP address eos::ip_addr_t address; // the IPv4/IPv6 address type eos::ip_prefix_t prefix; // the IPv4/IPv6 prefix type bool valid; // valid == true, and address is changed to contain the // representation of 1.1.1.1 with its af() == eos::AF_IPV4 valid = eos::parse_ip_addr("1.1.1.1", &address); // valid == false, address is unchanged valid = eos::parse_ip_addr("not_an_ip", &address); // Parses and validates an IP prefix // The IP address must be the prefix network address, else the // prefix is invalid. Like parse_ip_address, prefix is updated to // contain the representation of the parsed prefix if and only if // valid == true. valid = eos::parse_ip_prefix("192.0.2.0/24", &prefix); // valid == true valid = eos::parse_ip_prefix("192.0.2.1/24", &prefix); // valid == false valid = eos::parse_ip_prefix("192.0.2.1/32", &prefix); // valid == true valid = eos::parse_ip_prefix("::1/128", &prefix); // valid == true // Construct an IP address and mask for 192.0.2.200/24 (e.g., used to // plumb a network interface in ip_intf.h) eos::ip_addr_t intf_addr("192.0.2.200"); eos::ip_addr_mask_t intf_addr_mask(intf_addr, 24);
Public Functions
STL namespace.
Public Functions
Enums
The address family of an IP address.
Values:
Not a valid address family (e.g., the default address).
An IPv4 address.
An IPv6 address.
Functions
Parses a string IP address, returning true if the address is valid. Supports both IPv4 and IPv6 addresses.
Pointer to a C string containing an address to parse.
Mutable arugment to place a successfully parsed result into.
Parses an IP route prefix, returns true if the prefix is valid. Supports both IPv4 and IPv6 route prefixes.
For example, “10.1.2.0/24” or “fffe:abab:1234::/96” are legal, but “10.1.2.7/24” is not, as 10.1.2.7 is not a valid network address for a 24-bit prefix length.
Pointer to a C string containing a prefix to parse.
Mutable arugment to place a successfully parsed result into.
An IP address. Both IPv4 and IPv6 addresses are supported by this class.
Public Functions
Creates an address from an address family and a network order array of bytes. Pass exactly 4 bytes for AF_IPV4 address type or 16 bytes for AF_IPV6.
Creates an IP address from a POSIX in_addr (IPv4).
Creates an IP address from a POSIX in6_addr (IPv6).
Creates an IP address from the provided string. panic() is called if an invalid (non IPv4 or IPv6) address is supplied.
An IPv4 or IPv6 address as a string.
Creates an IP address from the provided string. panic() is called if an invalid (non IPv4 or IPv6) address is supplied.
An IPv4 or IPv6 address as a string.
Takes a network order 32-bit unsigned integer as an IPv4 address.
Getter for ‘af’: The address family of this IP address.
The IP address as a big endian array of bytes.
The IP address as a big endian 32-bit integer.
Only valid for IPv4 addresses; panic() is called if used on an AF_IPV6 family address.
String representation of the IP address, e.g. “1.2.3.4” or “f00d::1”.
Public Members
Private Members
Friends
A utility stream operator that adds a string representation of ip_addr_t to the ostream.
Parses a string IP address, returning true if the address is valid. Supports both IPv4 and IPv6 addresses.
Pointer to a C string containing an address to parse.
Mutable arugment to place a successfully parsed result into.
An IPv4 or IPv6 route prefix.
A route prefix combines a network address and a prefix length. A network address has no 1 bits in the host component of the address (i.e., only the first prefix_length bits of the address can be non-zero).
Public Functions
Constructs a prefix from an IP network address and prefix length in bits.
panic() is called if the address provided is not a valid network address given the provided prefix length.
Constructs a prefix with the provided IP prefix string. Supports IPv4 and IPv6 address prefixes. This constructor will call panic() if the string passed is not a valid network prefix (e.g., “10.1.2.7/24” is invalid, while “10.1.2.0/24” is OK).
Getter for ‘prefix_length’: the prefix length in bits.
The address family of the prefix.
The prefix’s network address.
The prefix as mask. A prefix length of 8 on a v4 address will yield the mask 255.0.0.0.
String representation of the IP prefix, e.g. “10.2.3.4/24” or “cafe::1/218”.
Friends
A utility stream operator that adds a string representation of ip_prefix_t to the ostream.
Parses an IP route prefix, returns true if the prefix is valid. Supports both IPv4 and IPv6 route prefixes.
For example, “10.1.2.0/24” or “fffe:abab:1234::/96” are legal, but “10.1.2.7/24” is not, as 10.1.2.7 is not a valid network address for a 24-bit prefix length.
Pointer to a C string containing a prefix to parse.
Mutable arugment to place a successfully parsed result into.
An IP address with a subnet mask.
This allows for contiguous subnet masks only for IPv4 and IPv6 addresses.
IPv6 addresses in EOS only support contiguous masks, so for IPv6 addresses mask() provides the same value as mask_length().
Public Functions
Getter for ‘addr’: the address/mask’s IP address.
Getter for ‘mask_length’: the bit mask length, e.g., 24.
The address family of the prefix.
The bit mask itself, e.g., 0xFFFFFF00 (IPv4). For IPv6, same as mask_length().
The IP address and mask as a string, e.g., “192.0.2.1/0xFFFFFF00”.
Friends
A utility stream operator that adds a string representation of ip_addr_mask_t to the ostream.
Tried to configure an internal VLAN on a trunk port.
Public Functions
Throws this exception.
Returns a string representation of the current object’s values.
Private Members
Friends
A utility stream operator that adds a string representation of address_overlap_error to the ostream.