From d0cc4d9e4b942d2bddd7754a7306751ce9ff68fe Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 23 Oct 2014 15:44:03 -0600 Subject: [PATCH] Fix inet_ntop() replacement on older systems without it. We only expose the prototype for net_ifs.c due to the use of socklen_t. --- configure | 14 ++++++++++++++ configure.ac | 4 ++++ include/sudo_compat.h | 11 ++++++++--- lib/util/inet_ntop.c | 2 +- src/net_ifs.c | 2 ++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/configure b/configure index a50f3d705..bcdc35d74 100755 --- a/configure +++ b/configure @@ -19216,6 +19216,20 @@ $as_echo "no" >&6; } fi LIBS="$OLIBS" +if test X"$found" != X"true"; then + case " $LIBOBJS " in + *" inet_ntop.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS inet_ntop.$ac_objext" + ;; +esac + + + for _sym in sudo_inet_ntop; do + COMPAT_EXP="${COMPAT_EXP}${_sym} +" + done + +fi OLIBS="$LIBS" LIBS="${LIBS} ${NET_LIBS}" found=false diff --git a/configure.ac b/configure.ac index be976daf3..b660d89e4 100644 --- a/configure.ac +++ b/configure.ac @@ -2686,6 +2686,10 @@ AC_CHECK_FUNC(inet_ntop, [ done ]) LIBS="$OLIBS" +if test X"$found" != X"true"; then + AC_LIBOBJ(inet_ntop) + SUDO_APPEND_COMPAT_EXP(sudo_inet_ntop) +fi dnl dnl If inet_pton(3) not in libc, check -lnsl and -linet dnl May need to link with *both* -lnsl and -lsocket due to unresolved symbols diff --git a/include/sudo_compat.h b/include/sudo_compat.h index f374ebde0..a314dc41a 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -19,8 +19,8 @@ * Materiel Command, USAF, under agreement number F39502-99-1-0512. */ -#ifndef _SUDO_MISSING_H -#define _SUDO_MISSING_H +#ifndef _SUDO_COMPAT_H +#define _SUDO_COMPAT_H #include #ifdef STDC_HEADERS @@ -467,6 +467,11 @@ __dso_public int sudo_clock_gettime(clockid_t clock_id, struct timespec *tp); # undef clock_gettime # define clock_gettime(_a, _b) sudo_clock_gettime((_a), (_b)) #endif /* HAVE_CLOCK_GETTIME */ +#if !defined(HAVE_INET_NTOP) && defined(_SUDO_NET_IFS_C) +__dso_public char *sudo_inet_ntop(int af, const void *src, char *dst, socklen_t size); +# undef inet_ntop +# define inet_ntop(_a, _b, _c, _d) sudo_inet_ntop((_a), (_b), (_c), (_d)) +#endif /* HAVE_INET_NTOP */ #ifndef HAVE_INET_PTON __dso_public int sudo_inet_pton(int af, const char *src, void *dst); # undef inet_pton @@ -478,4 +483,4 @@ __dso_public const char *sudo_getprogname(void); # define getprogname() sudo_getprogname() #endif /* HAVE_GETPROGNAME */ -#endif /* _SUDO_MISSING_H */ +#endif /* _SUDO_COMPAT_H */ diff --git a/lib/util/inet_ntop.c b/lib/util/inet_ntop.c index 28b6a9eb7..ebf87b3c4 100644 --- a/lib/util/inet_ntop.c +++ b/lib/util/inet_ntop.c @@ -211,7 +211,7 @@ inet_ntop6(const unsigned char *src, char *dst, socklen_t size) * Paul Vixie, 1996. */ const char * -inet_ntop(int af, const void *src, char *dst, socklen_t size) +sudo_inet_ntop(int af, const void *src, char *dst, socklen_t size) { switch (af) { case AF_INET: diff --git a/src/net_ifs.c b/src/net_ifs.c index 1cee550c9..157c9e3d4 100644 --- a/src/net_ifs.c +++ b/src/net_ifs.c @@ -84,6 +84,8 @@ struct rtentry; # include #endif +#define _SUDO_NET_IFS_C /* to expose sudo_inet_ntop in sudo_compat.h */ + #define DEFAULT_TEXT_DOMAIN "sudo" #include "sudo_gettext.h" /* must be included before sudo_compat.h */ -- 2.49.0