Update the ipam code to support geofeed.
This commit is contained in:
4
Makefile
4
Makefile
@ -5,7 +5,9 @@ CPPFLAGS+= -I . -g -O0
|
||||
|
||||
all: test ipam
|
||||
|
||||
test: ipam
|
||||
test:
|
||||
|
||||
run: ipam
|
||||
./ipam
|
||||
|
||||
clean:
|
||||
|
45
ipam.cc
45
ipam.cc
@ -229,6 +229,51 @@ try
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
add_command
|
||||
(
|
||||
{
|
||||
"geofeed",
|
||||
"Describe a network's various physical locations.",
|
||||
[]( const std::vector< std::string > &args )
|
||||
{
|
||||
if( args.empty() ) throw std::runtime_error{ "Requires one argument." };
|
||||
if( args.size() != 1 ) throw std::runtime_error{ "Too many arguments." };
|
||||
|
||||
const auto &network= boost::lexical_cast< IP_Address >( args.at( 0 ) );
|
||||
std::cout << "Parsed: `" << network << "` -- it has a " << network.prefix_length()
|
||||
<< " bit mask." << std::endl;
|
||||
|
||||
const Allocation *p= nullptr;
|
||||
|
||||
std::optional< IP_Address > found;
|
||||
auto better= [&]( const auto &where )
|
||||
{
|
||||
return not found.has_value() or where.is_subnet_of( found.value() );
|
||||
};
|
||||
|
||||
for( const auto &space: spaces )
|
||||
{
|
||||
const auto &[ where, owner, name, purpose, country, state, city, postal ]= space;
|
||||
if( network.is_subnet_of( where ) and better( where ) )
|
||||
{
|
||||
found= where;
|
||||
p = &space;
|
||||
}
|
||||
}
|
||||
|
||||
const auto &[ _, owner, name, purpose, country, state, city, postal ]= *p;
|
||||
|
||||
for( const auto &sub: p->subAllocations() )
|
||||
{
|
||||
std::cout << sub.network << "," << sub.country << "," << sub.region
|
||||
<< "," << sub.city << "," << sub.postal
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
while( not std::cin.eof() )
|
||||
|
Reference in New Issue
Block a user