Skip to content

Fix getprotobyname missing on Android preventing use#470

Open
Paliak wants to merge 6 commits into
schweikert:developfrom
Paliak:fix-getprotobyname-android
Open

Fix getprotobyname missing on Android preventing use#470
Paliak wants to merge 6 commits into
schweikert:developfrom
Paliak:fix-getprotobyname-android

Conversation

@Paliak
Copy link
Copy Markdown

@Paliak Paliak commented May 17, 2026

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 getprotobyname check.

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>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a configuration option to disable the use of getprotobyname and switches to using hardcoded protocol constants (IPPROTO_ICMP and IPPROTO_ICMPV6) for socket initialization. This change improves compatibility with environments like Android where these lookups may fail. A review comment identifies formatting issues in src/socket6.c, specifically the use of tabs instead of spaces and a minor syntax typo in an if condition.

Comment thread src/socket6.c Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment thread src/socket4.c Outdated
Comment thread configure.ac Outdated


AC_ARG_ENABLE([getprotobyname],
AS_HELP_STRING([--disable-getprotobyname], [Disable use of getprotobyname]),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the --disable-getprotobyname flag really necessary? If not, then an attempt should be made to perform an automatic check.
For example, using AC_CHECK_FUNCS()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the most portable way i could think of implementing this. AC_CHECK_FUNCS will return true on Android as getprotobyname does exist. It just always returns NULL. The only automatic way to check this that i know of would be to use AC_RUN_IFELSE but i decided against that as i feel it would be quite messy (and maybe cause issues with cross compilation). I guess the flag could just be removed altogether as #if !(defined(ANDROID) || defined(__ANDROID__)) would suffice for what this PR is trying to accomplish.

Just thought that it could be a nice to have.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, it would be better to move the Android detection to configure.ac. We already have the case "${target}" in function, and if other systems use the same approach, it can be extended quite easily.
This keeps the exception in the code itself more flexible.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in be8cc59 let me know what you think.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would first check whether getprotobyname is present, and then check whether it needs to be disabled again.

Here's my example:

# Detect Operatingsystem
AC_CANONICAL_TARGET
only_clock_realtime=no
disable_getprotobyname=no

case "${target}" in
  *darwin*)
    only_clock_realtime=yes
    ;;
  *freebsd*)
    only_clock_realtime=yes
    ;;
  *openbsd*)
    only_clock_realtime=yes
    ;;
  *android*)
    disable_getprotobyname=yes
    ;;
esac

dnl Checks for libraries.

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

Paliak added 4 commits May 31, 2026 20:51
Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com>
Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com>
Signed-off-by: Paliak <91493239+Paliak@users.noreply.github.com>
@Paliak
Copy link
Copy Markdown
Author

Paliak commented May 31, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces conditional compilation to bypass getprotobyname on platforms like Android, falling back to default protocol constants (IPPROTO_ICMP and IPPROTO_ICMPV6). The reviewer suggests a more robust and idiomatic approach using Autoconf's standard feature detection (AC_CHECK_FUNCS([getprotobyname])) to define HAVE_GETPROTOBYNAME automatically, rather than hardcoding platform-specific checks and using a custom USE_GETPROTOBYNAME variable.

Comment thread configure.ac
Comment thread configure.ac
Comment thread configure.ac
Comment thread src/socket4.c
Comment thread src/socket6.c
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 87.992% (-0.008%) from 88.0% — Paliak:fix-getprotobyname-android into schweikert:develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants