Is it possible to find out a string is a FQDN or an IP address using boost lib in c++. I have tried the below code which works fine for IP address but throws exception in case of FQDN.
// getHostname returns IP address or FQDN
std::string getHostname()
{
// some work and find address and return
return hostname;
}
bool ClassName::isAddressFqdn()
{
const std::string hostname = getHostname();
boost::asio::ip::address addr;
addr.from_string(hostname.c_str());
//addr.make_address(hostname.c_str()); // make_address does not work in my boost version
if ((addr.is_v6()) || (addr.is_v4()))
{
std::cout << ":: IP address : " << hostname << std::endl;
return false;
}
// If address is not an IPv4 or IPv6, then consider it is FQDN hostname
std::cout << ":: FQDN hostname: " << hostname << std::endl;
return true;
}
The fails in case of FQDN , as boost::asio::ip::address throws an exception in case of FQDN.
I have also tried searching for the same, in python something similar is availble but I need in c++.