1dnl Various checks for UNIX domain socket support and macros.
2dnl $Id: socket-unix.m4 10246 2018-02-16 21:12:42Z iulius $
3dnl
4dnl This is a collection of various Autoconf macros for checking UNIX domain
5dnl socket properties.  The macros provided are:
6dnl
7dnl     INN_MACRO_SUN_LEN
8dnl     INN_SYS_UNIX_SOCKETS
9dnl
10dnl They use a separate internal source macro to make the code easier to read.
11dnl
12dnl The canonical version of this file is maintained in the rra-c-util
13dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
14dnl
15dnl Copyright 2009
16dnl     The Board of Trustees of the Leland Stanford Junior University
17dnl Copyright 2004-2009 Internet Systems Consortium, Inc. ("ISC")
18dnl Copyright 1991, 1994-2003 The Internet Software Consortium and Rich Salz
19dnl
20dnl This code is derived from software contributed to the Internet Software
21dnl Consortium by Rich Salz.
22dnl
23dnl Permission to use, copy, modify, and distribute this software for any
24dnl purpose with or without fee is hereby granted, provided that the above
25dnl copyright notice and this permission notice appear in all copies.
26dnl
27dnl THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
28dnl REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
29dnl MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
30dnl SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
32dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
33dnl IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34dnl
35dnl SPDX-License-Identifier: ISC
36
37dnl Source used by INN_MACRO_SUN_LEN.
38AC_DEFUN([_INN_MACRO_SUN_LEN_SOURCE], [[
39#include <sys/types.h>
40#include <sys/un.h>
41
42int
43main(void)
44{
45    struct sockaddr_un s_un;
46    int i = SUN_LEN(&s_un);
47}
48]])
49
50dnl Check for SUN_LEN, which returns the size of a struct sockaddr_un.  Sets
51dnl HAVE_SUN_LEN if the macro is available.
52AC_DEFUN([INN_MACRO_SUN_LEN],
53[AC_CACHE_CHECK([for SUN_LEN macro], [inn_cv_sun_len_macro],
54   [AC_LINK_IFELSE([AC_LANG_SOURCE([_INN_MACRO_SUN_LEN_SOURCE])],
55       [inn_cv_sun_len_macro=yes],
56       [inn_cv_sun_len_macro=no])])
57AS_IF([test x"$inn_cv_sun_len_macro" = xyes],
58   [AC_DEFINE([HAVE_SUN_LEN], 1,
59       [Define if <sys/un.h> defines the SUN_LEN macro.])])])
60
61dnl Source used by INN_SYS_UNIX_SOCKETS.
62AC_DEFUN([_INN_SYS_UNIX_SOCKETS], [[
63#include <sys/types.h>
64#include <sys/socket.h>
65#ifndef AF_UNIX
66error: No UNIX domain sockets!
67#endif
68]])
69
70dnl Check if UNIX domain sockets are supported.  Assume that they are if
71dnl AF_UNIX is set in <sys/socket.h>.  This loses on really old versions of
72dnl Linux, where AF_UNIX is available but doesn't work, but we don't care
73dnl about Linux 1.0 any more.
74AC_DEFUN([INN_SYS_UNIX_SOCKETS],
75[AC_CACHE_CHECK([for UNIX domain sockets], [inn_cv_sys_unix_sockets],
76   [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_INN_SYS_UNIX_SOCKETS])],
77       [inn_cv_sys_unix_sockets=yes],
78       [inn_cv_sys_unix_sockets=no])])
79AS_IF([test x"$inn_cv_sys_unix_sockets" = xyes],
80   [AC_DEFINE([HAVE_UNIX_DOMAIN_SOCKETS], 1,
81       [Define if you have UNIX domain sockets.])])])
82