ip_address

struct mikrotik::api::ip_address

IP address verifier.

A quick utility to catch invalid ip address formats, before dealing with the sockets.

Checks if the given string is in the expected format for an IPv4 address: <a>.<b>.<c>.<d> where all variables are expected to be a byte ie. in the interval [0; 255].

Caution

This thing’s existence is questionable. It is likely going to get deprecated while in v1.x.x, or get some new and fancy functionality

Since

v1.0.0

Public Functions

ip_address(const char *address)

Creates an ip_address object from a string.

Creates an IPv4 address object by parsing the string. IPv4 is the only supported IP standard thus the expected string is of the form <a>.<b>.<c>.<d> where all values are in the interval [0; 255].

Since

v1.0.0

Exceptions
  • bad_ip_format: If the provided string does not contain a valid IPv4 address.

Parameters
  • address: The string that stores the IP address to validate & convert

ip_address(std::string_view address)

Creates an ip_address object from a string.

Creates an IPv4 address object by parsing the string. IPv4 is the only supported IP standard thus the expected string is of the form <a>.<b>.<c>.<d> where all values are in the interval [0; 255].

Since

v1.0.0

Exceptions
  • bad_ip_format: If the provided string does not contain a valid IPv4 address.

Parameters
  • address: The string that stores the IP address to validate & convert

std::string render(int port = 0) const

Creates a string from the stored ip address.

Creates a valid IPv4 address from the stored bytes.

Optionally a port may be supplied, which, if not zero, will be added at the end of the string ie. the end result is of the form <a>.<b>.<c>.<d>[:<port>] where the part in brackets is only created if port is nonzero.

Return

A string containing the IPv4 address and optionally the port.

Since

v1.0.0

Parameters
  • port: The port to add to the address. Zero is not rendered.

Public Members

std::array<std::uint8_t, 4> _bytes

The four bytes of the IPv4 address.