1dnl ######################################################################
2dnl Common IPv6 detection for NTP configure.ac files
3AC_DEFUN([NTP_IPV6], [
4
5AC_CACHE_CHECK(
6    [for struct sockaddr_storage],
7    [ntp_cv_sockaddr_storage],
8    [AC_COMPILE_IFELSE(
9          [AC_LANG_PROGRAM(
10              [[
11                    #ifdef HAVE_SYS_TYPES_H
12                    # include <sys/types.h>
13                    #endif
14                    #ifdef HAVE_SYS_SOCKET_H
15                    # include <sys/socket.h>
16                    #endif
17                    #ifdef HAVE_NETINET_IN_H
18                    # include <netinet/in.h>
19                    #endif
20              ]],
21              [[
22                    struct sockaddr_storage n;
23              ]]
24          )],
25          [ntp_cv_sockaddr_storage=yes],
26          [ntp_cv_sockaddr_storage=no]
27    )]
28)
29case "$ntp_cv_sockaddr_storage" in
30 yes)
31    AC_DEFINE([HAVE_STRUCT_SOCKADDR_STORAGE], [1],
32          [Does a system header define struct sockaddr_storage?])
33    AC_CACHE_CHECK(
34          [for sockaddr_storage.__ss_family],
35          [ntp_cv_have___ss_family],
36          [AC_COMPILE_IFELSE(
37              [AC_LANG_PROGRAM(
38                    [[
39                        #ifdef HAVE_SYS_TYPES_H
40                        # include <sys/types.h>
41                        #endif
42                        #ifdef HAVE_SYS_SOCKET_H
43                        # include <sys/socket.h>
44                        #endif
45                        #ifdef HAVE_NETINET_IN_H
46                        # include <netinet/in.h>
47                        #endif
48                    ]],
49                    [[
50                        struct sockaddr_storage s;
51                        s.__ss_family = 1;
52                    ]]
53              )],
54              [ntp_cv_have___ss_family=yes],
55              [ntp_cv_have___ss_family=no]
56          )]
57    )
58    case "$ntp_cv_have___ss_family" in
59     yes)
60          AC_DEFINE([HAVE___SS_FAMILY_IN_SS], [1],
61                      [Does struct sockaddr_storage have __ss_family?])
62    esac
63    AH_VERBATIM(
64          [HAVE___SS_FAMILY_IN_SS_VERBATIM],
65          [
66              /* Handle sockaddr_storage.__ss_family */
67              #ifdef HAVE___SS_FAMILY_IN_SS
68              # define ss_family __ss_family
69              #endif /* HAVE___SS_FAMILY_IN_SS */
70          ]
71    )
72esac
73
74
75#
76# Look for in_port_t.
77#
78AC_CACHE_CHECK(
79    [for in_port_t],
80    [isc_cv_have_in_port_t],
81    [AC_COMPILE_IFELSE(
82          [AC_LANG_PROGRAM(
83              [[
84                    #include <sys/types.h>
85                    #include <netinet/in.h>
86              ]],
87              [[
88                    in_port_t port = 25;
89                    return (0);
90              ]]
91          )],
92          [isc_cv_have_in_port_t=yes],
93          [isc_cv_have_in_port_t=no]
94    )]
95)
96case "$isc_cv_have_in_port_t" in
97 no)
98          AC_DEFINE([ISC_PLATFORM_NEEDPORTT], [1],
99              [Declare in_port_t?])
100esac
101
102AC_CACHE_CHECK(
103    [type of socklen arg for getsockname()],
104    [ntp_cv_getsockname_socklen_type],
105    [
106    getsockname_socklen_type_found=no
107    for getsockname_arg2 in 'struct sockaddr *' 'void *'; do
108          for ntp_cv_getsockname_socklen_type in 'socklen_t' 'size_t' 'unsigned int' 'int'; do
109              AC_COMPILE_IFELSE(
110                    [AC_LANG_PROGRAM(
111                        [[
112                              #ifdef HAVE_SYS_TYPES_H
113                              # include <sys/types.h>
114                              #endif
115                              #ifdef HAVE_SYS_SOCKET_H
116                              # include <sys/socket.h>
117                              #endif
118                        ]], [[
119                              extern
120                              getsockname(int, $getsockname_arg2,
121                                        $ntp_cv_getsockname_socklen_type *);
122                        ]]
123                    )],
124                    [getsockname_socklen_type_found=yes ; break 2],
125                    []
126              )
127          done
128    done
129    case "$getsockname_socklen_type_found" in
130     no)
131          ntp_cv_getsockname_socklen_type='socklen_t'
132    esac
133    AS_UNSET([getsockname_arg2])
134    AS_UNSET([getsockname_socklen_type_found])
135    ]
136)
137AC_DEFINE_UNQUOTED([GETSOCKNAME_SOCKLEN_TYPE],
138                       [$ntp_cv_getsockname_socklen_type],
139                       [What is getsockname()'s socklen type?])
140
141AC_CACHE_CHECK(
142    [struct sockaddr for sa_len],
143    [isc_cv_platform_havesalen],
144    [AC_COMPILE_IFELSE(
145          [AC_LANG_PROGRAM(
146              [[
147                    #include <sys/types.h>
148                    #include <sys/socket.h>
149              ]],
150              [[
151                    extern struct sockaddr *ps;
152                    return ps->sa_len;
153              ]]
154          )],
155          [isc_cv_platform_havesalen=yes],
156          [isc_cv_platform_havesalen=no]
157    )]
158)
159case "$isc_cv_platform_havesalen" in
160 yes)
161    AC_DEFINE([ISC_PLATFORM_HAVESALEN], [1],
162           [struct sockaddr has sa_len?])
163esac
164
165AC_ARG_ENABLE(
166    [ipv6],
167    [AS_HELP_STRING(
168          [--enable-ipv6],
169          [s use IPv6?]
170    )]
171)
172
173case "$enable_ipv6" in
174 yes|''|autodetect)
175    case "$host" in
176     powerpc-ibm-aix4*)
177          ;;
178     *)
179          AC_DEFINE([WANT_IPV6], [1], [configure --enable-ipv6])
180          ;;
181    esac
182    ;;
183 no)
184    ;;
185esac
186
187
188dnl [Bug 1984] ntp/libisc fails to compile on OS X 10.7 (Lion)
189case "$host" in
190 *-*-darwin*)
191    AC_DEFINE([__APPLE_USE_RFC_3542], [1], [Are we _special_?])
192esac
193
194
195AC_CACHE_CHECK(
196    [for IPv6 structures],
197    [isc_cv_found_ipv6],
198    [AC_COMPILE_IFELSE(
199          [AC_LANG_PROGRAM(
200              [[
201                    #include <sys/types.h>
202                    #include <sys/socket.h>
203                    #include <netinet/in.h>
204              ]],
205              [[
206                    struct sockaddr_in6 sin6;
207              ]]
208          )],
209          [isc_cv_found_ipv6=yes],
210          [isc_cv_found_ipv6=no]
211    )]
212)
213
214#
215# See whether IPv6 support is provided via a Kame add-on.
216# This is done before other IPv6 linking tests so LIBS is properly set.
217#
218AC_MSG_CHECKING([for Kame IPv6 support])
219AC_ARG_WITH(
220    [kame],
221    [AS_HELP_STRING(
222          [--with-kame],
223          [- =/usr/local/v6]
224    )],
225    [use_kame="$withval"],
226    [use_kame="no"]
227)
228case "$use_kame" in
229 no)
230    ;;
231 yes)
232    kame_path=/usr/local/v6
233    ;;
234 *)
235    kame_path="$use_kame"
236    ;;
237esac
238case "$use_kame" in
239 no)
240    AC_MSG_RESULT([no])
241    ;;
242 *)
243    if test -f $kame_path/lib/libinet6.a; then
244          AC_MSG_RESULT([$kame_path/lib/libinet6.a])
245          LIBS="-L$kame_path/lib -linet6 $LIBS"
246    else
247          AC_MSG_ERROR([$kame_path/lib/libinet6.a not found.
248
249Please choose the proper path with the following command:
250
251    configure --with-kame=PATH
252])
253    fi
254    ;;
255esac
256
257#
258# Whether netinet6/in6.h is needed has to be defined in isc/platform.h.
259# Including it on Kame-using platforms is very bad, though, because
260# Kame uses #error against direct inclusion.   So include it on only
261# the platform that is otherwise broken without it -- BSD/OS 4.0 through 4.1.
262# This is done before the in6_pktinfo check because that's what
263# netinet6/in6.h is needed for.
264#
265case "$host" in
266 *-bsdi4.[[01]]*)
267    AC_DEFINE([ISC_PLATFORM_NEEDNETINET6IN6H], [1],
268          [Do we need netinet6/in6.h?])
269    isc_netinet6in6_hack="#include <netinet6/in6.h>"
270    ;;
271 *)
272    isc_netinet6in6_hack=""
273    ;;
274esac
275
276#
277# This is similar to the netinet6/in6.h issue.
278#
279case "$host" in
280 *-sco-sysv*uw*|*-*-sysv*UnixWare*|*-*-sysv*OpenUNIX*)
281    AC_DEFINE([ISC_PLATFORM_FIXIN6ISADDR], [1],
282          [Do we need to fix in6isaddr?])
283    isc_netinetin6_hack="#include <netinet/in6.h>"
284    ;;
285 *)
286    isc_netinetin6_hack=""
287    ;;
288esac
289
290
291case "$isc_cv_found_ipv6" in
292 yes)
293    AC_DEFINE([ISC_PLATFORM_HAVEIPV6], [1], [have IPv6?])
294    AC_CACHE_CHECK(
295          [for in6_pktinfo],
296          [isc_cv_have_in6_pktinfo],
297          [AC_COMPILE_IFELSE(
298              [AC_LANG_PROGRAM(
299                    [[
300                        #include <sys/types.h>
301                        #include <sys/socket.h>
302                        #include <netinet/in.h>
303                        $isc_netinetin6_hack
304                        $isc_netinet6in6_hack
305                    ]],
306                    [[
307                        struct in6_pktinfo xyzzy;
308                    ]]
309              )],
310              [isc_cv_have_in6_pktinfo=yes],
311              [isc_cv_have_in6_pktinfo=no]
312          )]
313    )
314    case "$isc_cv_have_in6_pktinfo" in
315     yes)
316          AC_DEFINE([ISC_PLATFORM_HAVEIN6PKTINFO], [1],
317                    [have struct in6_pktinfo?])
318    esac
319
320
321    # HMS: Use HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID instead?
322    AC_CACHE_CHECK(
323          [for sockaddr_in6.sin6_scope_id],
324          [isc_cv_have_sin6_scope_id],
325          [AC_COMPILE_IFELSE(
326              [AC_LANG_PROGRAM(
327                    [[
328                        #include <sys/types.h>
329                        #include <sys/socket.h>
330                        #include <netinet/in.h>
331                        $isc_netinetin6_hack
332                        $isc_netinet6in6_hack
333                    ]],
334                    [[
335                        struct sockaddr_in6 xyzzy;
336                        xyzzy.sin6_scope_id = 0;
337                    ]]
338              )],
339              [isc_cv_have_sin6_scope_id=yes],
340              [isc_cv_have_sin6_scope_id=no]
341          )]
342    )
343
344    case "$isc_cv_have_sin6_scope_id" in
345     yes)
346          AC_DEFINE([ISC_PLATFORM_HAVESCOPEID], [1], [sin6_scope_id?])
347    esac
348esac
349
350
351# We need this check run even without isc_cv_found_ipv6=yes
352
353AC_CACHE_CHECK(
354    [for in6addr_any],
355    [isc_cv_in6addr_any_links],
356    [
357          SAVED_LIBS="$LIBS"
358          LIBS="$LDADD_LIBNTP $LIBS"
359          AC_LINK_IFELSE(
360              [AC_LANG_PROGRAM(
361                    AC_INCLUDES_DEFAULT [[
362                        #include <sys/socket.h>
363                        #include <netinet/in.h>
364                        $isc_netinetin6_hack
365                        $isc_netinet6in6_hack
366                    ]],
367                    [[
368                        printf("%x", in6addr_any.s6_addr[15]);
369                    ]]
370              )],
371              [isc_cv_in6addr_any_links=yes],
372              [isc_cv_in6addr_any_links=no]
373          )
374          LIBS="$SAVED_LIBS"
375          AS_UNSET([SAVED_LIBS])
376    ]
377)
378
379case "$isc_cv_in6addr_any_links" in
380 no)
381    AC_DEFINE([ISC_PLATFORM_NEEDIN6ADDRANY], [1], [missing in6addr_any?])
382esac
383
384
385AC_CACHE_CHECK(
386    [for struct if_laddrconf],
387    [isc_cv_struct_if_laddrconf],
388    [AC_COMPILE_IFELSE(
389          [AC_LANG_PROGRAM(
390              [[
391                    #include <sys/types.h>
392                    #include <net/if6.h>
393              ]],
394              [[
395                    struct if_laddrconf a;
396              ]]
397          )],
398          [isc_cv_struct_if_laddrconf=yes],
399          [isc_cv_struct_if_laddrconf=no]
400    )]
401)
402
403case "$isc_cv_struct_if_laddrconf" in
404 yes)
405    AC_DEFINE([ISC_PLATFORM_HAVEIF_LADDRCONF], [1],
406          [have struct if_laddrconf?])
407esac
408
409AC_CACHE_CHECK(
410    [for struct if_laddrreq],
411    isc_cv_struct_if_laddrreq,
412    [AC_COMPILE_IFELSE(
413          [AC_LANG_PROGRAM(
414              [[
415                    #include <sys/types.h>
416                    #include <net/if6.h>
417              ]],
418              [[
419                    struct if_laddrreq a;
420              ]]
421          )],
422          [isc_cv_struct_if_laddrreq=yes],
423          [isc_cv_struct_if_laddrreq=no]
424    )]
425)
426
427case "$isc_cv_struct_if_laddrreq" in
428 yes)
429    AC_DEFINE([ISC_PLATFORM_HAVEIF_LADDRREQ], [1],
430          [have struct if_laddrreq?])
431esac
432
433AC_CACHE_CHECK(
434    [for multicast IP support],
435    [ntp_cv_multicast],
436    [
437          ntp_cv_multicast=no
438          case "$host" in
439           i386-sequent-sysv4)
440              ;;
441           *)
442              AC_COMPILE_IFELSE(
443                    [AC_LANG_PROGRAM(
444                        [[
445                              #ifdef HAVE_NETINET_IN_H
446                              # include <netinet/in.h>
447                              #endif
448                        ]],
449                        [[
450                              struct ip_mreq ipmr;
451                              ipmr.imr_interface.s_addr = 0;
452                        ]]
453                    )],
454                    [ntp_cv_multicast=yes],
455                    []
456              )
457              ;;
458          esac
459    ]
460)
461case "$ntp_cv_multicast" in
462 yes)
463    AC_DEFINE([MCAST], [1], [Does the target support multicast IP?])
464    AC_CACHE_CHECK(
465          [arg type needed for setsockopt() IP*_MULTICAST_LOOP],
466          [ntp_cv_typeof_ip_multicast_loop],
467          [
468              case "$host" in
469               *-*-netbsd*|*-*-*linux*)
470                    ntp_cv_typeof_ip_multicast_loop=u_int
471                    ;;
472               *)
473                    ntp_cv_typeof_ip_multicast_loop=u_char
474                    ;;
475              esac
476          ]
477    )
478    AC_DEFINE_UNQUOTED([TYPEOF_IP_MULTICAST_LOOP],
479          [$ntp_cv_typeof_ip_multicast_loop],
480          [What type to use for setsockopt])
481esac
482
483AC_ARG_ENABLE(
484    [getifaddrs],
485    [AS_HELP_STRING(
486          [--enable-getifaddrs],
487          [+ Enable the use of getifaddrs() [[yes|no]].]
488    )],
489    [want_getifaddrs="$enableval"],
490    [want_getifaddrs="yes"]
491)
492
493case $want_getifaddrs in
494 glibc)
495    AC_MSG_WARN([--enable-getifaddrs=glibc is no longer required])
496esac
497case $want_getifaddrs in
498 no)
499    ;;
500 *)
501    SAVED_LIBS="$LIBS"
502    LIBS="$LDADD_LIBNTP $LIBS"
503    AC_CHECK_FUNCS([getifaddrs])
504    LIBS="$SAVED_LIBS"
505    AS_UNSET([SAVED_LIBS])
506    ;;
507esac
508
509#
510# Check for if_nametoindex() for IPv6 scoped addresses support
511#
512case "$host" in
513 *-hp-hpux*)
514    AC_SEARCH_LIBS([if_nametoindex], [ipv6])
515esac
516SAVED_LIBS="$LIBS"
517LIBS="$LDADD_LIBNTP $LIBS"
518AC_CHECK_FUNCS([if_nametoindex])
519LIBS="$SAVED_LIBS"
520AS_UNSET([SAVED_LIBS])
521case "$ac_cv_func_if_nametoindex" in
522 yes)
523          AC_DEFINE([ISC_PLATFORM_HAVEIFNAMETOINDEX], [1],
524              [ISC: do we have if_nametoindex()?])
525esac
526
527])dnl
528dnl ======================================================================
529