dnl pcap.h winds up in wierd places.

AC_DEFUN(AC_WF_CHECK_PCAP_HEADER_DIR,
          [AC_MSG_CHECKING(for pcap header directory)
		  ac_pcap_header_dir="none"
		  for dir in $prefix/include /include /usr/include /usr/local/include /include/pcap /usr/include/pcap /usr/local/include/pcap
		  do
		    if test -f "$dir/pcap.h" ; then
			  ac_pcap_header_dir=$dir
		    fi
	  done
		  
	  if test $ac_pcap_header_dir = "none" ; then
          AC_MSG_ERROR([
I cannot find the pcap header file anywhere. Perhaps you did not install 
the pcap package, or you did not install its development header files.], 1)
	  fi
	  
	  AC_MSG_RESULT($ac_pcap_header_dir)])

dnl on some broken systems /usr/local/lib is not in the linker's
dnl default path. so we'll sift about.

AC_DEFUN(AC_WF_CHECK_PCAP_LIB_DIR,
          [AC_MSG_CHECKING(for pcap library directory)
		  ac_pcap_lib_dir="none"
		  for dir in $prefix/lib /lib /usr/lib /usr/local/lib
		  do
		    if test -f "$dir/libpcap.a" ; then
			  ac_pcap_lib_dir=$dir
		    fi
	  done
		  
	  if test $ac_pcap_lib_dir = "none" ; then
                    AC_MSG_ERROR([
I cannot find the pcap library anywhere. Perhaps you did not install
the pcap package, or you did not install its development header files.], 1)
	  fi

	  AC_MSG_RESULT($ac_pcap_lib_dir)])

AC_DEFUN(AC_WF_TRY_PRI_MACROS,
[AC_MSG_CHECKING(for stdint conversion macros)
 AC_TRY_COMPILE([#include <stdio.h>
                 #include <stdlib.h>
                 #include <inttypes.h>
], [uint32_t t=1; printf("%"PRIu32, t);], 
                        [AC_MSG_RESULT(found)
                        have_primacros="yes"],
                        AC_MSG_RESULT(not found))])

AC_DEFUN(AC_WF_CHECK_KILL_SIGNAL_DETECT,
[AC_MSG_CHECKING(if kill(0, pid) can be used to detect a process)
AC_TRY_RUN([
/* Check the behaviour of kill(pid, 0).
 * We expect it to return 0 for an existing process that we can
 * signal, and < 0 otherwise.
 */

#include <stdlib.h> 
#include <stdio.h>

#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    pid_t child_pid;
    int kill_existing, kill_nonexisting;
    int wait_status;

    child_pid = fork();

    if (child_pid == -1) {
        perror("fork");
        exit(1);
    } else if (child_pid == 0) {
	(void)sleep(3600);
        _exit(0);
    }

    kill_existing = kill(child_pid, 0);

    (void)kill(child_pid, SIGTERM);
    (void)wait(&wait_status);

    kill_nonexisting = kill(child_pid, 0);

    if (kill_existing == 0 && kill_nonexisting < 0)
        exit(0); /* the behaviour we expect */
    else
        fprintf(stderr, "error: returned (%d,%d); expecting (0,-1)\n",
                kill_existing, kill_nonexisting);

    exit(1);
}
], [AC_DEFINE(KILL_SIGNAL_DETECT, 1, [kill(pid, 0) can be used to detect a process we can signal]) AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])


AC_DEFUN(AC_WF_CHECK_BPF_IMMEDIATE,
[AC_MSG_CHECKING(for bpf immediate ioctl)
 AC_TRY_COMPILE([#include <stdio.h>
                 #include <stdlib.h>
                 #include <sys/types.h>
                 #include <sys/time.h>
                 #include <sys/ioctl.h>
                 #include <net/bpf.h>
                 #include <net/bpfdesc.h>
], [    ioctl(0, BIOCIMMEDIATE, NULL);], 
                        [AC_MSG_RESULT(found)
                        AC_DEFINE(HAVE_BPF_IMMEDIATE, 1, [have BPF_IMMEDIATE])],
                        AC_MSG_RESULT(not found))])


syntax highlighted by Code2HTML, v. 0.9.1