} l_fp;
-inline void Ntp2Unix(uint32_t &n, time_t &u) {
+inline void Ntp2Unix(const uint32_t &n, time_t &u) {
// Ntp's time scale starts in 1900, Unix in 1970.
u = n - 0x83aa7e80; // 2208988800 1970 - 1900 in seconds
// ... To be continued
};
-bool InitWithHost(std::string &strHostName, SOCKET &sockfd, socklen_t &servlen, struct sockaddr *pcliaddr) {
- sockfd = -1;
+bool InitWithHost(const std::string &strHostName, SOCKET &sockfd, socklen_t &servlen, struct sockaddr *pcliaddr) {
+
+ sockfd = INVALID_SOCKET;
std::vector<CNetAddr> vIP;
bool fRet = LookupHost(strHostName.c_str(), vIP, 10, true);
bool found = false;
for(unsigned int i = 0; i < vIP.size(); i++) {
- if ((found = vIP[i].GetInAddr(&servaddr.sin_addr))) {
+ if ((found = vIP[i].GetInAddr(&servaddr.sin_addr)) != false) {
break;
}
}
ip = CNetAddr(((sockaddr_in *)&cliaddr)->sin_addr);
int64_t nTime = DoReq(sockfd, servlen, cliaddr);
- closesocket(sockfd);
+ CloseSocket(sockfd);
return nTime;
}
-int64_t NtpGetTime(std::string &strHostName)
+int64_t NtpGetTime(const std::string &strHostName)
{
struct sockaddr cliaddr;
int64_t nTime = DoReq(sockfd, servlen, cliaddr);
- closesocket(sockfd);
+ CloseSocket(sockfd);
return nTime;
}
}
void ThreadNtpSamples(void* parg) {
- const int64_t nMaxOffset = 86400; // Not a real limit, just sanity threshold.
+ const int64_t nMaxOffset = nOneDay; // Not a real limit, just sanity threshold.
printf("Trying to find NTP server at localhost...\n");