Topology helper Ipv4AddressHelper
allows to set the base address as shown in the example.
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
I want store an arbitrary number of addresses dynamically created, for example.
...
for( uint32_t subnetC = 0; subnetC < nSubnets; subnetC++ )
{
string ip = "10.1." + lexical_cast< string >( subnetC + 1 ) +".0";
ipList.push_back( ip );
}
...
vIpv4AddressHelper[ someIndex ].SetBase(ipList[ someIndex ], "255.255.255.0" );
...
However, I get the error
error: no matching function for call to ‘ns3::Ipv4AddressHelper::SetBase(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, const char [14])’
note: candidates are: void ns3::Ipv4AddressHelper::SetBase(ns3::Ipv4Address, ns3::Ipv4Mask, ns3::Ipv4Address)
How do I pass a string to SetBase
?
The compiler tells you that the candidate needs 2 params (the third one is optional. Also, see the doc for Ipv4AdressHelper). So pass those params.
In the docs you can see that Ipv4Adress
can be constructed with a char const*
. So try:
address.SetBase (ns3::Ipv4Adress(adress_string.c_str()), ns3::Ipv4Mask(mask_string.c_str()));
Changing adress_string
and mask_string
accordingly to your needs.