Debian Codegraph @

m4/sockpfaf.m4

raw
1 # sockpfaf.m4
2 # serial 11
3 dnl Copyright (C) 2004, 2006, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl Test for some common socket protocol families (PF_INET, PF_INET6, ...)
10 dnl and some common address families (AF_INET, AF_INET6, ...).
11 dnl This test assumes that a system supports an address family if and only if
12 dnl it supports the corresponding protocol family.
13
14 dnl From Bruno Haible.
15
16 AC_DEFUN([gl_SOCKET_FAMILIES],
17 [
18 AC_REQUIRE([gl_SYS_SOCKET_H])
19 AC_CHECK_HEADERS_ONCE([netinet/in.h])
20
21 AC_CACHE_CHECK([for IPv4 sockets],
22 [gl_cv_socket_ipv4],
23 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
24 #ifdef HAVE_SYS_SOCKET_H
25 #include <sys/socket.h>
26 #endif
27 #ifdef HAVE_NETINET_IN_H
28 #include <netinet/in.h>
29 #endif
30 #ifdef HAVE_WINSOCK2_H
31 #include <winsock2.h>
32 #endif]],
33 [[int x = AF_INET; struct in_addr y; struct sockaddr_in z;
34 if (&x && &y && &z) return 0;]])],
35 gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)])
36 if test $gl_cv_socket_ipv4 = yes; then
37 AC_DEFINE([HAVE_IPV4], [1], [Define to 1 if <sys/socket.h> defines AF_INET.])
38 fi
39
40 AC_CACHE_CHECK([for IPv6 sockets],
41 [gl_cv_socket_ipv6],
42 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
43 #ifdef HAVE_SYS_SOCKET_H
44 #include <sys/socket.h>
45 #endif
46 #ifdef HAVE_NETINET_IN_H
47 #include <netinet/in.h>
48 #endif
49 #ifdef HAVE_WINSOCK2_H
50 #include <winsock2.h>
51 #endif
52 #ifdef HAVE_WS2TCPIP_H
53 #include <ws2tcpip.h>
54 #endif]],
55 [[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;
56 if (&x && &y && &z) return 0;]])],
57 gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)])
58 if test $gl_cv_socket_ipv6 = yes; then
59 AC_DEFINE([HAVE_IPV6], [1], [Define to 1 if <sys/socket.h> defines AF_INET6.])
60 fi
61 ])
62
63 AC_DEFUN([gl_SOCKET_FAMILY_UNIX],
64 [
65 AC_REQUIRE([gl_SYS_SOCKET_H])
66 AC_CHECK_HEADERS_ONCE([sys/un.h])
67
68 dnl Windows versions released after 2017 may have support for AF_UNIX.
69 dnl Including it requires types from <winsock2.h> to be defined.
70 dnl <https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/>.
71 if test "$ac_cv_header_winsock2_h" = yes; then
72 AC_CHECK_HEADERS([afunix.h], [], [], [#include <winsock2.h>])
73 fi
74
75 AC_CACHE_CHECK([for UNIX domain sockets],
76 [gl_cv_socket_unix],
77 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
78 #ifdef HAVE_SYS_SOCKET_H
79 #include <sys/socket.h>
80 #endif
81 #ifdef HAVE_SYS_UN_H
82 #include <sys/un.h>
83 #endif
84 #ifdef HAVE_WINSOCK2_H
85 #include <winsock2.h>
86 #endif
87 #ifdef HAVE_AFUNIX_H
88 #include <afunix.h>
89 #endif]],
90 [[int x = AF_UNIX; struct sockaddr_un y;
91 if (&x && &y) return 0;]])],
92 gl_cv_socket_unix=yes, gl_cv_socket_unix=no)])
93 if test $gl_cv_socket_unix = yes; then
94 AC_DEFINE([HAVE_UNIXSOCKET], [1], [Define to 1 if <sys/socket.h> defines AF_UNIX.])
95 fi
96 ])