I have an application that is meant to be installed into multiple environments, each with the same relative IP addresses.
By way of example, let's say there are three devices (it's much more complicated than this but I've pared it down for simplicity). The mapping of devices and environments to IP addresses is as follows:
Environ A, baseline = 192.0.0.0, range = 192.0.0.0 - 192.0.1.255
device-1 = OR:0.0.0.5 = 192.0.0.5
device-2 = OR:0.0.0.200 = 192.0.0.200
device-3 = OR:0.0.1.17 = 192.0.1.17
Environ B, baseline = 192.0.2.0, range = 192.0.2.0 - 192.0.3.255
device-1 = OR:0.0.0.5 = 192.0.2.5
device-2 = OR:0.0.0.200 = 192.0.2.200
device-3 = OR:0.0.1.17 = 192.0.3.17
Environ C, baseline = 192.0.4.0, range = 192.0.4.0 - 192.0.5.255
device-1 = OR:0.0.0.5 = 192.0.4.5
device-2 = OR:0.0.0.200 = 192.0.4.200
device-3 = OR:0.0.1.17 = 192.0.5.17
Environ D, baseline = 192.0.6.0, range = 192.0.6.0 - 192.0.7.255
device-1 = OR:0.0.0.5 = 192.0.6.5
device-2 = OR:0.0.0.200 = 192.0.6.200
device-3 = OR:0.0.1.17 = 192.0.7.17
In this scenario, every device would have an IP "or-address" of 0.0.0.0
through 0.0.1.255
inclusive (the rightmost nine bits).
The baseline IP for each environment is therefore the leftmost 23 bits (much like found in routing tables) while each device IP address can be obtained by ORing it's or-address with the baseline IP).
Any given device can therefore work out the IP addresses of all other devices in its environment in this manner (it gets the baseline from its own IP address). There is no need to communicate between environments.
So I have a few things I need to do (strong preference for using Boost since I want it to be portable across multiple platforms).
1/ I need to be able to get the current device's local IP address, keeping in mind there's only one address, so no having to worry about multi-NIC or multi-homing.
2/ I need to be able to zero out the rightmost N bits and then OR that value with another address.
What's the easiest way to do these tasks? Once done, getting the string representation (or using the final address directly) should be easy.