From 1002e8a153097adb4273e6807b3a7cce7ba2df25 Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Mon, 23 May 2022 13:42:03 +0000
Subject: [PATCH] Count number of errors recorded and print in error column

---
 main.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/main.c b/main.c
index e9f7e63..340187f 100644
--- a/main.c
+++ b/main.c
@@ -116,6 +116,7 @@
 	struct dns_list* dns = (struct dns_list*)in;
 	dns->time.tv_sec = 0;
 	dns->time.tv_nsec = 0;
+    dns->errors = 0;
 	for (int i = 0; i < num_tests; i++) {
 		struct hosts_list* curr = hosts;
 		while (curr) {
@@ -126,16 +127,18 @@
 			for (int j = 0; j < 3 && run.tv_sec == -1; j++) {
 				run = resolve(buf, curr->server, dns->server, T_A);
 			}
-			if (run.tv_sec == -1) // if test has failed 3 times, set time taken
+			if (run.tv_sec == -1) { // if test has failed 3 times, set time taken
 			                      // to 3s as penalty
-				run.tv_sec = 3;
-			dns->time.tv_sec += run.tv_sec;
-			dns->time.tv_nsec += run.tv_nsec;
-			if (dns->time.tv_nsec >=
-			    1000000000) { // nanoseconds have overflowed into seconds
-				dns->time.tv_sec += 1;
-				dns->time.tv_nsec -= 1000000000;
-			}
+                dns->errors++;
+            } else {
+                dns->time.tv_sec += run.tv_sec;
+                dns->time.tv_nsec += run.tv_nsec;
+                if (dns->time.tv_nsec >=
+                    1000000000) { // nanoseconds have overflowed into seconds
+                    dns->time.tv_sec += 1;
+                    dns->time.tv_nsec -= 1000000000;
+                }
+            }
 			tests_done++;
 			curr = curr->next;
 		}

--
Gitblit v1.10.0