| 1 |
# -*- Autoconf -*- |
| 2 |
# Process this file with autoconf to produce a configure script. |
| 3 |
|
| 4 |
AC_PREREQ(2.61) |
| 5 |
AC_INIT(arping, 2.29, [email protected]) |
| 6 |
AC_CANONICAL_SYSTEM |
| 7 |
AC_CONFIG_SRCDIR([src/arping.c]) |
| 8 |
AM_INIT_AUTOMAKE |
| 9 |
AM_MAINTAINER_MODE |
| 10 |
AC_CONFIG_HEADER(config.h) |
| 11 |
|
| 12 |
|
| 13 |
# Checks for programs. |
| 14 |
AC_PROG_CC |
| 15 |
AC_PROG_INSTALL |
| 16 |
AC_PROG_MAKE_SET |
| 17 |
|
| 18 |
# Required to define __USE_MISC, which in turn typedefs uint, which |
| 19 |
# is used by libnet headers. |
| 20 |
# This "just works" until running GCC with -std=c99, where uint is |
| 21 |
# no longer defined by default. |
| 22 |
CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE=1" |
| 23 |
|
| 24 |
AC_DEFUN([CHECK_COMPILER_OPTION], [ |
| 25 |
AC_MSG_CHECKING([compiler option $1]) |
| 26 |
OLD_CFLAGS="$CFLAGS" |
| 27 |
CFLAGS="$CFLAGS $1" |
| 28 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], |
| 29 |
[AC_MSG_RESULT(yes)], |
| 30 |
[ |
| 31 |
AC_MSG_RESULT(no)] |
| 32 |
CFLAGS="$OLD_CFLAGS" |
| 33 |
) |
| 34 |
]) |
| 35 |
|
| 36 |
CHECK_COMPILER_OPTION([-std=c99]) |
| 37 |
|
| 38 |
# Checks for header files. |
| 39 |
AC_HEADER_STDC |
| 40 |
AC_CHECK_HEADERS([\ |
| 41 |
arpa/inet.h \ |
| 42 |
getopt.h \ |
| 43 |
netinet/in.h \ |
| 44 |
seccomp.h \ |
| 45 |
stdlib.h \ |
| 46 |
sys/socket.h \ |
| 47 |
time.h \ |
| 48 |
grp.h \ |
| 49 |
sys/time.h \ |
| 50 |
sys/types.h \ |
| 51 |
sys/param.h \ |
| 52 |
sys/capability.h \ |
| 53 |
stdint.h \ |
| 54 |
stddef.h \ |
| 55 |
libnet.h \ |
| 56 |
win32/libnet.h \ |
| 57 |
sys/random.h \ |
| 58 |
net/bpf.h \ |
| 59 |
pwd.h \ |
| 60 |
unistd.h \ |
| 61 |
linux/landlock.h \ |
| 62 |
linux/prctl.h \ |
| 63 |
sys/prctl.h \ |
| 64 |
sys/syscall.h]) |
| 65 |
|
| 66 |
# Checks for libraries. |
| 67 |
AC_CHECK_LIB([m], [sqrt]) |
| 68 |
AC_CHECK_LIB([socket], [socket]) |
| 69 |
AC_CHECK_LIB([nsl], [gethostbyname]) |
| 70 |
AC_CHECK_LIB([cap], [cap_init]) |
| 71 |
AC_CHECK_LIB([seccomp], [seccomp_init]) |
| 72 |
AC_CHECK_LIB([rt], [clock_gettime]) |
| 73 |
AC_CHECK_LIB([net], [libnet_name_resolve], |
| 74 |
[AC_MSG_ERROR([libnet 1.0.x found. Arping 2.x requires libnet 1.1 or newer])]) |
| 75 |
AC_CHECK_LIB([net], [libnet_init], ,[AC_MSG_ERROR([libnet 1.1.x not found])]) |
| 76 |
AC_CHECK_LIB([pcap], [pcap_open_live], ,[AC_MSG_ERROR([libpcap not found])]) |
| 77 |
AC_SEARCH_LIBS([clock_gettime], [rt]) |
| 78 |
|
| 79 |
AC_ARG_ENABLE([seccomp], [Enable seccomp priv drops by default (-z to turn on, -Z for off)], [ |
| 80 |
if test x"$enableval" = x"yes"; then |
| 81 |
if test "$ac_cv_lib_seccomp_seccomp_init" = "no"; then |
| 82 |
AC_MSG_ERROR([--enable-seccomp given but seccomp libraries not present]) |
| 83 |
fi |
| 84 |
AC_DEFINE([DEFAULT_SECCOMP], [1], [Enable seccomp by default]) |
| 85 |
else |
| 86 |
AC_DEFINE([DEFAULT_SECCOMP], [0], [Enable seccomp by default]) |
| 87 |
fi |
| 88 |
], [ |
| 89 |
AC_DEFINE([DEFAULT_SECCOMP], [0], [Disable seccomp by default]) |
| 90 |
]) |
| 91 |
|
| 92 |
# Libnet include file is not optional |
| 93 |
if test ! x$ac_cv_header_libnet_h = xyes; then |
| 94 |
AC_MSG_ERROR([Can't find libnet.h. See INSTALL file for where to get Libnet]) |
| 95 |
fi |
| 96 |
|
| 97 |
# Workaround for Android apparently having the headers, and having the library |
| 98 |
# function, but not having the declaration in sys/random.h and |
| 99 |
# sys/capabilities.h. |
| 100 |
# See issue #49 and #57. |
| 101 |
AC_MSG_CHECKING([if system actually has cap_init]) |
| 102 |
AC_LINK_IFELSE( |
| 103 |
[AC_LANG_PROGRAM( |
| 104 |
[#include<sys/capability.h>], |
| 105 |
[cap_t t = cap_init();] |
| 106 |
)], |
| 107 |
[ |
| 108 |
AC_MSG_RESULT(yes) |
| 109 |
AC_DEFINE([ACTUALLY_HAS_CAP_INIT], [1], [Actually has cap_init()]) |
| 110 |
], |
| 111 |
[AC_MSG_RESULT(no)] |
| 112 |
) |
| 113 |
AC_MSG_CHECKING([if system actually has getrandom]) |
| 114 |
AC_LINK_IFELSE( |
| 115 |
[AC_LANG_PROGRAM( |
| 116 |
[#include<sys/random.h>], |
| 117 |
[ssize_t n = getrandom((void*)0, 16, 0)] |
| 118 |
)], |
| 119 |
[ |
| 120 |
AC_MSG_RESULT(yes) |
| 121 |
AC_DEFINE([ACTUALLY_HAS_GETRANDOM], [1], [Actually has getrandom()]) |
| 122 |
], |
| 123 |
[AC_MSG_RESULT(no)] |
| 124 |
) |
| 125 |
|
| 126 |
AC_MSG_CHECKING([if system has landlock]) |
| 127 |
AC_LINK_IFELSE( |
| 128 |
[AC_LANG_PROGRAM( |
| 129 |
[ |
| 130 |
#define _GNU_SOURCE |
| 131 |
#include<linux/landlock.h> |
| 132 |
#include<sys/syscall.h> |
| 133 |
#include<unistd.h> |
| 134 |
], |
| 135 |
[syscall(SYS_landlock_create_ruleset, 0, 0, 0);] |
| 136 |
)], |
| 137 |
[ |
| 138 |
AC_MSG_RESULT(yes) |
| 139 |
AC_DEFINE([HAS_LANDLOCK], [1], [Has landlock]) |
| 140 |
], |
| 141 |
[AC_MSG_RESULT(no)] |
| 142 |
) |
| 143 |
|
| 144 |
AC_MSG_CHECKING([if NO_NEW_PRIVS exists]) |
| 145 |
AC_LINK_IFELSE( |
| 146 |
[AC_LANG_PROGRAM( |
| 147 |
[ |
| 148 |
#define _GNU_SOURCE |
| 149 |
#include<linux/prctl.h> |
| 150 |
#include<sys/prctl.h> |
| 151 |
], |
| 152 |
[prctl(PR_SET_NO_NEW_PRIVS, 1L, 0L, 0L, 0L);] |
| 153 |
)], |
| 154 |
[ |
| 155 |
AC_MSG_RESULT(yes) |
| 156 |
AC_DEFINE([HAS_NO_NEW_PRIVS], [1], [Has NO_NEW_PRIVS]) |
| 157 |
], |
| 158 |
[AC_MSG_RESULT(no)] |
| 159 |
) |
| 160 |
|
| 161 |
# Checks for typedefs, structures, and compiler characteristics. |
| 162 |
AC_C_CONST |
| 163 |
AC_HEADER_TIME |
| 164 |
AC_C_VOLATILE |
| 165 |
AC_TYPE_UINT8_T |
| 166 |
AC_TYPE_UINT16_T |
| 167 |
AC_TYPE_UINT32_T |
| 168 |
AC_TYPE_UINT64_T |
| 169 |
|
| 170 |
# Checks for library functions. |
| 171 |
AC_PROG_GCC_TRADITIONAL |
| 172 |
AC_FUNC_SELECT_ARGTYPES |
| 173 |
AC_FUNC_SETVBUF_REVERSED |
| 174 |
AC_TYPE_SIGNAL |
| 175 |
AC_CHECK_FUNCS([gettimeofday memset select strchr strdup strerror strstr \ |
| 176 |
getifaddrs cap_init pcap_create pcap_list_tstamp_types pcap_set_immediate_mode \ |
| 177 |
pledge unveil pcap_findalldevs getrandom strtoll]) |
| 178 |
|
| 179 |
if test x$ac_cv_func_getifaddrs = xyes; then |
| 180 |
AC_LIBOBJ([findif_getifaddrs]) |
| 181 |
else |
| 182 |
case "$target_os" in |
| 183 |
*linux*) |
| 184 |
AC_LIBOBJ([findif_linux]) |
| 185 |
;; |
| 186 |
*freebsd*|*openbsd*|*darwin*) |
| 187 |
AC_LIBOBJ([findif_sysctl]) |
| 188 |
;; |
| 189 |
*solaris*) |
| 190 |
AC_LIBOBJ([findif_bsdroute]) |
| 191 |
;; |
| 192 |
*) |
| 193 |
AC_LIBOBJ([findif_other]) |
| 194 |
;; |
| 195 |
esac |
| 196 |
fi |
| 197 |
|
| 198 |
AC_CACHE_CHECK([for libnet_init signature has const], |
| 199 |
ac_cv_have_libnet_init_const, [ |
| 200 |
AC_TRY_LINK([#include<libnet.h>], |
| 201 |
[libnet_t*libnet_init(int a,const char* b,char* c);], |
| 202 |
[ ac_cv_have_libnet_init_const="yes" ], |
| 203 |
[ ac_cv_have_libnet_init_const="no" ]) |
| 204 |
]) |
| 205 |
if test x$ac_cv_have_libnet_init_const = xyes; then |
| 206 |
AC_DEFINE([HAVE_LIBNET_INIT_CONST], [1], [Libnet init takes const char device]) |
| 207 |
fi |
| 208 |
|
| 209 |
AC_CACHE_CHECK([for libnet_name2addr4 signature has const], |
| 210 |
ac_cv_have_libnet_name2addr4_const, [ |
| 211 |
AC_TRY_LINK([#include<libnet.h>], |
| 212 |
[uint32_t libnet_name2addr4(libnet_t*a, const char* b,uint8_t c);], |
| 213 |
[ ac_cv_have_libnet_name2addr4_const="yes" ], |
| 214 |
[ ac_cv_have_libnet_name2addr4_const="no" ]) |
| 215 |
]) |
| 216 |
if test x$ac_cv_have_libnet_name2addr4_const = xyes; then |
| 217 |
AC_DEFINE([HAVE_LIBNET_NAME2ADDR4_CONST], [1], [Libnet name2addr4 takes const char* addr]) |
| 218 |
fi |
| 219 |
|
| 220 |
|
| 221 |
# check for CLOCK_MONOTONIC |
| 222 |
AC_CHECK_DECL([CLOCK_MONOTONIC], [], [], |
| 223 |
[ |
| 224 |
#include <time.h> |
| 225 |
#include <sys/time.h> |
| 226 |
] |
| 227 |
) |
| 228 |
AM_CONDITIONAL(HAVE_CLOCK_MONOTONIC, test x$ac_cv_have_decl_CLOCK_MONOTONIC = xyes) |
| 229 |
if test x$ac_cv_have_decl_CLOCK_MONOTONIC = xyes; then |
| 230 |
AC_DEFINE([HAVE_CLOCK_MONOTONIC], [1], [Monotonic clock]) |
| 231 |
fi |
| 232 |
|
| 233 |
AC_ARG_ENABLE(hardened, |
| 234 |
AS_HELP_STRING([--enable-hardened], [Enable security build options]), |
| 235 |
[ |
| 236 |
CHECK_COMPILER_OPTION([-fstack-clash-protection]) |
| 237 |
CHECK_COMPILER_OPTION([-fstack-protector-strong]) |
| 238 |
CHECK_COMPILER_OPTION([-mbranch-protection=standard]) |
| 239 |
CHECK_COMPILER_OPTION([-fcf-protection=full]) |
| 240 |
CHECK_COMPILER_OPTION([-fstrict-flex-arrays=3]) |
| 241 |
CHECK_COMPILER_OPTION([-fPIE -pie]) |
| 242 |
CHECK_COMPILER_OPTION([-Wl,-z,nodlopen]) |
| 243 |
CHECK_COMPILER_OPTION([-Wl,-z,noexecstack]) |
| 244 |
CHECK_COMPILER_OPTION([-Wl,-z,relro]) |
| 245 |
CHECK_COMPILER_OPTION([-Wl,-z,noexecheap]) |
| 246 |
CHECK_COMPILER_OPTION([-Wl,-z,now]) |
| 247 |
CHECK_COMPILER_OPTION([-fstack-protector-all]) |
| 248 |
CHECK_COMPILER_OPTION([--param ssp-buffer-size=1]) |
| 249 |
CHECK_COMPILER_OPTION([-U _FORTIFY_SOURCE -D_FORTIFY_SOURCE=3]) |
| 250 |
]) |
| 251 |
AC_ARG_ENABLE(warnings, |
| 252 |
AS_HELP_STRING([--enable-warnings], [Enable build warnings]), |
| 253 |
[ |
| 254 |
CHECK_COMPILER_OPTION([-Wall]) |
| 255 |
CHECK_COMPILER_OPTION([-Wextra]) |
| 256 |
CHECK_COMPILER_OPTION([-Wpedantic]) |
| 257 |
CHECK_COMPILER_OPTION([-Wstack-protector]) |
| 258 |
CHECK_COMPILER_OPTION([-Wformat]) |
| 259 |
CHECK_COMPILER_OPTION([-Wformat-security]) |
| 260 |
CHECK_COMPILER_OPTION([-Wformat-y2k]) |
| 261 |
CHECK_COMPILER_OPTION([-Werror=format-security]) |
| 262 |
CHECK_COMPILER_OPTION([-Wconversion]) |
| 263 |
CHECK_COMPILER_OPTION([-Wsign-conversion]) |
| 264 |
CHECK_COMPILER_OPTION([-Wimplicit-fallthrough]) |
| 265 |
CHECK_COMPILER_OPTION([-Wtrampolines]) |
| 266 |
]) |
| 267 |
|
| 268 |
AC_DEFUN([CHECK_SECCOMP_SYSCALL], [ |
| 269 |
AC_MSG_CHECKING([seccomp syscall $1]) |
| 270 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ |
| 271 |
#include<seccomp.h> |
| 272 |
]], [[ |
| 273 |
void test() |
| 274 |
{ |
| 275 |
scmp_filter_ctx ctx; |
| 276 |
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS($1), 0); |
| 277 |
} |
| 278 |
]])], |
| 279 |
[ |
| 280 |
AC_MSG_RESULT(yes) |
| 281 |
AC_DEFINE([HAVE_SECCOMP_SYSCALL_$1], [1], [Have seccomp syscall]) |
| 282 |
],[AC_MSG_RESULT(no)])]) |
| 283 |
|
| 284 |
AC_CONFIG_FILES([Makefile]) |
| 285 |
AC_CONFIG_FILES([src/Makefile]) |
| 286 |
AC_CONFIG_FILES([doc/Makefile]) |
| 287 |
AC_OUTPUT |
| 288 |
|
| 289 |
echo " |
| 290 |
$PACKAGE_NAME version $PACKAGE_VERSION |
| 291 |
Prefix.........: $prefix |
| 292 |
Debug Build....: $debug |
| 293 |
C Compiler.....: $CC $CFLAGS $CPPFLAGS |
| 294 |
Linker.........: $LD $LDFLAGS $LIBS |
| 295 |
" |