dnl Process this file with autoconf to produce a configure script.
dnl 
dnl $USAGI: configure.in,v 1.9 2001/01/23 02:58:18 yoshfuji Exp $
dnl 
AC_INIT(ping6.c)
AC_CONFIG_HEADER(config.h)
AC_PREFIX_DEFAULT(/usr/local/v6)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL

dnl Checks for libraries.
dnl Replace `main' with a function in -lresolv:
AC_CHECK_LIB(resolv, main)

ipv6=yes
IN6_GUESS_STACK(ipv6, ipv6libdir, ipv6lib)
CFLAGS="$CFLAGS $INET6_CFLAGS"
LIBS="$INET6_LIBS $LIBS"

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h malloc.h sys/file.h sys/ioctl.h sys/time.h syslog.h unistd.h)
AC_CHECK_HEADERS(getopt.h)
AC_CHECK_HEADERS(netinet/ip6.h netinet/icmp6.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_TYPE_UID_T

AC_MSG_CHECKING([which to include to define IPV6_RECVERR])
AC_EGREP_CPP(%%%yes%%%, [dnl
#include <netinet/in.h>
#ifdef IPV6_RECVERR
%%%yes%%%
#endif
],[	AC_MSG_RESULT([<netinet/in.h>])
	AC_DEFINE(HAVE_IPV6_RECVERR_IN_NETINET_IN_H)
],[	AC_EGREP_CPP(%%%yes%%%, [dnl
#include <linux/in.h>
#ifdef IPV6_RECVERR
%%%yes%%%
#endif
	],[	AC_MSG_RESULT([<linux/in.h>])
		AC_DEFINE(HAVE_IPV6_RECVERR_IN_LINUX_IN_H)
	],[	AC_EGREP_CPP(%%%yes%%%, [dnl
#include <linux/in6.h>
#ifdef IPV6_RECVERR
%%%yes%%%
#endif
		],[	AC_MSG_RESULT([<linux/in6.h>])
			AC_DEFINE(HAVE_IPV6_RECVERR_IN_LINUX_IN6_H)
		],[	AC_MSG_RESULT([not found!?])

		])
	])
])

AC_MSG_CHECKING([whether you have struct ip6_rthdr0{}])
AC_TRY_COMPILE([
#include <netinet/in.h>
#include <netinet/ip6.h>
],[
	size_t x = sizeof(struct ip6_rthdr0);
],[	AC_DEFINE(HAVE_STRUCT_IP6_RTHDR0)
	AC_TRY_COMPILE([
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
	],[
int main(){
	struct ip6_rthdr0 rth0;
	size_t s = sizeof(rth0.ip6r0_addr);
}
	],[
		AC_MSG_RESULT([yes, RFC2292])
		AC_DEFINE(HAVE_STRUCT_IP6_RTHDR0_IP6R0_ADDR)
	],[	AC_MSG_RESULT([yes, RFC2292bis])
	])
],[	AC_MSG_RESULT(no)
])

AC_MSG_CHECKING([whether you have struct icmp6_nodeinfo{}])
AC_TRY_COMPILE([
#include <netinet/icmp6.h>
],[
	size_t x = sizeof(struct icmp6_nodeinfo);
],[	AC_MSG_RESULT(yes)
	AC_DEFINE(HAVE_STRUCT_ICMP6_NODEINFO)
],[	AC_MSG_RESULT(no)
])

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(getopt_long)
AC_CHECK_FUNCS(gethostname gettimeofday select socket strdup strerror strtod strtol)
AC_CHECK_FUNCS(inet6_rthdr_init)

AC_MSG_CHECKING([getaddrinfo() with ICMPv6])
AC_TRY_RUN([
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
int main(){
	struct addrinfo hints, *res0;
	int ret = 0;

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = PF_INET6;
	hints.ai_socktype = SOCK_RAW;
	hints.ai_protocol = IPPROTO_ICMPV6;
	if (getaddrinfo("::1", NULL, &hints, &res0)){
		ret = 1;
	}
	else {
		if (res0->ai_family != PF_INET6 ||
		    res0->ai_socktype != SOCK_RAW ||
		    res0->ai_protocol != IPPROTO_ICMPV6)
			ret = 1;
		freeaddrinfo(res0);
	}
	return ret;
}
],[	AC_MSG_RESULT([yes])
	AC_DEFINE(GAI_OK_WITH_RAW_ICMPV6)
],[	AC_MSG_RESULT([no])
],[	AC_MSG_RESULT([unknown])
])

AC_OUTPUT(Makefile)
