1

I am using CurlPP to get the public IP address of a network by using the API of https://ipify.org My function works fine, however, it only does when called up to 4-6 times. I am calling the function in a while loop to check for changes of the IP address. (It sometimes works for 4 times, sometimes for 5 or 6 times). After that, nothing happens, no output, nothing, just the cursor blinking in the terminal, no error or anything!

std::string getIPAddress()
{

    try
    {
        curlpp::Cleanup myCleanup;
        {
            std::ostringstream ip_address_stream;
            ip_address_stream << curlpp::options::Url("http://api.ipify.org");
            ip_address = ip_address_stream.str();
            return ip_address;
        }
    }
    catch(curlpp::RuntimeError &e)
    {
        std::cout << e.what() << std::endl;
    }
    catch(curlpp::LogicError &e)
    {
        std::cout << e.what() << std::endl;
    }

}
dmuensterer
  • 1,875
  • 11
  • 26
  • are you sure that api you're using isn't rate limited ? Try adding a (longer) sleep between requests. – Sander De Dycker Aug 07 '18 at 07:08
  • Yes, the API doesn't limit requests. Sleep also doesn't solve it. I have however an idea what it's about: While running the curlpp requests I am connecting to a VPN. So I assume that during the time there's no usable network interface, curlpp throws an error that I don't catch, although I think It should be catched as a runtime error? – dmuensterer Aug 07 '18 at 07:20
  • if you're unsure whether you catch all exceptions, you can use `catch (...)`. Alternatively, have a look at the network http traffic (using wireshark eg.) to see if you spot an oddity there. – Sander De Dycker Aug 07 '18 at 09:40

0 Answers0