* sockpfaf.m4 (gl_SOCKET_FAMILIES): Use gl_HEADER_SYS_SOCKET
[gnulib.git] / m4 / sockpfaf.m4
1 # sockpfaf.m4 serial 4
2 dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl Test for some common socket protocol families (PF_INET, PF_INET6, ...)
8 dnl and some common address families (AF_INET, AF_INET6, ...).
9 dnl This test assumes that a system supports an address family if and only if
10 dnl it supports the corresponding protocol family.
11
12 dnl From Bruno Haible.
13
14 AC_DEFUN([gl_SOCKET_FAMILIES],
15 [
16   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
17   AC_CHECK_HEADERS_ONCE([netinet/in.h])
18
19   AC_MSG_CHECKING(for IPv4 sockets)
20   AC_CACHE_VAL(gl_cv_socket_ipv4,
21     [AC_TRY_COMPILE([#include <sys/types.h>
22 #ifdef HAVE_SYS_SOCKET_H
23 #include <sys/socket.h>
24 #endif
25 #ifdef HAVE_NETINET_IN_H
26 #include <netinet/in.h>
27 #endif
28 #ifdef HAVE_WINSOCK2_H
29 #include <winsock2.h>
30 #endif],
31 [int x = AF_INET; struct in_addr y; struct sockaddr_in z;],
32        gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)])
33   AC_MSG_RESULT($gl_cv_socket_ipv4)
34   if test $gl_cv_socket_ipv4 = yes; then
35     AC_DEFINE(HAVE_IPV4, 1, [Define to 1 if <sys/socket.h> defines AF_INET.])
36   fi
37
38   AC_MSG_CHECKING(for IPv6 sockets)
39   AC_CACHE_VAL(gl_cv_socket_ipv6,
40     [AC_TRY_COMPILE([#include <sys/types.h>
41 #ifdef HAVE_SYS_SOCKET_H
42 #include <sys/socket.h>
43 #endif
44 #ifdef HAVE_NETINET_IN_H
45 #include <netinet/in.h>
46 #endif
47 #ifdef HAVE_WINSOCK2_H
48 #include <winsock2.h>
49 #endif],
50 [int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;],
51        gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)])
52   AC_MSG_RESULT($gl_cv_socket_ipv6)
53   if test $gl_cv_socket_ipv6 = yes; then
54     AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if <sys/socket.h> defines AF_INET6.])
55   fi
56 ])