/** @file * @brief IPHelper class header. This class represents a Helper to get the actual IP. * * * * @copyright Intra2net AG * @license GPLv2 */ #ifndef IPADDRHELPER_H #define IPADDRHELPER_H #include "logger.hpp" #include #include #include #include class IPAddrHelper { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version) { ar & LastWebcheck; } Logger::Ptr Log; std::string WebcheckIpUrl; std::string WebcheckIpUrlAlt; int WebcheckInterval; time_t LastWebcheck; std::string Proxy; int ProxyPort; bool UseIPv6; std::string Hostname; bool is_local_ipv4(const std::string ip) const; bool is_local_ipv6(const std::string ip) const; std::string webcheck_ip(bool changed_to_online); CURL * init_curl(std::string& curl_writedata_buff, char* curl_err_buff) const; int perform_curl_operation(CURL * curl_easy_handle, const char* curl_err_buff, const std::string& actual_url) const; std::string parse_ipv4(const std::string& data) const; CURLcode set_curl_url(CURL * curl_easy_handle, const std::string& url) const; public: typedef boost::shared_ptr Ptr; IPAddrHelper(); IPAddrHelper(const Logger::Ptr _log, const std::string& _webcheck_url, const std::string& _webcheck_url_alt, const int _webcheck_interval, const time_t _last_webcheck, const bool _use_ipv6, const std::string& _proxy, const int _proxy_port); ~IPAddrHelper(); std::string dns_query(const std::string& _hostname) const; std::string get_actual_ip( bool use_webcheck, bool changed_to_online, const std::string &wan_override_ip ); std::string get_local_wan_nic_ip() const; // libcurl is a C library, so we have to make the callback member function static :-( static size_t http_receive(void *inBuffer, size_t size, size_t nmemb, std::string *outBuffer); time_t get_last_webcheck() const; }; #endif