From 9d07f0cadaf6eadd2d3c0a03c33b58d479197e06 Mon Sep 17 00:00:00 2001 From: Paliak <91493239+Paliak@users.noreply.github.com> Date: Sun, 17 May 2026 20:11:32 +0200 Subject: [PATCH 1/7] FIX: getprotobyname missing on Android preventing use getprotobyname is stubbed out on Android causing crash_and_burn to be called. This commit removes the icmp support check when compiling for Android and adds a configuration option to compile without the check. Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com> --- configure.ac | 8 ++++++++ src/socket4.c | 17 ++++++++++------- src/socket6.c | 17 ++++++++++------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index b17f3bb9..01153c5c 100644 --- a/configure.ac +++ b/configure.ac @@ -104,6 +104,14 @@ AC_ARG_ENABLE([debug], AS_IF([test "x$enable_debug" = "xyes"], [ AC_DEFINE([DEBUG], [1], [Define if debugging is enabled])]) + +AC_ARG_ENABLE([getprotobyname], + AS_HELP_STRING([--disable-getprotobyname], [Disable use of getprotobyname]), + [], [enable_getprotobyname=yes]) +AS_IF([test "x$enable_getprotobyname" = "xyes"], [ + AC_DEFINE([USE_GETPROTOBYNAME], [1], [Enable use of getprotobyname]) +]) + AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_MAINTAINER_MODE diff --git a/src/socket4.c b/src/socket4.c index cb986e22..f0f1982a 100644 --- a/src/socket4.c +++ b/src/socket4.c @@ -59,20 +59,23 @@ static int outgoing_src_addr_set_ipv4 = 0; int open_ping_socket_ipv4(int *socktype) { - struct protoent* proto; - int s; + int s = -1; + int p_proto = IPPROTO_ICMP; - /* confirm that ICMP is available on this machine */ - if ((proto = getprotobyname("icmp")) == NULL) - crash_and_burn("icmp: unknown protocol"); +#if defined(USE_GETPROTOBYNAME) && !(defined(ANDROID) || defined(__ANDROID__)) + /* confirm that ICMP is available on this machine */ + if (getprotobyname("icmp") == NULL) { + crash_and_burn("icmp: unknown protocol"); + } +#endif /* create raw socket for ICMP calls (ping) */ *socktype = SOCK_RAW; - s = socket(AF_INET, *socktype, proto->p_proto); + s = socket(AF_INET, *socktype, p_proto); if (s < 0) { /* try non-privileged icmp (works on Mac OSX without privileges, for example) */ *socktype = SOCK_DGRAM; - s = socket(AF_INET, *socktype, proto->p_proto); + s = socket(AF_INET, *socktype, p_proto); if (s < 0) { return -1; } diff --git a/src/socket6.c b/src/socket6.c index ab6e199f..1d2b032d 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -57,20 +57,23 @@ static int outgoing_src_addr_set_ipv6 = 0; int open_ping_socket_ipv6(int *socktype) { - struct protoent* proto; - int s; + int s = -1; + int p_proto = IPPROTO_ICMPV6; - /* confirm that ICMP6 is available on this machine */ - if ((proto = getprotobyname("ipv6-icmp")) == NULL) - crash_and_burn("ipv6-icmp: unknown protocol"); +#if defined(USE_GETPROTOBYNAME) && !(defined(ANDROID) || defined(__ANDROID__)) + /* confirm that ICMP6 is available on this machine */ + if (getprotobyname("ipv6-icmp") == NULL ) { + crash_and_burn("ipv6-icmp: unknown protocol"); + } +#endif /* create raw socket for ICMP6 calls (ping) */ *socktype = SOCK_RAW; - s = socket(AF_INET6, *socktype, proto->p_proto); + s = socket(AF_INET6, *socktype, p_proto); if (s < 0) { /* try non-privileged icmp6 (works on Mac OSX without privileges, for example) */ *socktype = SOCK_DGRAM; - s = socket(AF_INET6, *socktype, proto->p_proto); + s = socket(AF_INET6, *socktype, p_proto); if (s < 0) { return -1; } From 85ee18b04c118a4bd8ad6a4b68ac067a15d9288b Mon Sep 17 00:00:00 2001 From: Paliak <91493239+Paliak@users.noreply.github.com> Date: Sun, 17 May 2026 20:34:40 +0200 Subject: [PATCH 2/7] Fix formatting in socket6.c Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/socket6.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/socket6.c b/src/socket6.c index 1d2b032d..25857203 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -61,10 +61,10 @@ int open_ping_socket_ipv6(int *socktype) int p_proto = IPPROTO_ICMPV6; #if defined(USE_GETPROTOBYNAME) && !(defined(ANDROID) || defined(__ANDROID__)) - /* confirm that ICMP6 is available on this machine */ - if (getprotobyname("ipv6-icmp") == NULL ) { - crash_and_burn("ipv6-icmp: unknown protocol"); - } + /* confirm that ICMP6 is available on this machine */ + if (getprotobyname("ipv6-icmp") == NULL) { + crash_and_burn("ipv6-icmp: unknown protocol"); + } #endif /* create raw socket for ICMP6 calls (ping) */ From be8cc590df6dceca467a0770e7054fdb72dbdda1 Mon Sep 17 00:00:00 2001 From: Paliak <91493239+Paliak@users.noreply.github.com> Date: Sun, 31 May 2026 20:51:50 +0200 Subject: [PATCH 3/7] FIX: use existing OS detection for USE_GETPROTOBYNAME Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com> --- configure.ac | 12 +++++------- src/socket4.c | 2 +- src/socket6.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 01153c5c..4fc58f6c 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,7 @@ m4_ifdef([AC_AUTOCONF_VERSION],[AC_USE_SYSTEM_EXTENSIONS], [AC_GNU_SOURCE]) # Detect Operatingsystem AC_CANONICAL_TARGET only_clock_realtime=no +use_getprotobyname=yes case "${target}" in *darwin*) @@ -21,6 +22,9 @@ case "${target}" in *openbsd*) only_clock_realtime=yes ;; + *android*) + use_getprotobyname=no + ;; esac dnl Detect IBM i PASE environment @@ -104,13 +108,7 @@ AC_ARG_ENABLE([debug], AS_IF([test "x$enable_debug" = "xyes"], [ AC_DEFINE([DEBUG], [1], [Define if debugging is enabled])]) - -AC_ARG_ENABLE([getprotobyname], - AS_HELP_STRING([--disable-getprotobyname], [Disable use of getprotobyname]), - [], [enable_getprotobyname=yes]) -AS_IF([test "x$enable_getprotobyname" = "xyes"], [ - AC_DEFINE([USE_GETPROTOBYNAME], [1], [Enable use of getprotobyname]) -]) +AS_IF([test "x$use_getprotobyname" = "xyes"], [AC_DEFINE([USE_GETPROTOBYNAME], [1], [Enable use of getprotobyname])]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_MAINTAINER_MODE diff --git a/src/socket4.c b/src/socket4.c index f0f1982a..6c6864e0 100644 --- a/src/socket4.c +++ b/src/socket4.c @@ -62,7 +62,7 @@ int open_ping_socket_ipv4(int *socktype) int s = -1; int p_proto = IPPROTO_ICMP; -#if defined(USE_GETPROTOBYNAME) && !(defined(ANDROID) || defined(__ANDROID__)) +#ifdef USE_GETPROTOBYNAME /* confirm that ICMP is available on this machine */ if (getprotobyname("icmp") == NULL) { crash_and_burn("icmp: unknown protocol"); diff --git a/src/socket6.c b/src/socket6.c index 1d2b032d..55d5979b 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -60,7 +60,7 @@ int open_ping_socket_ipv6(int *socktype) int s = -1; int p_proto = IPPROTO_ICMPV6; -#if defined(USE_GETPROTOBYNAME) && !(defined(ANDROID) || defined(__ANDROID__)) +#ifdef USE_GETPROTOBYNAME /* confirm that ICMP6 is available on this machine */ if (getprotobyname("ipv6-icmp") == NULL ) { crash_and_burn("ipv6-icmp: unknown protocol"); From 0d09161499cf8b1de1e26a1c8c328f53b67eefd9 Mon Sep 17 00:00:00 2001 From: Paliak <91493239+Paliak@users.noreply.github.com> Date: Sun, 31 May 2026 20:53:07 +0200 Subject: [PATCH 4/7] FIX: use value returned by getprotobyname when it is enabled Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com> --- src/socket4.c | 12 ++++++++---- src/socket6.c | 13 +++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/socket4.c b/src/socket4.c index 6c6864e0..b1811491 100644 --- a/src/socket4.c +++ b/src/socket4.c @@ -63,10 +63,14 @@ int open_ping_socket_ipv4(int *socktype) int p_proto = IPPROTO_ICMP; #ifdef USE_GETPROTOBYNAME - /* confirm that ICMP is available on this machine */ - if (getprotobyname("icmp") == NULL) { - crash_and_burn("icmp: unknown protocol"); - } + { + /* confirm that ICMP is available on this machine */ + struct protoent* proto = getprotobyname("icmp"); + if (proto == NULL) { + crash_and_burn("icmp: unknown protocol"); + } + p_proto = proto->p_proto; + } #endif /* create raw socket for ICMP calls (ping) */ diff --git a/src/socket6.c b/src/socket6.c index 55d5979b..93ec1faa 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -61,12 +61,17 @@ int open_ping_socket_ipv6(int *socktype) int p_proto = IPPROTO_ICMPV6; #ifdef USE_GETPROTOBYNAME - /* confirm that ICMP6 is available on this machine */ - if (getprotobyname("ipv6-icmp") == NULL ) { - crash_and_burn("ipv6-icmp: unknown protocol"); - } + { + /* confirm that ICMP6 is available on this machine */ + struct protoent* proto = getprotobyname("ipv6-icmp"); + if (proto == NULL) { + crash_and_burn("ipv6-icmp: unknown protocol"); + } + p_proto = proto->p_proto; + } #endif + /* create raw socket for ICMP6 calls (ping) */ *socktype = SOCK_RAW; s = socket(AF_INET6, *socktype, p_proto); From cb15cc5145a48c6abe2f1f098c55116bf71e07a6 Mon Sep 17 00:00:00 2001 From: Paliak <91493239+Paliak@users.noreply.github.com> Date: Sun, 31 May 2026 21:01:23 +0200 Subject: [PATCH 5/7] MISC: remove extra new line Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com> --- src/socket6.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/socket6.c b/src/socket6.c index 93ec1faa..52e88173 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -71,7 +71,6 @@ int open_ping_socket_ipv6(int *socktype) } #endif - /* create raw socket for ICMP6 calls (ping) */ *socktype = SOCK_RAW; s = socket(AF_INET6, *socktype, p_proto); From d335b8c79b36008bc88569d84e443b84b781570a Mon Sep 17 00:00:00 2001 From: Paliak <91493239+Paliak@users.noreply.github.com> Date: Tue, 9 Jun 2026 22:25:47 +0200 Subject: [PATCH 6/7] FIX: use AC_CHECK_FUNCS to check that getprotobyname exists before disabling with android override Change as per https://github.com/schweikert/fping/pull/470#discussion_r3349690786 --- configure.ac | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 4fc58f6c..b0bfe05e 100644 --- a/configure.ac +++ b/configure.ac @@ -10,7 +10,7 @@ m4_ifdef([AC_AUTOCONF_VERSION],[AC_USE_SYSTEM_EXTENSIONS], [AC_GNU_SOURCE]) # Detect Operatingsystem AC_CANONICAL_TARGET only_clock_realtime=no -use_getprotobyname=yes +disable_getprotobyname=no case "${target}" in *darwin*) @@ -23,7 +23,7 @@ case "${target}" in only_clock_realtime=yes ;; *android*) - use_getprotobyname=no + disable_getprotobyname=yes ;; esac @@ -108,7 +108,20 @@ AC_ARG_ENABLE([debug], AS_IF([test "x$enable_debug" = "xyes"], [ AC_DEFINE([DEBUG], [1], [Define if debugging is enabled])]) -AS_IF([test "x$use_getprotobyname" = "xyes"], [AC_DEFINE([USE_GETPROTOBYNAME], [1], [Enable use of getprotobyname])]) +AS_IF([test "x$only_clock_realtime" = "xyes"], [AC_DEFINE(ONLY_CLOCK_REALTIME, [1], [ONLY_CLOCK_REALTIME is defined])]) + +dnl check for getprotobyname support + +AC_CHECK_FUNCS([getprotobyname]) + +AS_IF([test "x$disable_getprotobyname" = "xyes"], [ + AC_MSG_NOTICE([Android detected: Disabling getprotobyname]) + ac_cv_func_getprotobyname=no +]) + +if test $ac_cv_func_getprotobyname = yes; then + AC_DEFINE([USE_GETPROTOBYNAME], [1], [Define if getprotobyname is available and should be used.]) +fi AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_MAINTAINER_MODE From 4cd0304af30d5e827dfa9dfeb4e4b80569598ac9 Mon Sep 17 00:00:00 2001 From: Paliak <91493239+Paliak@users.noreply.github.com> Date: Sat, 13 Jun 2026 15:48:01 +0200 Subject: [PATCH 7/7] FIX: remove use of getprotobyname Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com> --- configure.ac | 6 ------ src/socket4.c | 18 ++---------------- src/socket6.c | 18 ++---------------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/configure.ac b/configure.ac index 4fc58f6c..b17f3bb9 100644 --- a/configure.ac +++ b/configure.ac @@ -10,7 +10,6 @@ m4_ifdef([AC_AUTOCONF_VERSION],[AC_USE_SYSTEM_EXTENSIONS], [AC_GNU_SOURCE]) # Detect Operatingsystem AC_CANONICAL_TARGET only_clock_realtime=no -use_getprotobyname=yes case "${target}" in *darwin*) @@ -22,9 +21,6 @@ case "${target}" in *openbsd*) only_clock_realtime=yes ;; - *android*) - use_getprotobyname=no - ;; esac dnl Detect IBM i PASE environment @@ -108,8 +104,6 @@ AC_ARG_ENABLE([debug], AS_IF([test "x$enable_debug" = "xyes"], [ AC_DEFINE([DEBUG], [1], [Define if debugging is enabled])]) -AS_IF([test "x$use_getprotobyname" = "xyes"], [AC_DEFINE([USE_GETPROTOBYNAME], [1], [Enable use of getprotobyname])]) - AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_MAINTAINER_MODE diff --git a/src/socket4.c b/src/socket4.c index b1811491..264d9055 100644 --- a/src/socket4.c +++ b/src/socket4.c @@ -59,27 +59,13 @@ static int outgoing_src_addr_set_ipv4 = 0; int open_ping_socket_ipv4(int *socktype) { - int s = -1; - int p_proto = IPPROTO_ICMP; - -#ifdef USE_GETPROTOBYNAME - { - /* confirm that ICMP is available on this machine */ - struct protoent* proto = getprotobyname("icmp"); - if (proto == NULL) { - crash_and_burn("icmp: unknown protocol"); - } - p_proto = proto->p_proto; - } -#endif - /* create raw socket for ICMP calls (ping) */ *socktype = SOCK_RAW; - s = socket(AF_INET, *socktype, p_proto); + int s = socket(AF_INET, *socktype, IPPROTO_ICMP); if (s < 0) { /* try non-privileged icmp (works on Mac OSX without privileges, for example) */ *socktype = SOCK_DGRAM; - s = socket(AF_INET, *socktype, p_proto); + s = socket(AF_INET, *socktype, IPPROTO_ICMP); if (s < 0) { return -1; } diff --git a/src/socket6.c b/src/socket6.c index 52e88173..a4da1a61 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -57,27 +57,13 @@ static int outgoing_src_addr_set_ipv6 = 0; int open_ping_socket_ipv6(int *socktype) { - int s = -1; - int p_proto = IPPROTO_ICMPV6; - -#ifdef USE_GETPROTOBYNAME - { - /* confirm that ICMP6 is available on this machine */ - struct protoent* proto = getprotobyname("ipv6-icmp"); - if (proto == NULL) { - crash_and_burn("ipv6-icmp: unknown protocol"); - } - p_proto = proto->p_proto; - } -#endif - /* create raw socket for ICMP6 calls (ping) */ *socktype = SOCK_RAW; - s = socket(AF_INET6, *socktype, p_proto); + int s = socket(AF_INET6, *socktype, IPPROTO_ICMPV6); if (s < 0) { /* try non-privileged icmp6 (works on Mac OSX without privileges, for example) */ *socktype = SOCK_DGRAM; - s = socket(AF_INET6, *socktype, p_proto); + s = socket(AF_INET6, *socktype, IPPROTO_ICMPV6); if (s < 0) { return -1; }