From: Juergen Perlinger Date: Sun, 27 Jan 2019 09:19:08 +0000 (+0100) Subject: ntpdate: fix service resolution if 'ntp' is not in '/etc/services' X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd106bdc467dbd874100d3fa475645c1a1e6e7c3;p=thirdparty%2Fntp.git ntpdate: fix service resolution if 'ntp' is not in '/etc/services' bk: 5c4d778ccCMFgyR3XeKGrgbSAXujPQ --- diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index 4cf0f6265..4e86af1ac 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -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*/