Commit | Line | Data |
---|---|---|
0665b239 BS |
1 | /** @file |
2 | * @brief IPHelper class header. This class represents a Helper to get the actual IP. | |
3 | * | |
4 | * | |
5 | * | |
6 | * @copyright Intra2net AG | |
7 | * @license GPLv2 | |
8 | */ | |
9 | ||
ad0e5016 BS |
10 | #ifndef IPADDRHELPER_H |
11 | #define IPADDRHELPER_H | |
0665b239 | 12 | |
4de6a9b8 | 13 | #include "logger.hpp" |
0665b239 BS |
14 | |
15 | #include <boost/shared_ptr.hpp> | |
1c0908b5 | 16 | #include <curl/curl.h> |
0665b239 | 17 | |
20399847 BS |
18 | #include <boost/archive/text_oarchive.hpp> |
19 | #include <boost/archive/text_iarchive.hpp> | |
20 | ||
efbde536 | 21 | |
ad0e5016 | 22 | class IPAddrHelper |
0665b239 | 23 | { |
92beaba3 | 24 | |
0665b239 | 25 | private: |
b30f392d | 26 | |
20399847 BS |
27 | friend class boost::serialization::access; |
28 | template<class Archive> | |
29 | void serialize(Archive & ar, const unsigned int version) | |
30 | { | |
31 | ar & LastWebcheck; | |
32 | } | |
33 | ||
b30f392d | 34 | Logger::Ptr Log; |
019dc0d9 BS |
35 | std::string WebcheckIpUrl; |
36 | std::string WebcheckIpUrlAlt; | |
2b0f7c11 | 37 | int WebcheckInterval; |
c730deea | 38 | time_t LastWebcheck; |
4eb87664 BS |
39 | std::string Proxy; |
40 | int ProxyPort; | |
0665b239 | 41 | bool UseIPv6; |
b30f392d | 42 | std::string Hostname; |
0665b239 | 43 | |
1d2e2f56 BS |
44 | bool is_local_ipv4(const std::string ip) const; |
45 | bool is_local_ipv6(const std::string ip) const; | |
3c4705d9 | 46 | std::string webcheck_ip(bool changed_to_online); |
4ef36a12 | 47 | CURL * init_curl(std::string& curl_writedata_buff, char* curl_err_buff) const; |
ce70569b | 48 | int perform_curl_operation(CURL * curl_easy_handle, const char* curl_err_buff, const std::string& actual_url) const; |
1d2e2f56 | 49 | std::string parse_ipv4(const std::string& data) const; |
c730deea | 50 | CURLcode set_curl_url(CURL * curl_easy_handle, const std::string& url) const; |
4ef36a12 | 51 | |
0665b239 BS |
52 | public: |
53 | ||
ad0e5016 | 54 | typedef boost::shared_ptr<IPAddrHelper> Ptr; |
0665b239 | 55 | |
ad0e5016 | 56 | IPAddrHelper(); |
0665b239 | 57 | |
08a5a621 | 58 | 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); |
0665b239 | 59 | |
ad0e5016 | 60 | ~IPAddrHelper(); |
0665b239 | 61 | |
c3dea5dc | 62 | std::string dns_query(const std::string& _hostname) const; |
0665b239 | 63 | |
6114d87c | 64 | std::string get_actual_ip( bool use_webcheck, bool changed_to_online, const std::string &wan_override_ip ); |
1c0908b5 | 65 | |
ce70569b | 66 | std::string get_local_wan_nic_ip() const; |
1d2e2f56 | 67 | |
1c0908b5 | 68 | // libcurl is a C library, so we have to make the callback member function static :-( |
0955e6a2 | 69 | static size_t http_receive(void *inBuffer, size_t size, size_t nmemb, std::string *outBuffer); |
1c0908b5 | 70 | |
08a5a621 | 71 | time_t get_last_webcheck() const; |
0665b239 BS |
72 | }; |
73 | ||
74 | #endif |