1# sockpfaf.m4 serial 9
2dnl Copyright (C) 2004, 2006, 2009-2020 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl Test for some common socket protocol families (PF_INET, PF_INET6, ...)
8dnl and some common address families (AF_INET, AF_INET6, ...).
9dnl This test assumes that a system supports an address family if and only if
10dnl it supports the corresponding protocol family.
11
12dnl From Bruno Haible.
13
14AC_DEFUN([gl_SOCKET_FAMILIES],
15[
16  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
17  AC_CHECK_HEADERS_ONCE([netinet/in.h])
18
19  AC_CACHE_CHECK([for IPv4 sockets],
20    [gl_cv_socket_ipv4],
21    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#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 if (&x && &y && &z) return 0;]])],
33       gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)])
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_CACHE_CHECK([for IPv6 sockets],
39    [gl_cv_socket_ipv6],
40    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#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#ifdef HAVE_WS2TCPIP_H
51#include <ws2tcpip.h>
52#endif]],
53[[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;
54 if (&x && &y && &z) return 0;]])],
55       gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)])
56  if test $gl_cv_socket_ipv6 = yes; then
57    AC_DEFINE([HAVE_IPV6], [1], [Define to 1 if <sys/socket.h> defines AF_INET6.])
58  fi
59])
60
61AC_DEFUN([gl_SOCKET_FAMILY_UNIX],
62[
63  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
64  AC_CHECK_HEADERS_ONCE([sys/un.h])
65
66  AC_CACHE_CHECK([for UNIX domain sockets],
67    [gl_cv_socket_unix],
68    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
69#ifdef HAVE_SYS_SOCKET_H
70#include <sys/socket.h>
71#endif
72#ifdef HAVE_SYS_UN_H
73#include <sys/un.h>
74#endif
75#ifdef HAVE_WINSOCK2_H
76#include <winsock2.h>
77#endif]],
78[[int x = AF_UNIX; struct sockaddr_un y;
79 if (&x && &y) return 0;]])],
80       gl_cv_socket_unix=yes, gl_cv_socket_unix=no)])
81  if test $gl_cv_socket_unix = yes; then
82    AC_DEFINE([HAVE_UNIXSOCKET], [1], [Define to 1 if <sys/socket.h> defines AF_UNIX.])
83  fi
84])
85