diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 7e4d1f69f..99b13b03c 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2994,8 +2994,8 @@ void Interpreter::HandleSntpResponse(uint64_t aTime, otError aResult) { // Some Embedded C libraries do not support printing of 64-bit unsigned integers. // To simplify, unix epoch time and era number are printed separately. - mServer->OutputFormat("SNTP response - Unix time: %ld (era: %ld)\r\n", - static_cast(aTime & UINT32_MAX), static_cast(aTime >> 32)); + mServer->OutputFormat("SNTP response - Unix time: %ld (era: %ld)\r\n", static_cast(aTime), + static_cast(aTime >> 32)); } else { diff --git a/src/core/net/sntp_client.cpp b/src/core/net/sntp_client.cpp index ac5da715f..fd9c051cf 100644 --- a/src/core/net/sntp_client.cpp +++ b/src/core/net/sntp_client.cpp @@ -374,7 +374,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag // Due to NTP protocol limitation, this module stops working correctly after around year 2106, if // unix era is not updated. This seems to be a reasonable limitation for now. Era number cannot be // obtained using NTP protocol, and client of this module is responsible to set it properly. - unixTime = GetUnixEra() * (UINT32_MAX + 1ULL); + unixTime = GetUnixEra() * (1ULL << 32); if (responseHeader.GetTransmitTimestampSeconds() > kTimeAt1970) { @@ -382,8 +382,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag } else { - unixTime += - static_cast(responseHeader.GetTransmitTimestampSeconds()) + (UINT32_MAX + 1ULL) - kTimeAt1970; + unixTime += static_cast(responseHeader.GetTransmitTimestampSeconds()) + (1ULL << 32) - kTimeAt1970; } // Return the time since 1970.