{"thread":{"id":"52743","subject":"Fix inet_ntop and inet_pton on Solaris","startedAt":"2020-02-03T15:23:00Z","lastAt":"2020-02-14T06:50:43Z","messageCount":3,"participants":["Jeffrey Walton","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"391044","messageId":"CAH8yC8kaWXbN+RYMJnM9em7KKW54+N07JtyS1MZk0qppD=m2BA@mail.gmail.com","threadId":"52743","inReplyTo":null,"subject":"Fix inet_ntop and inet_pton on Solaris","fromName":"Jeffrey Walton","fromEmail":"noloader@gmail.com","sentAt":"2020-02-03T15:22:46Z","receivedAt":"2020-02-03T15:23:00Z","isPatch":false,"sender":{"key":"noloader@gmail.com","avatar":null},"body":"Hi Everyone,\n\ninet_ntop and inet_pton were not being detected properly on modern on\nSolaris. This patch revisits the the socket gear configuration on\nSunOS and brings it up to date for Solaris 11.\n\nAccording to configure.ac, the three or four functions of interest\ninclude hstrerror, inet_ntop and inet_pton. The libraries of interest\nare -lresolv -lsocket -lnsl. The configure tests now look for\ninet_ntop and inet_pton in -lsocket -lnsl per the man page. If not\nfound, the configure tests fall back to existing behavior by searching\nin -lresolv. And if not found in -lresolv, then NO_INET_NTOP and\nNO_INET_PTON are set.\n\nHere's the configure fly-by:\n\nchecking for socket... no\nchecking for library containing socket... no\nchecking for inet_ntop... no\nchecking for library containing inet_ntop... -lnsl\nchecking for inet_pton... yes\nchecking for hstrerror... no\nchecking for library containing hstrerror... -lresolv\n\nAnd config.status:\n\n$ /usr/gnu/bin/grep -E 'RESOLV|SOCKET|NSL' config.status\nNEEDS_RESOLV=YesPlease\nNEEDS_SOCKET=YesPlease\nNEEDS_NSL=YesPlease\n\nJeff\n\n\ndiff --git a/Makefile b/Makefile\nindex 09f98b777c..7166b19ab4 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1461,15 +1461,15 @@ ifndef LIBC_CONTAINS_LIBINTL\n \tEXTLIBS += -lintl\n endif\n endif\n+ifdef NEEDS_RESOLV\n+\tEXTLIBS += -lresolv\n+endif\n ifdef NEEDS_SOCKET\n \tEXTLIBS += -lsocket\n endif\n ifdef NEEDS_NSL\n \tEXTLIBS += -lnsl\n endif\n-ifdef NEEDS_RESOLV\n-\tEXTLIBS += -lresolv\n-endif\n ifdef NO_D_TYPE_IN_DIRENT\n \tBASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT\n endif\ndiff --git a/configure.ac b/configure.ac\nindex 66aedb9288..b83a0e970d 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -711,40 +711,58 @@ GIT_UNSTASH_FLAGS($ZLIB_PATH)\n \n GIT_CONF_SUBST([NO_DEFLATE_BOUND])\n \n+#\n+# The next few tests will define NEEDS_RESOLV, NEEDS_SOCKET or\n+# NEEDS_NSL if linking with libresolv, libsocket and libnsl\n+# provides some of the functions we would normally get from libc.\n+NEEDS_RESOLV=\n+NEEDS_SOCKET=\n+NEEDS_NSL=\n+\n #\n # Define NEEDS_SOCKET if linking with libc is not enough (SunOS,\n # Patrick Mauritz).\n-AC_CHECK_LIB([c], [socket],\n-[NEEDS_SOCKET=],\n-[NEEDS_SOCKET=YesPlease])\n-GIT_CONF_SUBST([NEEDS_SOCKET])\n-test -n \"$NEEDS_SOCKET\" && LIBS=\"$LIBS -lsocket\"\n+AC_CHECK_FUNC([socket],\n+    [],\n+    [AC_SEARCH_LIBS([socket], [c],\n+       [NEEDS_SOCKET=],\n+       [NEEDS_SOCKET=YesPlease])\n+])\n \n #\n-# The next few tests will define NEEDS_RESOLV if linking with\n-# libresolv provides some of the functions we would normally get\n-# from libc.\n-NEEDS_RESOLV=\n-#\n-# Define NO_INET_NTOP if linking with -lresolv is not enough.\n-# Solaris 2.7 in particular hos inet_ntop in -lresolv.\n+# Define NO_INET_NTOP if linking with -lresolv, -lsocket and -lnsl\n+# is not enough. Solaris 11 provides inet_ntop in -lsocket -lnsl.\n+# Solaris 2.7 provides inet_ntop in -lresolv.\n NO_INET_NTOP=\n AC_CHECK_FUNC([inet_ntop],\n     [],\n-    [AC_CHECK_LIB([resolv], [inet_ntop],\n-\t[NEEDS_RESOLV=YesPlease],\n-\t[NO_INET_NTOP=YesPlease])\n+    [AC_SEARCH_LIBS([inet_ntop], [socket nsl],\n+       [NEEDS_SOCKET=YesPlease; NEEDS_NSL=YesPlease],\n+       [AC_CHECK_FUNC([inet_ntop],\n+          [],\n+          [AC_SEARCH_LIBS([inet_ntop], [resolv],\n+          [NEEDS_RESOLV=YesPlease],\n+          [NO_INET_PTON=YesPlease])\n+       ])\n+    ])\n ])\n GIT_CONF_SUBST([NO_INET_NTOP])\n #\n-# Define NO_INET_PTON if linking with -lresolv is not enough.\n-# Solaris 2.7 in particular hos inet_pton in -lresolv.\n+# Define NO_INET_PTON if linking with -lresolv, -lsocket and -lnsl\n+# is not enough. Solaris 11 provides inet_pton in -lsocket -lnsl.\n+# Solaris 2.7 provides inet_pton in -lresolv.\n NO_INET_PTON=\n AC_CHECK_FUNC([inet_pton],\n     [],\n-    [AC_CHECK_LIB([resolv], [inet_pton],\n-\t[NEEDS_RESOLV=YesPlease],\n-\t[NO_INET_PTON=YesPlease])\n+    [AC_SEARCH_LIBS([inet_pton], [socket nsl],\n+       [NEEDS_SOCKET=YesPlease; NEEDS_NSL=YesPlease],\n+       [AC_CHECK_FUNC([inet_pton],\n+          [],\n+          [AC_SEARCH_LIBS([inet_pton], [resolv],\n+          [NEEDS_RESOLV=YesPlease],\n+          [NO_INET_PTON=YesPlease])\n+       ])\n+    ])\n ])\n GIT_CONF_SUBST([NO_INET_PTON])\n #\n@@ -753,19 +771,26 @@ GIT_CONF_SUBST([NO_INET_PTON])\n NO_HSTRERROR=\n AC_CHECK_FUNC([hstrerror],\n     [],\n-    [AC_CHECK_LIB([resolv], [hstrerror],\n-\t[NEEDS_RESOLV=YesPlease],\n-\t[NO_HSTRERROR=YesPlease])\n+    [AC_SEARCH_LIBS([hstrerror], [resolv],\n+       [NEEDS_RESOLV=YesPlease],\n+       [NO_HSTRERROR=YesPlease])\n ])\n GIT_CONF_SUBST([NO_HSTRERROR])\n \n dnl This must go after all the possible places for its initialization,\n dnl in the AC_CHECK_FUNC invocations above.\n GIT_CONF_SUBST([NEEDS_RESOLV])\n+GIT_CONF_SUBST([NEEDS_SOCKET])\n+GIT_CONF_SUBST([NEEDS_NSL])\n+\n #\n-# If any of the above tests determined that -lresolv is needed at\n-# build-time, also set it here for remaining configure-time checks.\n+# If any of the above tests determined that -lresolv, -lsocket or -lnsl\n+# are needed at build-time, also set it here for remaining configure-time\n+# checks. The Sun man pages list library order as -lresolv -lsocket -lnsl.\n test -n \"$NEEDS_RESOLV\" && LIBS=\"$LIBS -lresolv\"\n+test -n \"$NEEDS_SOCKET\" && LIBS=\"$LIBS -lsocket\"\n+test -n \"$NEEDS_NSL\" && LIBS=\"$LIBS -lnsl\"\n+\n \n AC_CHECK_LIB([c], [basename],\n [NEEDS_LIBGEN=],\n"},{"id":"391065","messageId":"CAH8yC8njDV9t+qF=EwFftVW5OkwKzaDMR-7ZGOBnqPbdt1R95A@mail.gmail.com","threadId":"52743","inReplyTo":"CAH8yC8kaWXbN+RYMJnM9em7KKW54+N07JtyS1MZk0qppD=m2BA@mail.gmail.com","subject":"Re: Fix inet_ntop and inet_pton on Solaris","fromName":"Jeffrey Walton","fromEmail":"noloader@gmail.com","sentAt":"2020-02-04T00:00:43Z","receivedAt":"2020-02-04T00:00:57Z","isPatch":false,"sender":{"key":"noloader@gmail.com","avatar":null},"body":"On Mon, Feb 3, 2020 at 10:22 AM Jeffrey Walton <noloader@gmail.com> wrote:\n>\n> Hi Everyone,\n>\n> inet_ntop and inet_pton were not being detected properly on modern on\n> Solaris. This patch revisits the the socket gear configuration on\n> SunOS and brings it up to date for Solaris 11.\n>\n> According to configure.ac, the three or four functions of interest\n> include hstrerror, inet_ntop and inet_pton. The libraries of interest\n> are -lresolv -lsocket -lnsl. The configure tests now look for\n> inet_ntop and inet_pton in -lsocket -lnsl per the man page. If not\n> found, the configure tests fall back to existing behavior by searching\n> in -lresolv. And if not found in -lresolv, then NO_INET_NTOP and\n> NO_INET_PTON are set.\n>\n> Here's the configure fly-by:\n>\n> checking for socket... no\n> checking for library containing socket... no\n> checking for inet_ntop... no\n> checking for library containing inet_ntop... -lnsl\n> checking for inet_pton... yes\n> checking for hstrerror... no\n> checking for library containing hstrerror... -lresolv\n>\n> And config.status:\n>\n> $ /usr/gnu/bin/grep -E 'RESOLV|SOCKET|NSL' config.status\n> NEEDS_RESOLV=YesPlease\n> NEEDS_SOCKET=YesPlease\n> NEEDS_NSL=YesPlease\n\nThe patch tested good on Linux (Ubuntu 18.04), Solaris 11 (SunOS 5.11)\nand Darwin (OS X 10.9).\n\nIt is the same patch used for Git Master maint branch and Git 2.25.0\nrelease tarball.\n\nJeff\n"},{"id":"391743","messageId":"20200214065041.GF605125@coredump.intra.peff.net","threadId":"52743","inReplyTo":"CAH8yC8kaWXbN+RYMJnM9em7KKW54+N07JtyS1MZk0qppD=m2BA@mail.gmail.com","subject":"Re: Fix inet_ntop and inet_pton on Solaris","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-02-14T06:50:41Z","receivedAt":"2020-02-14T06:50:43Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 03, 2020 at 10:22:46AM -0500, Jeffrey Walton wrote:\n\n> inet_ntop and inet_pton were not being detected properly on modern on\n> Solaris. This patch revisits the the socket gear configuration on\n> SunOS and brings it up to date for Solaris 11.\n> \n> According to configure.ac, the three or four functions of interest\n> include hstrerror, inet_ntop and inet_pton. The libraries of interest\n> are -lresolv -lsocket -lnsl. The configure tests now look for\n> inet_ntop and inet_pton in -lsocket -lnsl per the man page. If not\n> found, the configure tests fall back to existing behavior by searching\n> in -lresolv. And if not found in -lresolv, then NO_INET_NTOP and\n> NO_INET_PTON are set.\n\nThis makes sense, and the patch looks plausibly correct (which is the\nbest I can say given my general lack of autoconf knowledge).\n\nI was a little surprised by this hunk:\n\n> diff --git a/Makefile b/Makefile\n> index 09f98b777c..7166b19ab4 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1461,15 +1461,15 @@ ifndef LIBC_CONTAINS_LIBINTL\n>  \tEXTLIBS += -lintl\n>  endif\n>  endif\n> +ifdef NEEDS_RESOLV\n> +\tEXTLIBS += -lresolv\n> +endif\n>  ifdef NEEDS_SOCKET\n>  \tEXTLIBS += -lsocket\n>  endif\n>  ifdef NEEDS_NSL\n>  \tEXTLIBS += -lnsl\n>  endif\n> -ifdef NEEDS_RESOLV\n> -\tEXTLIBS += -lresolv\n> -endif\n\nBut I guess it is trying to mimic the \"-lresolv -lsocket -lnsl\" order\nyou mentioned in the Solaris manpage. You should be able to test if\nthat's necessary by compiling with:\n\n  make NEEDS_RESOLV=Yes NEEDS_SOCKET=Yes NEEDS_NSL=Yes\n\nIf so, that ordering switch could probably happen as a separate commit\nbefore the configure.ac change.\n\n> diff --git a/configure.ac b/configure.ac\n> index 66aedb9288..b83a0e970d 100644\n> --- a/configure.ac\n> +++ b/configure.ac\n\nThe rest of it looks OK to me. Do you want to send it as a regular Git\npatch with a commit message and your signoff (see SubmittingPatches)?\n\n-Peff\n"}]}