[Git][NTPsec/ntpsec][master] TESTFRAME: Remove more complexity from ntp_intercept.c.

Eric S. Raymond gitlab at mg.gitlab.com
Thu Sep 29 14:13:10 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
6f764f37 by Eric S. Raymond at 2016-09-29T10:12:18-04:00
TESTFRAME: Remove more complexity from ntp_intercept.c.

- - - - -


2 changed files:

- ntpd/ntp_config.c
- ntpd/ntp_intercept.c


Changes:

=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -1570,6 +1570,39 @@ free_config_monitor(
 	FREE_FILEGEN_FIFO(ptree->filegen_opts);
 }
 
+bool getaddrinfo_now(char *hname, sockaddr_u *peeraddrp)
+{
+	int a_info;
+	size_t octets;
+	struct addrinfo		hints, *res;
+	ZERO(hints);
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_socktype = SOCK_DGRAM;
+	hints.ai_protocol = IPPROTO_UDP;
+	a_info = getaddrinfo(hname, "ntp", &hints, &res);
+	if (a_info == EAI_NONAME
+#ifdef EAI_NODATA
+	    || a_info == EAI_NODATA
+#endif
+	    ) {
+	    hints.ai_flags = AI_CANONNAME;
+	    hints.ai_flags |= AI_ADDRCONFIG;
+	    a_info = getaddrinfo(hname, "ntp", &hints, &res);
+	}
+	if (a_info != 0) {
+	    msyslog(LOG_ERR,
+		    "hostname %s can not be used (%s), please use IP address.",
+		    hname, gai_strerror(a_info));
+	    return false;
+	} else {
+	    INSIST(res != NULL);
+	    memset(peeraddrp, '\0', sizeof(*peeraddrp));
+	    octets = min(sizeof(*peeraddrp), res->ai_addrlen);
+	    memcpy(peeraddrp, res->ai_addr, octets);
+	    freeaddrinfo(res);
+	    return true;
+	}
+}
 
 static void
 config_access(


=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -259,6 +259,8 @@ static void file_replay(const char *configfile, char *delimiter, char *tempfile)
 }
 
 
+extern bool getaddrinfo_now(char *hname, sockaddr_u *peeraddrp);
+
 bool intercept_getaddrinfo(char *hname, sockaddr_u *peeraddrp)
 {
     if (mode == replay) {
@@ -278,42 +280,13 @@ bool intercept_getaddrinfo(char *hname, sockaddr_u *peeraddrp)
 	    replay_fail("invalid IP address %s\n", addr);
 	return true;
     } else {
-	int a_info;
-	size_t octets;
-	struct addrinfo		hints, *res;
-
-	ZERO(hints);
-	hints.ai_family = AF_UNSPEC;
-	hints.ai_socktype = SOCK_DGRAM;
-	hints.ai_protocol = IPPROTO_UDP;
-	a_info = getaddrinfo(hname, "ntp", &hints, &res);
-	if (a_info == EAI_NONAME
-#ifdef EAI_NODATA
-	    || a_info == EAI_NODATA
-#endif
-	    ) {
-	    hints.ai_flags = AI_CANONNAME;
-	    hints.ai_flags |= AI_ADDRCONFIG;
-	    a_info = getaddrinfo(hname, "ntp", &hints, &res);
-	}
+	bool lookup_ok = getaddrinfo_now(hname, peeraddrp);
 	if (mode == capture)
 	    printf("getaddrinfo %s %s %d\n",
 		   hname,
-		   socktoa((sockaddr_u *)res->ai_addr),
-		   a_info == 0);
-	if (a_info != 0) {
-	    msyslog(LOG_ERR,
-		    "hostname %s can not be used (%s), please use IP address.",
-		    hname, gai_strerror(a_info));
-	    return false;
-	} else {
-	    INSIST(res != NULL);
-	    memset(peeraddrp, '\0', sizeof(*peeraddrp));
-	    octets = min(sizeof(*peeraddrp), res->ai_addrlen);
-	    memcpy(peeraddrp, res->ai_addr, octets);
-	    freeaddrinfo(res);
-	    return true;
-	}
+		   socktoa((sockaddr_u *)peeraddrp),
+		   lookup_ok);
+	return lookup_ok;
     }
 }
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/6f764f374fdcf23ce007e59cc492c824061daa49
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160929/036370bf/attachment.html>


More information about the vc mailing list