478
if (entry->ce_name == NULL && SOCKNUL(&entry->peer_store)) {
475
if (entry->ce_name == NULL && SOCKNUL(&entry->peer_store)) {
479
476
msyslog(LOG_ERR, "findhostaddr: both ce_name and ce_peeraddr are undefined!");
483
480
if (entry->ce_name) {
486
msyslog(LOG_INFO, "findhostaddr: Resolving <%s>",
481
DPRINTF(2, ("findhostaddr: Resolving <%s>\n",
490
484
memset(&hints, 0, sizeof(hints));
491
485
hints.ai_family = AF_UNSPEC;
508
502
entry->ce_config.v6_flag = 1;
511
else if (error == EAI_NONAME)
513
msyslog(LOG_ERR, "host name not found: %s", entry->ce_name);
518
msyslog(LOG_INFO, "findhostaddr: Resolving %s>",
519
stoa(&entry->peer_store));
521
entry->ce_name = emalloc(MAXHOSTNAMELEN);
506
DPRINTF(2, ("findhostaddr: Resolving <%s>\n",
507
stoa(&entry->peer_store)));
509
entry->ce_name = emalloc(NI_MAXHOST);
522
510
error = getnameinfo((const struct sockaddr *)&entry->peer_store,
523
511
SOCKLEN(&entry->peer_store),
524
(char *)&entry->ce_name, MAXHOSTNAMELEN,
512
(char *)&entry->ce_name, NI_MAXHOST,
529
printf("intres: got error status of: %d\n", error);
533
* If the resolver failed, see if the failure is
534
* temporary. If so, return success.
518
/* again is our return value, for success it is 1 */
521
DPRINTF(2, ("findhostaddr: %s resolved.\n",
522
(entry->ce_name) ? "name" : "address"));
525
* If the resolver failed, see if the failure is
526
* temporary. If so, return success.
542
#ifndef FORCE_DNSRETRY
547
542
#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
545
msyslog(LOG_ERR, "host name not found%s%s: %s",
546
(EAI_NONAME == error) ? "" : " EAI_NODATA",
547
(eai_again_seen) ? " (permanent)" : "",
549
again = !eai_again_seen;
551
552
#ifdef EAI_SYSTEM
555
* EAI_SYSTEM means the real error is in errno. We should be more
556
* discriminating about which errno values require retrying, but
557
* this matches existing behavior.
560
DPRINTF(1, ("intres: EAI_SYSTEM errno %d (%s) means try again, right?\n",
561
errno, strerror(errno)));
560
if (entry->ce_name) {
563
msyslog(LOG_INFO, "findhostaddr: name resolved.");
568
msyslog(LOG_INFO, "findhostaddr: address resolved.");
566
/* do this here to avoid perturbing errno earlier */
567
DPRINTF(2, ("intres: got error status of: %d\n", error));
592
592
* For now only bother with IPv4
594
594
hints.ai_family = AF_INET;
596
595
hints.ai_socktype = SOCK_DGRAM;
597
if (getaddrinfo(localhost, "ntp", &hints, &addrResult)!=0) {
598
msyslog(LOG_ERR, "getaddrinfo failed: %m");
597
err = getaddrinfo(localhost, "ntp", &hints, &addr);
601
if (EAI_SYSTEM == err)
602
msyslog(LOG_ERR, "getaddrinfo(%s) failed: %m",
606
msyslog(LOG_ERR, "getaddrinfo(%s) failed: %s",
607
localhost, gai_strerror(err));
599
608
resolver_exit(1);
601
sockfd = socket(addrResult->ai_family, addrResult->ai_socktype, 0);
611
sockfd = socket(addr->ai_family, addr->ai_socktype, 0);
613
if (INVALID_SOCKET == sockfd) {
604
614
msyslog(LOG_ERR, "socket() failed: %m");
605
615
resolver_exit(1);
620
* On Windows only the count of sockets must be less than
621
* FD_SETSIZE. On Unix each descriptor's value must be less
622
* than FD_SETSIZE, as fd_set is a bit array.
624
if (sockfd >= FD_SETSIZE) {
625
msyslog(LOG_ERR, "socket fd %d too large, FD_SETSIZE %d",
626
(int)sockfd, FD_SETSIZE);
609
631
* Make the socket non-blocking. We'll wait with select()
632
* Unix: fcntl(O_NONBLOCK) or fcntl(FNDELAY)
612
#if defined(O_NONBLOCK)
613
635
if (fcntl(sockfd, F_SETFL, O_NONBLOCK) == -1) {
614
636
msyslog(LOG_ERR, "fcntl(O_NONBLOCK) failed: %m");
615
637
resolver_exit(1);
619
641
if (fcntl(sockfd, F_SETFL, FNDELAY) == -1) {
620
642
msyslog(LOG_ERR, "fcntl(FNDELAY) failed: %m");
621
643
resolver_exit(1);
624
# include "Bletch: NEED NON BLOCKING IO"
625
#endif /* FNDDELAY */
626
#endif /* O_NONBLOCK */
627
#else /* SYS_WINNT */
630
if (ioctlsocket(sockfd,FIONBIO,(u_long *) &on) == SOCKET_ERROR) {
631
msyslog(LOG_ERR, "ioctlsocket(FIONBIO) fails: %m");
632
resolver_exit(1); /* Windows NT - set socket in non-blocking mode */
646
# include "Bletch: NEED NON BLOCKING IO"
647
# endif /* FNDDELAY */
648
# endif /* O_NONBLOCK */
649
(void)on; /* quiet unused warning */
650
#else /* !SYS_WINNT above */
652
* Make the socket non-blocking. We'll wait with select()
653
* Windows: ioctlsocket(FIONBIO)
656
err = ioctlsocket(sockfd, FIONBIO, &on);
657
if (SOCKET_ERROR == err) {
658
msyslog(LOG_ERR, "ioctlsocket(FIONBIO) fails: %m");
635
661
#endif /* SYS_WINNT */
636
if (connect(sockfd, addrResult->ai_addr, addrResult->ai_addrlen) == -1) {
663
err = connect(sockfd, addr->ai_addr, addr->ai_addrlen);
664
if (SOCKET_ERROR == err) {
637
665
msyslog(LOG_ERR, "openntp: connect() failed: %m");
638
666
resolver_exit(1);
640
freeaddrinfo(addrResult);