Sebastian Wolf 3 vuotta sitten
vanhempi
commit
1adbfa7038
3 muutettua tiedostoa jossa 16 lisäystä ja 12 poistoa
  1. 4 0
      NEWS
  2. 6 6
      plugins/check_ntp.c
  3. 6 6
      plugins/check_ntp_time.c

+ 4 - 0
NEWS

@@ -1,5 +1,9 @@
 This file documents the major additions and syntax changes between releases.
 This file documents the major additions and syntax changes between releases.
 
 
+2.4.2 2022-11-??
+	FIXES
+	check_ntp_time: Fix calculation bug introduced in 2.4.1 (#677)
+
 2.4.1 2022-10-25
 2.4.1 2022-10-25
 	FIXES
 	FIXES
 	check_ntp_time: Ensure -W/-C (stratum warning/critical thresholds) are available as short options (#661)
 	check_ntp_time: Ensure -W/-C (stratum warning/critical thresholds) are available as short options (#661)

+ 6 - 6
plugins/check_ntp.c

@@ -189,8 +189,8 @@ static int allow_zero_stratum = 0;
 double ntp32_to_double(uint32_t n) {
 double ntp32_to_double(uint32_t n) {
 	double result = 0;
 	double result = 0;
 	if (n) {
 	if (n) {
-		uint16_t l16 = ntohs((uint16_t) (n >> 16));
-		uint16_t r16 = ntohs((uint16_t) (n & ((1<<16) - 1)));
+		uint16_t l16 = ntohs((uint16_t) (n & ((1<<16) - 1)));
+		uint16_t r16 = ntohs((uint16_t) (n >> 16));
 		result = l16 + ((double) r16/65536.0);
 		result = l16 + ((double) r16/65536.0);
 	}
 	}
 	return result;
 	return result;
@@ -202,8 +202,8 @@ double ntp32_to_double(uint32_t n) {
 double ntp64_to_double(uint64_t n) {
 double ntp64_to_double(uint64_t n) {
 	double result = 0;
 	double result = 0;
 	if (n) {
 	if (n) {
-		uint32_t l32 = ntohl((uint32_t) (n >> 32));
-		uint32_t r32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
 		result = (l32 - EPOCHDIFF)
 		result = (l32 - EPOCHDIFF)
 		       + (.00000001*(0.5+(double)(r32/42.94967296)));
 		       + (.00000001*(0.5+(double)(r32/42.94967296)));
 	}
 	}
@@ -222,8 +222,8 @@ double ntp64_to_double(uint64_t n) {
 struct timeval ntp64_to_tv(uint64_t n) {
 struct timeval ntp64_to_tv(uint64_t n) {
 	struct timeval result = {};
 	struct timeval result = {};
 	if (n) {
 	if (n) {
-		uint32_t l32 = ntohl((uint32_t) (n >> 32));
-		uint32_t r32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
 		result.tv_sec = l32 - EPOCHDIFF;
 		result.tv_sec = l32 - EPOCHDIFF;
 		result.tv_usec = (int)(0.5+(double)(r32/4294.967296));
 		result.tv_usec = (int)(0.5+(double)(r32/4294.967296));
 	}
 	}

+ 6 - 6
plugins/check_ntp_time.c

@@ -177,8 +177,8 @@ ntp_server_results *servers=NULL;
 double ntp32_to_double(uint32_t n) {
 double ntp32_to_double(uint32_t n) {
 	double result = 0;
 	double result = 0;
 	if (n) {
 	if (n) {
-		uint16_t l16 = ntohs((uint16_t) (n >> 16));
-		uint16_t r16 = ntohs((uint16_t) (n & ((1<<16) - 1)));
+		uint16_t l16 = ntohs((uint16_t) (n & ((1<<16) - 1)));
+		uint16_t r16 = ntohs((uint16_t) (n >> 16));
 		result = l16 + ((double) r16/65536.0);
 		result = l16 + ((double) r16/65536.0);
 	}
 	}
 	return result;
 	return result;
@@ -190,8 +190,8 @@ double ntp32_to_double(uint32_t n) {
 double ntp64_to_double(uint64_t n) {
 double ntp64_to_double(uint64_t n) {
 	double result = 0;
 	double result = 0;
 	if (n) {
 	if (n) {
-		uint32_t l32 = ntohl((uint32_t) (n >> 32));
-		uint32_t r32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
 		result = (l32 - EPOCHDIFF)
 		result = (l32 - EPOCHDIFF)
 		       + (.00000001*(0.5+(double)(r32/42.94967296)));
 		       + (.00000001*(0.5+(double)(r32/42.94967296)));
 	}
 	}
@@ -210,8 +210,8 @@ double ntp64_to_double(uint64_t n) {
 struct timeval ntp64_to_tv(uint64_t n) {
 struct timeval ntp64_to_tv(uint64_t n) {
 	struct timeval result = {};
 	struct timeval result = {};
 	if (n) {
 	if (n) {
-		uint32_t l32 = ntohl((uint32_t) (n >> 32));
-		uint32_t r32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
 		result.tv_sec = l32 - EPOCHDIFF;
 		result.tv_sec = l32 - EPOCHDIFF;
 		result.tv_usec = (int)(0.5+(double)(r32/4294.967296));
 		result.tv_usec = (int)(0.5+(double)(r32/4294.967296));
 	}
 	}