1 | dnl Various checks for socket support and macros. |
---|
2 | dnl |
---|
3 | dnl This is a collection of various Autoconf macros for checking networking |
---|
4 | dnl and socket properties. The macros provided are: |
---|
5 | dnl |
---|
6 | dnl RRA_FUNC_GETADDRINFO_ADDRCONFIG |
---|
7 | dnl RRA_MACRO_IN6_ARE_ADDR_EQUAL |
---|
8 | dnl RRA_MACRO_SA_LEN |
---|
9 | dnl |
---|
10 | dnl They use a separate internal source macro to make the code easier to read. |
---|
11 | dnl |
---|
12 | dnl Copyright 2008, 2009 Board of Trustees, Leland Stanford Jr. University |
---|
13 | dnl Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009 |
---|
14 | dnl by Internet Systems Consortium, Inc. ("ISC") |
---|
15 | dnl Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
---|
16 | dnl 2002, 2003 by The Internet Software Consortium and Rich Salz |
---|
17 | dnl |
---|
18 | dnl See LICENSE for licensing terms. |
---|
19 | |
---|
20 | dnl Source used by RRA_FUNC_GETADDRINFO_ADDRCONFIG. |
---|
21 | AC_DEFUN([_RRA_FUNC_GETADDRINFO_ADDRCONFIG_SOURCE], [[ |
---|
22 | #include <netdb.h> |
---|
23 | #include <stdio.h> |
---|
24 | #include <sys/socket.h> |
---|
25 | |
---|
26 | int |
---|
27 | main(void) { |
---|
28 | struct addrinfo hints, *ai; |
---|
29 | |
---|
30 | memset(&hints, 0, sizeof(hints)); |
---|
31 | hints.ai_family = AF_UNSPEC; |
---|
32 | hints.ai_socktype = SOCK_STREAM; |
---|
33 | hints.ai_flags = AI_ADDRCONFIG; |
---|
34 | return (getaddrinfo("localhost", NULL, &hints, &ai) != 0); |
---|
35 | } |
---|
36 | ]]) |
---|
37 | |
---|
38 | dnl Check whether the AI_ADDRCONFIG flag works properly with getaddrinfo. |
---|
39 | dnl If so, set HAVE_GETADDRINFO_ADDRCONFIG. |
---|
40 | AC_DEFUN([RRA_FUNC_GETADDRINFO_ADDRCONFIG], |
---|
41 | [AC_CACHE_CHECK([for working AI_ADDRCONFIG flag], |
---|
42 | [rra_cv_func_getaddrinfo_addrconfig_works], |
---|
43 | [AC_RUN_IFELSE(AC_LANG_SOURCE([_RRA_FUNC_GETADDRINFO_ADDRCONFIG_SOURCE]), |
---|
44 | [rra_cv_func_getaddrinfo_addrconfig_works=yes], |
---|
45 | [rra_cv_func_getaddrinfo_addrconfig_works=no], |
---|
46 | [rra_cv_func_getaddrinfo_addrconfig_works=no])]) |
---|
47 | AS_IF([test x"$rra_cv_func_getaddrinfo_addrconfig_works" = xyes], |
---|
48 | [AC_DEFINE([HAVE_GETADDRINFO_ADDRCONFIG], 1, |
---|
49 | [Define if the AI_ADDRCONFIG flag works with getaddrinfo.])])]) |
---|
50 | |
---|
51 | dnl Source used by INN_IN6_EQ_BROKEN. Test borrowed from a bug report by |
---|
52 | dnl tmoestl@gmx.net for glibc. |
---|
53 | AC_DEFUN([_RRA_MACRO_IN6_ARE_ADDR_EQUAL_SOURCE], [[ |
---|
54 | #include <sys/types.h> |
---|
55 | #include <sys/socket.h> |
---|
56 | #include <netinet/in.h> |
---|
57 | #include <arpa/inet.h> |
---|
58 | |
---|
59 | int |
---|
60 | main (void) |
---|
61 | { |
---|
62 | struct in6_addr a; |
---|
63 | struct in6_addr b; |
---|
64 | |
---|
65 | inet_pton(AF_INET6, "fe80::1234:5678:abcd", &a); |
---|
66 | inet_pton(AF_INET6, "fe80::1234:5678:abcd", &b); |
---|
67 | return IN6_ARE_ADDR_EQUAL(&a, &b) ? 0 : 1; |
---|
68 | } |
---|
69 | ]]) |
---|
70 | |
---|
71 | dnl Check whether the IN6_ARE_ADDR_EQUAL macro is broken (like glibc 2.1.3) or |
---|
72 | dnl missing. |
---|
73 | AC_DEFUN([RRA_MACRO_IN6_ARE_ADDR_EQUAL], |
---|
74 | [AC_CACHE_CHECK([whether IN6_ARE_ADDR_EQUAL macro is broken], |
---|
75 | [rra_cv_in6_are_addr_equal_broken], |
---|
76 | [AC_RUN_IFELSE([AC_LANG_SOURCE([_RRA_MACRO_IN6_ARE_ADDR_EQUAL_SOURCE])], |
---|
77 | [rra_cv_in6_are_addr_equal_broken=no], |
---|
78 | [rra_cv_in6_are_addr_equal_broken=yes], |
---|
79 | [rra_cv_in6_are_addr_equal_broken=yes])]) |
---|
80 | AS_IF([test x"$rra_cv_in6_are_addr_equal_broken" = xyes], |
---|
81 | [AC_DEFINE([HAVE_BROKEN_IN6_ARE_ADDR_EQUAL], 1, |
---|
82 | [Define if your IN6_ARE_ADDR_EQUAL macro is broken.])])]) |
---|
83 | |
---|
84 | dnl Source used by RRA_MACRO_SA_LEN. |
---|
85 | AC_DEFUN([_RRA_MACRO_SA_LEN_SOURCE], [[ |
---|
86 | #include <sys/types.h> |
---|
87 | #include <sys/socket.h> |
---|
88 | |
---|
89 | int |
---|
90 | main(void) |
---|
91 | { |
---|
92 | struct sockaddr sa; |
---|
93 | int x = SA_LEN(&sa); |
---|
94 | } |
---|
95 | ]]) |
---|
96 | |
---|
97 | dnl Check whether the SA_LEN macro is available. This should give the length |
---|
98 | dnl of a struct sockaddr regardless of type. |
---|
99 | AC_DEFUN([RRA_MACRO_SA_LEN], |
---|
100 | [AC_CACHE_CHECK([for SA_LEN macro], [rra_cv_sa_len_macro], |
---|
101 | [AC_LINK_IFELSE([AC_LANG_SOURCE([_RRA_MACRO_SA_LEN_SOURCE])], |
---|
102 | [rra_cv_sa_len_macro=yes], |
---|
103 | [rra_cv_sa_len_macro=no])]) |
---|
104 | AS_IF([test "$rra_cv_sa_len_macro" = yes], |
---|
105 | [AC_DEFINE([HAVE_SA_LEN], 1, |
---|
106 | [Define if <sys/socket.h> defines the SA_LEN macro])])]) |
---|