Fix 'occurred' typo
[bpdyndnsd] / src / ip_addr_helper.cpp
index 8628cb9..fcc3680 100644 (file)
@@ -14,6 +14,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <ifaddrs.h>
+#include "version_info.h"
 
 
 using namespace std;
@@ -179,15 +180,19 @@ bool IPAddrHelper::is_local_ipv4(const string ip) const
 
 /**
  * Get the actual IP of this host through a conventional DNS query or through a IP webcheck URL if configured so.
+ * @param use_webcheck If true: Determine IP via web check
  * @param changed_to_online Indicates if we just went online
+ * @param wan_override_ip Override automatic WAN IP detection if not empty
  * @return A string representation of the actual IP in dotted format or an empty string if something went wrong.
  */
-string IPAddrHelper::get_actual_ip( bool use_webcheck, bool changed_to_online )
+string IPAddrHelper::get_actual_ip( bool use_webcheck, bool changed_to_online, const std::string &wan_override_ip )
 {
     string ip;
 
     if ( !WebcheckIpUrl.empty() && use_webcheck )
         ip = webcheck_ip(changed_to_online);
+    else if (!wan_override_ip.empty())
+        ip = wan_override_ip;
     else
         ip = get_local_wan_nic_ip();
 
@@ -409,6 +414,9 @@ string IPAddrHelper::webcheck_ip(bool changed_to_online)
         return "";
     }
 
+    // Set the LastWebcheck time to current time.
+    LastWebcheck = current_time;
+
     // If perform_curl_operation returns a connection problem indicating return code, try the next ip webcheck url if there is one.
     while ( (curl_err_code == 1) && (url_list.size() != 0) && (url_list.front() != "") )
     {
@@ -451,9 +459,6 @@ string IPAddrHelper::webcheck_ip(bool changed_to_online)
         return "";
     }
 
-    // Set the LastWebcheck time to current time.
-    LastWebcheck = current_time;
-
     // If IP is within a private range then return ""
     if ( is_local_ipv4(ip_addr) )
     {
@@ -506,7 +511,7 @@ int IPAddrHelper::perform_curl_operation(CURL * curl_easy_handle, const char* cu
     CURLcode curl_err_code;
     if ( (curl_err_code = curl_easy_perform(curl_easy_handle) ) != CURLE_OK )
     {
-        // CURL error occured
+        // CURL error occurred
         if ( (curl_err_code == CURLE_COULDNT_CONNECT) || (curl_err_code == CURLE_OPERATION_TIMEOUTED) || (curl_err_code == CURLE_COULDNT_RESOLVE_HOST) )
         {
             // In case of connection problems we should return 1, that the fallback url will be used.
@@ -556,7 +561,9 @@ CURLcode IPAddrHelper::set_curl_url(CURL * curl_easy_handle, const string& url)
  */
 CURL * IPAddrHelper::init_curl(string& curl_writedata_buff,char* curl_err_buff) const
 {
-    string user_agent = "Intra2net AG - Bullet Proof DYNDNS Daemon - 0.1.1";
+    ostringstream user_agent_stream;
+    user_agent_stream << "Intra2net AG - Bullet Proof DYNDNS Daemon - " << MAJOR_VERSION << "." << MINOR_VERSION;
+    string user_agent = user_agent_stream.str();
 
     CURL *curl_easy_handle = curl_easy_init();
     if ( curl_easy_handle == NULL )
@@ -580,7 +587,7 @@ CURL * IPAddrHelper::init_curl(string& curl_writedata_buff,char* curl_err_buff)
     if ( curlError == CURLE_OK)
         curlError = curl_easy_setopt(curl_easy_handle,CURLOPT_WRITEDATA,&curl_writedata_buff);
     if ( curlError == CURLE_OK)
-        curlError = curl_easy_setopt(curl_easy_handle,CURLOPT_USERAGENT,&user_agent);
+        curlError = curl_easy_setopt(curl_easy_handle,CURLOPT_USERAGENT,user_agent.c_str());
 
     if ( !Proxy.empty() )
     {
@@ -610,11 +617,11 @@ CURL * IPAddrHelper::init_curl(string& curl_writedata_buff,char* curl_err_buff)
  * @param outBuffer Pointer to output stream.
  * @return The size received.
  */
-size_t IPAddrHelper::http_receive( const char *inBuffer, size_t size, size_t nmemb, string *outBuffer )
+size_t IPAddrHelper::http_receive( void *inBuffer, size_t size, size_t nmemb, string *outBuffer )
 {
-    outBuffer->append(inBuffer);
+    outBuffer->append(static_cast<char *>(inBuffer), size*nmemb);
     return (size*nmemb);
-}
+} //lint !e818
 
 
 /**