]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ntpdate: fix service resolution if 'ntp' is not in '/etc/services'
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 27 Jan 2019 09:19:08 +0000 (10:19 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 27 Jan 2019 09:19:08 +0000 (10:19 +0100)
bk: 5c4d778ccCMFgyR3XeKGrgbSAXujPQ

ntpdate/ntpdate.c

index 4cf0f6265cdaafeddfe676a9cbfdd27767465e8e..4e86af1ace8e42d3a1464eb5de89f584774b78d9 100644 (file)
@@ -1367,6 +1367,10 @@ addserver(
 #endif
 
        error = getaddrinfo(serv, service, &hints, &addrResult);
+       if (error == EAI_SERVICE) {
+               strlcpy(service, "123", sizeof(service));
+               error = getaddrinfo(serv, service, &hints, &addrResult);
+       }
        if (error != 0) {
                /* Conduct more refined error analysis */
                if (error == EAI_FAIL || error == EAI_AGAIN){
@@ -1703,7 +1707,12 @@ init_io(void)
        hints.ai_flags = AI_PASSIVE;
        hints.ai_socktype = SOCK_DGRAM;
 
-       if (getaddrinfo(NULL, service, &hints, &res) != 0) {
+       rc = getaddrinfo(NULL, service, &hints, &res);
+       if (rc == EAI_SERVICE) {
+               strlcpy(service, "123", sizeof(service));
+               rc = getaddrinfo(NULL, service, &hints, &res);
+       }
+       if (rc != 0) {
                msyslog(LOG_ERR, "getaddrinfo() failed: %m");
                exit(1);
                /*NOTREACHED*/