Set all fields to zero
[novacoin.git] / src / ntp.cpp
index d05cfa5..5d0b90a 100644 (file)
@@ -1,19 +1,9 @@
-#ifdef WIN32
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#endif
 #ifndef WIN32
 #include <unistd.h>
 #endif
 
 #include "netbase.h"
 #include "net.h"
-//#include "util.h"
 #include "ui_interface.h"
 
 extern int GetRandInt(int nMax);
@@ -285,12 +275,12 @@ bool InitWithHost(const std::string &strHostName, SOCKET &sockfd, socklen_t &ser
     sockfd = INVALID_SOCKET;
 
     std::vector<CNetAddr> vIP;
-    bool fRet = LookupHost(strHostName.c_str(), vIP, 10, true);
+    bool fRet = LookupHost(strHostName, vIP, 10, true);
     if (!fRet) {
         return false;
     }
 
-    struct sockaddr_in servaddr;
+    struct sockaddr_in servaddr = {};
     servaddr.sin_family = AF_INET;
     servaddr.sin_port = htons(123);
 
@@ -438,7 +428,7 @@ int64_t NtpGetTime(const std::string &strHostName)
 std::string strTrustedUpstream = "localhost";
 
 // Current offset
-int64_t nNtpOffset = INT64_MAX;
+int64_t nNtpOffset = numeric_limits<int64_t>::max();
 
 int64_t GetNtpOffset() {
     return nNtpOffset;
@@ -477,7 +467,7 @@ void ThreadNtpSamples(void* parg) {
             }
             else {
                 // Something went wrong, disable trusted offset sampling.
-                nNtpOffset = INT64_MAX;
+                nNtpOffset = numeric_limits<int64_t>::max();
                 strTrustedUpstream = "localhost";
 
                 int nSleepMinutes = 1 + GetRandInt(9); // Sleep for 1-10 minutes.
@@ -506,7 +496,7 @@ void ThreadNtpSamples(void* parg) {
             }
             else {
                 // Not enough offsets yet, try to collect additional samples later.
-                nNtpOffset = INT64_MAX;
+                nNtpOffset = numeric_limits<int64_t>::max();
                 int nSleepMinutes = 1 + GetRandInt(4); // Sleep for 1-5 minutes.
                 for (int i = 0; i < nSleepMinutes * 60 && !fShutdown; i++) 
                     Sleep(1000);
@@ -514,7 +504,7 @@ void ThreadNtpSamples(void* parg) {
             }
         }
 
-        if (GetNodesOffset() == INT_MAX && abs(nNtpOffset) > 40 * 60)
+        if (GetNodesOffset() == numeric_limits<int64_t>::max() && abs(nNtpOffset) > 40 * 60)
         {
             // If there is not enough node offsets data and NTP time offset is greater than 40 minutes then give a warning.
             std::string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong NovaCoin will not work properly.");