15 # if !defined(FNM_CASEFOLD) && defined(FNM_IGNORECASE)
16 # define FNM_CASEFOLD FNM_IGNORECASE
19 #ifdef HAVE_SYS_PARAM_H
20 # include <sys/param.h>
22 #ifdef HAVE_SYS_IOCTL_H
23 # include <sys/ioctl.h>
25 #ifdef HAVE_SYS_SOCKIO_H /* UXPV: SIOC* #defines (Frank Vance <fvance@waii.com>) */
26 # include <sys/sockio.h>
33 #include "ntp_assert.h"
34 #include "ntp_stdlib.h"
38 #include "ntp_machine.h"
42 #include "ntp_lists.h"
43 #include "ntp_refclock.h"
44 #include "ntp_worker.h"
45 #include "ntp_request.h"
46 #include "timevalops.h"
47 #include "timespecops.h"
48 #include "ntpd-opts.h"
51 /* Don't include ISC's version of IPv6 variables and structures */
54 #include <isc/interfaceiter.h>
55 #include <isc/netaddr.h>
56 #include <isc/result.h>
57 #include <isc/sockaddr.h>
61 * Code to tell if we have an IP address
62 * If we have then return the sockaddr structure
63 * and set the return value
64 * see the bind9/getaddresses.c for details
74 struct addrinfo hints;
75 struct addrinfo *result;
76 struct sockaddr_in6 *resaddr6;
80 REQUIRE(host != NULL);
81 REQUIRE(addr != NULL);
86 * Try IPv4, then IPv6. In order to handle the extended format
87 * for IPv6 scoped addresses (address%scope_ID), we'll use a local
88 * working buffer of 128 bytes. The length is an ad-hoc value, but
89 * should be enough for this purpose; the buffer can contain a string
90 * of at least 80 bytes for scope_ID in addition to any IPv6 numeric
91 * addresses (up to 46 bytes), the delimiter character and the
92 * terminating NULL character.
94 if (AF_UNSPEC == af || AF_INET == af)
95 if (inet_pton(AF_INET, host, &in4) == 1) {
97 SET_ADDR4N(addr, in4.s_addr);
102 if (AF_UNSPEC == af || AF_INET6 == af)
103 if (sizeof(tmpbuf) > strlen(host)) {
104 if ('[' == host[0]) {
105 strlcpy(tmpbuf, &host[1], sizeof(tmpbuf));
106 pch = strchr(tmpbuf, ']');
110 strlcpy(tmpbuf, host, sizeof(tmpbuf));
113 hints.ai_family = AF_INET6;
114 hints.ai_flags |= AI_NUMERICHOST;
115 if (getaddrinfo(tmpbuf, NULL, &hints, &result) == 0) {
117 resaddr6 = UA_PTR(struct sockaddr_in6, result->ai_addr);
118 SET_ADDR6N(addr, resaddr6->sin6_addr);
119 SET_SCOPE(addr, resaddr6->sin6_scope_id);
121 freeaddrinfo(result);
126 * If we got here it was not an IP address