How-To create a network
The liberate::net::network
class exists for making working with
IPv4 and IPv6 networks easier. In particular, this means the class makes it
easy to access special addresess within it.
Create a network from CIDR-style notation
1#include <liberate/net/network.h>
2
3liberate::net::network net{"192.168.0.3/16"};
You can, of course, access the “local” address easily enough, which is just the address you passed to the constructor. But you can also get the network part of the address only, the gateway and broadcast addresses.
Access the local address
1net.local_address() // == 192.168.0.3
2net.network_address() // == 192.168.0.0
3net.gateway_address() // == 192.168.0.1
4net.broadcast_address() // == 192.168.255.255
Note
There is no need for a gateway to be configured at gateway_address()
,
but that is common practice.