How to properly check for -lresolv and resolv.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey there,

I've just quelled a bunch of obselscence warnings for 2.70/2.71 in OpenDMARC, so now I'm looking at the rest of it.

In our project, we're doing the following to detect if we need -lresolv (bottom of mail).

I'm also seeing this for the definitions of AC_MACRO_RESOLV:

Macro: AC_HEADER_RESOLV
Checks for header resolv.h, checking for prerequisites first. To properly use resolv.h, your code should contain something like the following:

#ifdef HAVE_SYS_TYPES_H
#  include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
#  include <netinet/in.h>   /* inet_ functions / structs */
#endif
#ifdef HAVE_ARPA_NAMESER_H
#  include <arpa/nameser.h> /* DNS HEADER struct */
#endif
#ifdef HAVE_NETDB_H
#  include <netdb.h>
#endif
#include <resolv.h>

So there seems to be a good way to quiesce the need for resolv.h but not -lresolv. This feels disjoint. Am I missing something?

MTR does the following, which feels a *little* cleaner:

# Find resolver library.
AC_CHECK_FUNC([res_query], [RESOLV_LIBS=""], [
  AC_CHECK_LIB([resolv], [__res_query], [RESOLV_LIBS="-lresolv"], [
    AC_CHECK_LIB([resolv], [res_query], [RESOLV_LIBS="-lresolv"], [
      AC_CHECK_LIB([bind], [res_query], [RESOLV_LIBS="-lbind"], [
        AC_MSG_ERROR([No resolver library found])
      ])
    ])
  ])
])
dnl MacOS has res_query in libc, but needs libresolv for dn_expand().
AS_IF([test "x" = "x$RESOLV_LIBS"], [
  AC_CHECK_LIB([resolv], [dn_expand], [RESOLV_LIBS="-lresolv"])
])
AC_SUBST([RESOLV_LIBS])

Is there a simpler way in more modern autoconfs??

-Dan



#
# See if we will need -lresolv
#
dnscheck='
#include "confdefs.h"
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
int main() {
res_mkquery (0, 0, 0, 0, 0, 0, 0, 0, 0);
dn_expand (0, 0, 0, 0, 0);
dn_skipname (0, 0);
dn_comp (0, 0, 0, 0, 0);
return 0;
}'
AC_MSG_CHECKING([whether the resolver works without -lresolv])
LIBRESOLV=
AC_LINK_IFELSE([AC_LANG_SOURCE([
$dnscheck
])] , [
        AC_MSG_RESULT(yes)
] , [
        AC_MSG_RESULT(no)
        AC_MSG_CHECKING([whether the resolver works with -lresolv])
        saved_LIBS="$LIBS"
        LIBS=-lresolv
        AC_LINK_IFELSE([AC_LANG_SOURCE([
$dnscheck
        ])] , [
                AC_MSG_RESULT(yes)
                LIBRESOLV=-lresolv
        ] , [
                AC_MSG_RESULT(no)
                AC_MSG_ERROR([need workable resolver library])
        ])
        LIBS="$saved_LIBS"
])
AC_SUBST([LIBRESOLV])

--

"Ca. Tas. Tro. Phy."

-John Smedley, March 28th 1998, 3AM

--------Dan Mahoney--------
Techie,  Sysadmin,  WebGeek
Gushi on efnet/undernet IRC
FB:  fb.com/DanielMahoneyIV
LI:   linkedin.com/in/gushi
Site:  http://www.gushi.org
---------------------------





[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux