21 Internet protocol [internet]

21.11 Class template ip::network_v4 [internet.network.v4]

21.11.2 ip::network_v4 members [internet.network.v4.members]

constexpr address_v4 address() const noexcept;

Returns: The address specified when the network_v4 object was constructed.

constexpr int prefix_length() const noexcept;

Returns: The prefix length of the network.

constexpr address_v4 netmask() const noexcept;

Returns: An address_v4 object with prefix_length() contiguous non-zero bits set, starting from the most significant bit in network byte order. All other bits are zero.

constexpr address_v4 network() const noexcept;

Returns: An address_v4 object with the first prefix_length() bits, starting from the most significant bit in network byte order, set to the corresponding bit value of this->address(). All other bits are zero.

constexpr address_v4 broadcast() const noexcept;

Returns: An address_v4 object with the first prefix_length() bits, starting from the most significant bit in network byte order, set to the corresponding bit value of this->address(). All other bits are non-zero.

address_v4_range hosts() const noexcept;

Returns: If is_host() is true, an address_v4_range object representing the single address this->address(). Otherwise, an address_v4_range object representing the range of unique host IP addresses in the network.

Note: For IPv4, the network address and the broadcast address are not included in the range of host IP addresses. For example, given a network 192.168.1.0/24, the range returned by hosts() is from 192.168.1.1 to 192.168.1.254 inclusive, and neither 192.168.1.0 nor the broadcast address 192.168.1.255 are in the range.  — end note ]

constexpr network_v4 canonical() const noexcept;

Returns: network_v4(network(), prefix_length()).

constexpr bool is_host() const noexcept;

Returns: prefix_length() == 32.

constexpr bool is_subnet_of(const network_v4& other) const noexcept;

Returns: true if other.prefix_length() < prefix_length() and network_v4(this->address(), other.prefix_length()).canonical() == other.canonical(), otherwise false.

template<class Allocator = allocator<char>> basic_string<char, char_traits<char>, Allocator> to_string(const Allocator& a = Allocator()) const;

Returns: this->address().to_string(a) + "/" + std::to_string(prefix_length()).