Skip webcheck idle period check if we just went online. Improve webcheck logging
[bpdyndnsd] / src / ip_addr_helper.cpp
index 56100bb..8628cb9 100644 (file)
@@ -179,14 +179,15 @@ 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 changed_to_online Indicates if we just went online
  * @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 )
+string IPAddrHelper::get_actual_ip( bool use_webcheck, bool changed_to_online )
 {
     string ip;
 
     if ( !WebcheckIpUrl.empty() && use_webcheck )
-        ip = webcheck_ip();
+        ip = webcheck_ip(changed_to_online);
     else
         ip = get_local_wan_nic_ip();
 
@@ -370,9 +371,10 @@ string IPAddrHelper::dns_query(const string& _hostname) const
 
 /**
  * Get the actual IP of this host through a IP webcheck URL.
+ * @param changed_to_online Indicates if we just went online
  * @return A string representation of the actual IP in dotted format or an empty string if something went wrong.
  */
-string IPAddrHelper::webcheck_ip()
+string IPAddrHelper::webcheck_ip(bool changed_to_online)
 {
     // Init IPAddress with a empty string.
     string ip_addr = "";
@@ -381,7 +383,8 @@ string IPAddrHelper::webcheck_ip()
     time_t current_time = time(NULL);
 
     // Test if webcheck is allowed due to webcheck_interval.
-    if ( (LastWebcheck + ((time_t)WebcheckInterval*60)) >= current_time )
+    // Ignored if we just went online.
+    if ( !changed_to_online && (LastWebcheck + ((time_t)WebcheckInterval*60)) >= current_time )
     {
         // Webcheck not allowed, log it and return empty string.
         Log->print_webcheck_exceed_interval( LastWebcheck, (WebcheckInterval*60), current_time );