commit arping2 for openSUSE:Factory
Hello community, here is the log from the commit of package arping2 for openSUSE:Factory checked in at 2020-08-02 12:20:30 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/arping2 (Old) and /work/SRC/openSUSE:Factory/.arping2.new.3592 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "arping2" Sun Aug 2 12:20:30 2020 rev:20 rq:823905 version:2.21 Changes: -------- --- /work/SRC/openSUSE:Factory/arping2/arping2.changes 2019-08-22 10:58:49.253647962 +0200 +++ /work/SRC/openSUSE:Factory/.arping2.new.3592/arping2.changes 2020-08-02 12:21:10.243413031 +0200 @@ -1,0 +2,10 @@ +Thu Jul 30 21:02:18 UTC 2020 - Matthias Eliasson <elimat@opensuse.org> + +- Update to version 2.21 + * Use more modern pcap API calls, when available + * Add payload data to mac ping + * chdir(/) after chroot() + * Misc minor cleanup +- Run spec-cleaner + +------------------------------------------------------------------- Old: ---- arping-2.20.tar.gz arping-2.20.tar.gz.asc New: ---- arping-2.21.tar.gz arping-2.21.tar.gz.asc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ arping2.spec ++++++ --- /var/tmp/diff_new_pack.MDK2tK/_old 2020-08-02 12:21:10.719413540 +0200 +++ /var/tmp/diff_new_pack.MDK2tK/_new 2020-08-02 12:21:10.719413540 +0200 @@ -1,7 +1,7 @@ # # spec file for package arping2 # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,19 +17,17 @@ Name: arping2 -Version: 2.20 +Version: 2.21 Release: 0 Summary: Layer-2 Ethernet pinger License: GPL-2.0-or-later Group: Productivity/Networking/Diagnostic -Url: http://www.habets.pp.se/synscan/programs.php?prog=arping - +URL: http://www.habets.pp.se/synscan/programs.php?prog=arping #Git-Clone: git://github.com/ThomasHabets/arping Source0: http://www.habets.pp.se/synscan/files/arping-%version.tar.gz Source1: http://www.habets.pp.se/synscan/files/arping-%version.tar.gz.asc Source2: %name.keyring Patch1: arping-setgroups.diff -BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: libnet-devel BuildRequires: libpcap-devel @@ -39,22 +37,20 @@ unrouted networks and with ICMP-blocking hosts. %prep -%setup -n arping-%version -%patch -P 1 -p1 +%autosetup -n arping-%version -p1 %build %configure -make %{?_smp_mflags} +%make_build %install -b="%buildroot"; +b="%buildroot" %make_install # Avoid collision with iputils's inferior arping. -mv "$b/%_sbindir"/{arping,%name}; -mv "$b/%_mandir/man8"/{arping.8,%name.8}; +mv "$b/%_sbindir/arping" "$b/%_sbindir/%name" +mv "$b/%_mandir/man8/arping.8" "$b/%_mandir/man8/arping2.8" %files -%defattr(-,root,root) %_sbindir/arping2 %_mandir/man8/arping2.8* %doc README ++++++ arping-2.20.tar.gz -> arping-2.21.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/HACKING.md new/arping-2.21/HACKING.md --- old/arping-2.20/HACKING.md 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/HACKING.md 2020-03-08 15:23:37.000000000 +0100 @@ -1,5 +1,17 @@ # Hacking on Arping +## Coding style + +* C99 to retain portability for the widest range of platforms +* Approximately [Linux kernel coding style][1], except: + * Line break before function name, in function definitions. + * Curly braces are mandatory. + * Place `*` next to the type, not the name. E.g. `char* p` + +Don't make style-only changes, but fix the style on the line you're touching anyway. + +[1]: https://github.com/torvalds/linux/blob/master/Documentation/process/coding-s... + ## Make release 1. Up version in configure.ac. Commit. 2. Run `./extra/mktarball HEAD` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/INSTALL new/arping-2.21/INSTALL --- old/arping-2.20/INSTALL 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/INSTALL 2020-03-08 15:23:37.000000000 +0100 @@ -4,8 +4,8 @@ Dependencies ------------ -libnet 1.1.x - https://github.com/sam-github/libnet +libnet 1.1 or newer + https://github.com/libnet/libnet or http://ftp.debian.org/debian/pool/main/libn/libnet/libnet_1.1.2.1.orig.tar.g... Note: Libnet 1.1.5 or later needed for Linux capability support. @@ -29,9 +29,9 @@ Installing, longer version -------------------------- -Note that arping 2.x requires libnet 1.1.x to work. It will NOT work with -libnet 1.0.x. Arping 1.x works with libnet 1.0.x, but it's not included in the -same package anymore. +Note that arping 2.x requires libnet 1.1 or newer to work. It will NOT +work with libnet 1.0.x. Arping 1.x works with libnet 1.0.x, but it's +not included in the same package anymore. Standard autotools: ./configure && make && make install diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/README new/arping-2.21/README --- old/arping-2.20/README 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/README 2020-03-08 15:23:37.000000000 +0100 @@ -43,15 +43,15 @@ * Latest Debian stable x86 and amd64 * Linux (Debian or Ubuntu) on arm * Latest OpenBSD x86 or amd64 -* FreeBSD x86 -* Solaris 10 sparc -I don't have these systems up and runnig 24/7, but I try to get them tested -every now and then: +Systems that it should still work on, but I don't personally regularly test: +* Debian Alpha +* FreeBSD +* IRIX 6.5 mips (last test 2009-09-27) * MacOS X -* Debian alpha +* NetBSD * OpenBSD sparc64 (last test: 2009-10-02) -* IRIX 6.5 mips (last test 2009-09-27) +* Solaris Mailing list ------------ @@ -122,20 +122,12 @@ --- Q: ./configure says I need libnet and/or libpcap -A: Arping depends on libnet 1.1.x and libpcap, get libnet at: - http://packetfactory.openwall.net/projects/libnet/ - and libpcap from http://www.tcpdump.org. +A: Arping depends on libnet 1.1 or newer, and libpcap. Get libnet from + https://github.com/libnet/libnet and libpcap from http://www.tcpdump.org. Or more likely they were both included in your Linux distribution. - Lately www.packetfactory.net seems to be down, so you can get the original - tarball from the Debian archives: - http://ftp.debian.org/debian/pool/main/libn/libnet/libnet_1.1.4.orig.tar.gz - If that exact file doesn't exist there probably is one with a higher - version number. - - Or github.com: - http://github.com/sam-github/libnet - http://github.com/ThomasHabets/libnet + The original libnet site + was http://packetfactory.openwall.net/projects/libnet/, but is not updated. --- Q: I get bus error on my non-x86 box diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/config.h.in new/arping-2.21/config.h.in --- old/arping-2.20/config.h.in 2019-08-18 13:17:06.000000000 +0200 +++ new/arping-2.21/config.h.in 2020-03-08 15:23:39.000000000 +0100 @@ -15,6 +15,9 @@ /* Define to 1 if you have the <getopt.h> header file. */ #undef HAVE_GETOPT_H +/* Define to 1 if you have the `getrandom' function. */ +#undef HAVE_GETRANDOM + /* Define to 1 if you have the `gettimeofday' function. */ #undef HAVE_GETTIMEOFDAY @@ -69,6 +72,9 @@ /* Define to 1 if you have the `pcap_create' function. */ #undef HAVE_PCAP_CREATE +/* Define to 1 if you have the `pcap_findalldevs' function. */ +#undef HAVE_PCAP_FINDALLDEVS + /* Define to 1 if you have the `pcap_list_tstamp_types' function. */ #undef HAVE_PCAP_LIST_TSTAMP_TYPES @@ -114,6 +120,9 @@ /* Define to 1 if you have the <sys/param.h> header file. */ #undef HAVE_SYS_PARAM_H +/* Define to 1 if you have the <sys/random.h> header file. */ +#undef HAVE_SYS_RANDOM_H + /* Define to 1 if you have the <sys/select.h> header file. */ #undef HAVE_SYS_SELECT_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/configure new/arping-2.21/configure --- old/arping-2.20/configure 2019-08-18 13:17:06.000000000 +0200 +++ new/arping-2.21/configure 2020-03-08 15:23:39.000000000 +0100 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for arping 2.20. +# Generated by GNU Autoconf 2.69 for arping 2.21. # # Report bugs to <thomas@habets.se>. # @@ -580,8 +580,8 @@ # Identity of this package. PACKAGE_NAME='arping' PACKAGE_TARNAME='arping' -PACKAGE_VERSION='2.20' -PACKAGE_STRING='arping 2.20' +PACKAGE_VERSION='2.21' +PACKAGE_STRING='arping 2.21' PACKAGE_BUGREPORT='thomas@habets.se' PACKAGE_URL='' @@ -1297,7 +1297,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures arping 2.20 to adapt to many kinds of systems. +\`configure' configures arping 2.21 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1369,7 +1369,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of arping 2.20:";; + short | recursive ) echo "Configuration of arping 2.21:";; esac cat <<\_ACEOF @@ -1465,7 +1465,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -arping configure 2.20 +arping configure 2.21 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1934,7 +1934,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by arping $as_me 2.20, which was +It was created by arping $as_me 2.21, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2909,7 +2909,7 @@ # Define the identity of the package. PACKAGE='arping' - VERSION='2.20' + VERSION='2.21' cat >>confdefs.h <<_ACEOF @@ -4372,7 +4372,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_net_libnet_name_resolve" >&5 $as_echo "$ac_cv_lib_net_libnet_name_resolve" >&6; } if test "x$ac_cv_lib_net_libnet_name_resolve" = xyes; then : - as_fn_error $? "libnet 1.0.x found. Arping 2.x requires libnet 1.1.x" "$LINENO" 5 + as_fn_error $? "libnet 1.0.x found. Arping 2.x requires libnet 1.1 or newer" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libnet_init in -lnet" >&5 @@ -4939,6 +4939,7 @@ stdint.h \ libnet.h \ win32/libnet.h \ +sys/random.h \ net/bpf.h \ pwd.h \ unistd.h @@ -5326,7 +5327,7 @@ for ac_func in gettimeofday memset select strchr strdup strerror strstr \ getifaddrs cap_init pcap_create pcap_list_tstamp_types pcap_set_immediate_mode \ -pledge unveil +pledge unveil pcap_findalldevs getrandom do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -6037,7 +6038,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by arping $as_me 2.20, which was +This file was extended by arping $as_me 2.21, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -6103,7 +6104,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -arping config.status 2.20 +arping config.status 2.21 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/configure.ac new/arping-2.21/configure.ac --- old/arping-2.20/configure.ac 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/configure.ac 2020-03-08 15:23:37.000000000 +0100 @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT(arping, 2.20, thomas@habets.se) +AC_INIT(arping, 2.21, thomas@habets.se) AC_CANONICAL_SYSTEM AC_CONFIG_SRCDIR([src/arping.c]) AM_INIT_AUTOMAKE @@ -28,7 +28,7 @@ AC_CHECK_LIB([cap], [cap_init]) AC_CHECK_LIB([rt], [clock_gettime]) AC_CHECK_LIB([net], [libnet_name_resolve], - [AC_MSG_ERROR([libnet 1.0.x found. Arping 2.x requires libnet 1.1.x])]) + [AC_MSG_ERROR([libnet 1.0.x found. Arping 2.x requires libnet 1.1 or newer])]) AC_CHECK_LIB([net], [libnet_init], ,[AC_MSG_ERROR([libnet 1.1.x not found])]) AC_CHECK_LIB([pcap], [pcap_open_live], ,[AC_MSG_ERROR([libpcap not found])]) AC_SEARCH_LIBS([clock_gettime], [rt]) @@ -50,6 +50,7 @@ stdint.h \ libnet.h \ win32/libnet.h \ +sys/random.h \ net/bpf.h \ pwd.h \ unistd.h]) @@ -75,7 +76,7 @@ AC_TYPE_SIGNAL AC_CHECK_FUNCS([gettimeofday memset select strchr strdup strerror strstr \ getifaddrs cap_init pcap_create pcap_list_tstamp_types pcap_set_immediate_mode \ -pledge unveil]) +pledge unveil pcap_findalldevs getrandom]) if test x$ac_cv_func_getifaddrs = xyes; then AC_LIBOBJ([findif_getifaddrs]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/extra/build-test.sh new/arping-2.21/extra/build-test.sh --- old/arping-2.20/extra/build-test.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/arping-2.21/extra/build-test.sh 2020-03-08 15:23:37.000000000 +0100 @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -e + +./bootstrap.sh + +for std in c99 c11 c18; do + for cc in gcc clang; do + cppflags="-I$HOME/opt/libnet/include" + ldflags="-L$HOME/opt/libnet/lib -Wl,-rpath -Wl,$HOME/opt/libnet/lib" + cflags="-std=$std -Wall -Wextra -pedantic -O3 -march=native" + ./configure --prefix="$HOME/opt/arping" \ + CPPFLAGS="$cppflags" \ + CFLAGS="$cflags" \ + LDFLAGS="$ldflags" \ + CC=$cc + make clean + make -j8 EXTRA_CFLAGS="-Werror" + make check 2>/dev/null || (echo "Test failed" && exit 1) + done +done diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/src/Makefile.am new/arping-2.21/src/Makefile.am --- old/arping-2.20/src/Makefile.am 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/src/Makefile.am 2020-03-08 15:23:37.000000000 +0100 @@ -1,6 +1,7 @@ # arping/src/Makefile.am include $(top_srcdir)/Makefile.am.common +CFLAGS+= $(EXTRA_CFLAGS) sbin_PROGRAMS = arping noinst_PROGRAMS = fuzz_pingip diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/src/Makefile.in new/arping-2.21/src/Makefile.in --- old/arping-2.20/src/Makefile.in 2019-08-18 13:17:06.000000000 +0200 +++ new/arping-2.21/src/Makefile.in 2020-03-08 15:23:39.000000000 +0100 @@ -401,7 +401,7 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ +CFLAGS = @CFLAGS@ $(EXTRA_CFLAGS) CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/src/arping.c new/arping-2.21/src/arping.c --- old/arping-2.20/src/arping.c 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/src/arping.c 2020-03-08 15:23:37.000000000 +0100 @@ -73,6 +73,10 @@ #include <sys/param.h> #endif +#if HAVE_SYS_RANDOM_H +#include <sys/random.h> +#endif + #if HAVE_GRP_H #include <grp.h> #endif @@ -165,6 +169,9 @@ */ static uint8_t dstmac[ETH_ALEN]; +static char* payload_suffix = NULL; +static ssize_t payload_suffix_size = -1; + uint32_t srcip; /* autodetected, override with -S/-b/-0 */ uint8_t srcmac[ETH_ALEN]; /* autodetected, override with -s */ @@ -212,6 +219,40 @@ /* Doesn't really need to be volatile, but doesn't hurt. */ static volatile sig_atomic_t time_to_die = 0; +static ssize_t +xgetrandom(void *buf, const size_t buflen, const unsigned int flags) +{ +#ifdef HAVE_GETRANDOM + return getrandom(buf, buflen, flags); +#else + char* p = buf; + for (int n = 0; n < buflen; n++) { + p[n] = random() & 0xff; + } + return buflen; +#endif +} + +static long int +xrandom() { + const int maxtry = 10; + for (int c = 0; c < maxtry; c++) { + long int ret; + const ssize_t rc = xgetrandom(&ret, sizeof(ret), 0); + if (rc == -1) { + fprintf(stderr, "arping: failed to get random bytes: %s\n", strerror(errno)); + continue; + } + if (sizeof(ret) != rc) { + fprintf(stderr, "arping: got too few random bytes %zd, want %zd\n", rc, sizeof(ret)); + continue; + } + return ret; + } + fprintf(stderr, "arping: failed to get random bytes after %d tries\n", maxtry); + exit(1); +} + /** * If possible, chroot. * @@ -245,6 +286,12 @@ } return; } + if (chdir("/")) { + if (verbose) { + printf("arping: chdir(/): %s\n", strerror(errno)); + } + return; + } if (verbose > 1) { printf("arping: Successfully chrooted to %s\n", pw->pw_dir); } @@ -905,7 +952,7 @@ if (max_wait < 0) { return 0; } - if (max_wait > packetwait / 1000000) { + if (max_wait > packetwait / 1000000.0) { return packetwait; } return max_wait * 1000000; @@ -952,8 +999,6 @@ return buf; } - - /** Send directed IPv4 ICMP echo request. * * \param id IP id @@ -968,7 +1013,16 @@ // Without this padding some systems (e.g. Raspberry Pi 3 // wireless interface) failed. dmesg said: // arping: packet size is too short (42 <= 50) - const uint8_t padding[16] = {0}; + const size_t padding_size = sizeof(struct timespec) + payload_suffix_size; + uint8_t padding[padding_size]; + memset(padding, 0, padding_size); + { + struct timespec ts; + getclock(&ts); + memcpy(padding, &ts, sizeof(struct timespec)); + memcpy(&padding[sizeof(struct timespec)], + payload_suffix, payload_suffix_size); + } int c; @@ -987,7 +1041,8 @@ } if (-1==(ipv4 = libnet_build_ipv4(LIBNET_IPV4_H - + LIBNET_ICMPV4_ECHO_H + 0, + + LIBNET_ICMPV4_ECHO_H + + sizeof padding, 0, /* ToS */ id, /* id */ 0, /* frag */ @@ -1340,6 +1395,10 @@ return; } + if (verbose > 3) { + printf("arping: ... right dst mac\n"); + } + // Source MAC must match, if set. if (memcmp(dstmac, ethxmas, ETH_ALEN)) { if (memcmp(pkt_srcmac, dstmac, ETH_ALEN)) { @@ -1347,6 +1406,10 @@ } } + if (verbose > 3) { + printf("arping: ... right src mac\n"); + } + // IPv4 Address must be me (maybe). if (addr_must_be_same) { uint32_t tmp; @@ -1356,11 +1419,48 @@ } } - // Must be ICMP echo reply. + if (verbose > 3) { + printf("arping: ... src IP acceptable\n"); + } + + // Must be ICMP echo reply type. if (htons(hicmp->icmp_type) != ICMP_ECHOREPLY) { return; } + if (verbose > 3) { + printf("arping: ... is echo reply type\n"); + } + + // Must be ICMP echo reply code 0. + if (htons(hicmp->icmp_code) != 0) { + return; + } + + if (verbose > 3) { + printf("arping: ... is echo reply code\n"); + } + + const char* payload = (char*)hicmp + LIBNET_ICMPV4_ECHO_H; + const ssize_t payload_size = h->len - (payload - (char*)packet); + if (payload_size < 0) { + return; + } + if (payload_size < sizeof(struct timespec) + payload_suffix_size) { + return; + } + if (verbose > 3) { + printf("arping: ... correct payload size (%zd)\n", + payload_size); + } + if (memcmp(&payload[sizeof(struct timespec)], + payload_suffix, payload_suffix_size)) { + return; + } + if (verbose > 3) { + printf("arping: ... correct payload suffix\n"); + } + update_stats(timespec2dbl(&arrival) - timespec2dbl(&lastpacketsent)); if (beep) { printf("\a"); @@ -1605,6 +1705,7 @@ double deadline = -1; char bpf_filter[64]; ebuf[0] = 0; + srandom(time(NULL)); for (c = 1; c < argc; c++) { if (!strcmp(argv[c], "--help")) { @@ -1658,6 +1759,7 @@ break; case 'h': usage(0); + exit(0); // Needless but shuts up compiler warnings. case 'g': drop_group = optarg; break; @@ -1671,7 +1773,9 @@ "purpose)\n"); exit(1); } - case 'I': /* FALL THROUGH */ + ifname = optarg; + break; + case 'I': ifname = optarg; break; case 'm': @@ -1756,6 +1860,37 @@ exit(1); } + // Generate random payload suffix for MAC pings, to be able to + // differentiate from unrelated ping replies. + if (payload_suffix_size < 0) { + payload_suffix_size = 4; + payload_suffix = malloc(payload_suffix_size); + if (payload_suffix) { + const ssize_t rc = xgetrandom(payload_suffix, payload_suffix_size, 0); + if (rc == -1) { + fprintf(stderr, + "arping: failed to get %zd random bytes: %s\n", + payload_suffix_size, + strerror(errno)); + free(payload_suffix); + payload_suffix = NULL; + } else if (payload_suffix_size != rc) { + fprintf(stderr, + "arping: only got %zd out of %zd bytes for random suffix\n", + rc, payload_suffix_size); + } + } else { + fprintf(stderr, "arping: failed to allocate %zd bytes for payload suffix.\n", + payload_suffix_size); + } + + if (!payload_suffix) { + fprintf(stderr, "arping: Using constant suffix.\n"); + payload_suffix = "arping"; + payload_suffix_size = strlen(payload_suffix); + } + } + if (((mode == PINGIP) && opt_T) || ((mode == PINGMAC) && (opt_B || dstmac_opt || opt_U))) { fprintf(stderr, "arping: -T can only be used to ping MAC" @@ -1857,7 +1992,7 @@ * Handle dstip_given instead of ip address after parms (-B really) */ if (mode == NONE) { - if (optind + 1 == argc) { + if (parm) { mode = is_mac_addr(parm)?PINGMAC:PINGIP; } else if (dstip_given) { mode = PINGIP; @@ -2098,7 +2233,7 @@ } else { /* PINGMAC */ int c; for (c = 0; (maxcount < 0 || c < maxcount) && !time_to_die; c++) { - pingmac_send(rand(), c); + pingmac_send(xrandom(), c); const uint32_t w = wait_time(deadline, packetwait); if (w == 0) { break; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/src/findif_linux.c new/arping-2.21/src/findif_linux.c --- old/arping-2.20/src/findif_linux.c 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/src/findif_linux.c 2020-03-08 15:23:37.000000000 +0100 @@ -33,6 +33,8 @@ #include "arping.h" +#error "This code should never be chosen. If you just want to use it then uncomment this error line" + /** * WARNING: non-reentrant */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/src/mock_libnet.c new/arping-2.21/src/mock_libnet.c --- old/arping-2.20/src/mock_libnet.c 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/src/mock_libnet.c 2020-03-08 15:23:37.000000000 +0100 @@ -24,7 +24,7 @@ UNUSED(err_buf); if (device == NULL) { if (mock_libnet_null_ok) { - return malloc(1); + return malloc(sizeof(libnet_t)); } return NULL; } @@ -32,10 +32,10 @@ return NULL; } if (!strcmp(device, "good")) { - return malloc(1); + return malloc(sizeof(libnet_t)); } if (mock_libnet_lo_ok && !strcmp(device, "lo")) { - return malloc(1); + return malloc(sizeof(libnet_t)); } return NULL; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/arping-2.20/src/unix.c new/arping-2.21/src/unix.c --- old/arping-2.20/src/unix.c 2019-08-18 13:17:04.000000000 +0200 +++ new/arping-2.21/src/unix.c 2020-03-08 15:23:37.000000000 +0100 @@ -20,7 +20,17 @@ #include "config.h" #endif +#include <errno.h> #include <signal.h> +#include <string.h> + +#if HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif + +#if HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif #include <pcap.h> @@ -34,9 +44,59 @@ const char * arping_lookupdev_default(uint32_t srcip, uint32_t dstip, char *ebuf) { +#ifdef HAVE_PCAP_FINDALLDEVS + UNUSED(srcip); + pcap_if_t *ifs = NULL; + int rc = pcap_findalldevs(&ifs, ebuf); + if (rc) { + return NULL; + } + + pcap_if_t *t; + char* ifname = NULL; + for (t = ifs; !ifname && t; t = t->next) { +#ifdef PCAP_IF_LOOPBACK + if (t->flags & PCAP_IF_LOOPBACK) { + continue; + } +#endif +#ifdef PCAP_IF_UP + if (!(t->flags & PCAP_IF_UP)) { + continue; + } +#endif + + // This code is only called when using -F, which is "don't try + // to be smart". If we wanted to be smart we would have used + // findif_*.c. + if (1) { + ifname = strdup(t->name); // Memory leak. + break; + } + + // UNREACHABLE + pcap_addr_t *a; + for (a = t->addresses; !ifname && a; a = a->next) { + if (a->addr->sa_family != AF_INET) { + continue; + } + const struct sockaddr_in* sa = (struct sockaddr_in*)a->addr; + const struct sockaddr_in* smask = (struct sockaddr_in*)a->netmask; + const uint32_t addr = sa->sin_addr.s_addr; + const uint32_t mask = smask->sin_addr.s_addr; + if ((addr & mask) != (dstip & mask)) { + // Not optimal: memory leak. + ifname = strdup(t->name); + } + } + } + pcap_freealldevs(ifs); + return ifname; +#else UNUSED(srcip); UNUSED(dstip); return pcap_lookupdev(ebuf); +#endif } /** @@ -45,7 +105,10 @@ void do_signal_init() { - signal(SIGINT, sigint); + if (SIG_ERR == signal(SIGINT, sigint)) { + fprintf(stderr, "arping: failed to set SIGINT handler: %s\n", + strerror(errno)); + } } /* ---- Emacs Variables ---- * Local Variables:
participants (1)
-
root