Add ax_lib_socket_nsl.m4 macro

Add SOCKET_LIBS and NSL_LIBS to global LIBS variables on platforms
where it is required.

Make configure checks for getaddrinfo/gethostname unconditional,
that is handled with #ifdefs if necessary.

Change-Id: Ia874038454fb9cf3bdbf8e6fd829f319e331837e
Reviewed-on: https://code.wireshark.org/review/14560
Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
João Valverde 2016-03-22 05:49:00 +00:00 committed by João Valverde
parent b0db6a01a8
commit a1ed731413
7 changed files with 63 additions and 150 deletions

View File

@ -1350,8 +1350,6 @@ else()
endif()
set(LIBEPAN_LIBS
# @NSL_LIBS@ # -lnsl
# @SOCKET_LIBS@ # -lsocket
# @SSL_LIBS@ # -lcrypto
epan
# $(plugin_ldadd) # in case of static
@ -2129,8 +2127,6 @@ if(BUILD_randpkt)
wsutil
${M_LIBRARIES}
${PCAP_LIBRARIES}
# @SOCKET_LIBS@
# @NSL_LIBS@
${CARES_LIBRARIES}
${ZLIB_LIBRARIES}
)
@ -2256,8 +2252,6 @@ if(BUILD_dumpcap AND PCAP_FOUND)
caputils
${PCAP_LIBRARIES}
${CAP_LIBRARIES}
# @SOCKET_LIBS@
# @NSL_LIBS@
${GLIB2_LIBRARIES}
${GTHREAD2_LIBRARIES}
${ZLIB_LIBRARIES}

View File

@ -374,12 +374,6 @@ endif
# Libraries and plugin flags with which to link wireshark.
#
# Note that Wireshark, when built with a version of GTK+ that runs
# atop X11, doesn't have to be linked with @SOCKET_LIBS@ or @NSL_LIBS@,
# as those should also be included in @GTK_LIBS@ (as those are also
# needed for X applications, and GTK+ applications are X applications
# if the version of GTK+ they're built with runs atop X11).
#
# GTK_CFLAGS/GTK_LIBS is a strict superset of GLIB_CFLAGS/GLIB_LIBS
# (see configure.ac for pkg-config modules used).
#
@ -450,8 +444,6 @@ tshark_LDADD = \
$(plugin_ldadd) \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@C_ARES_LIBS@ \
@KRB5_LIBS@ \
@SYSTEMCONFIGURATION_FRAMEWORKS@ \
@ -475,8 +467,6 @@ tfshark_LDADD = \
$(plugin_ldadd) \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@KRB5_LIBS@ \
@SYSTEMCONFIGURATION_FRAMEWORKS@ \
@COREFOUNDATION_FRAMEWORKS@ \
@ -498,8 +488,6 @@ rawshark_LDADD = \
$(plugin_ldadd) \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@C_ARES_LIBS@ \
@KRB5_LIBS@ \
@SYSTEMCONFIGURATION_FRAMEWORKS@ \
@ -572,8 +560,6 @@ randpkt_LDADD = \
wsutil/libwsutil.la \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@C_ARES_LIBS@
dftest_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS)
@ -588,8 +574,6 @@ dftest_LDADD = \
$(plugin_ldadd) \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@C_ARES_LIBS@ \
@KRB5_LIBS@ \
@LIBGCRYPT_LIBS@ \
@ -605,8 +589,6 @@ echld_test_LDADD = \
wsutil/libwsutil.la \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@C_ARES_LIBS@
echld_test_DEPENDENCIES = \
@ -626,8 +608,6 @@ dumpcap_LDADD = \
wsutil/libwsutil.la \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@SYSTEMCONFIGURATION_FRAMEWORKS@ \
@COREFOUNDATION_FRAMEWORKS@ \
@LIBCAP_LIBS@ \

View File

@ -177,77 +177,6 @@ fi
])
#
# AC_WIRESHARK_GETADDRINFO_LIB_CHECK
#
# Checks whether we have "getaddrinfo()" and whether we need "-lnsl" to get it.
AC_DEFUN([AC_WIRESHARK_GETADDRINFO_LIB_CHECK],
[
AC_CHECK_FUNCS(getaddrinfo, ,
AC_CHECK_LIB(nsl, getaddrinfo,
[
NSL_LIBS="-lnsl"
AC_DEFINE(HAVE_GETADDRINFO, 1, [Defined if we have getaddrinfo])
]))
AC_SUBST(NSL_LIBS)
])
#
# AC_WIRESHARK_GETHOSTBY_LIB_CHECK
#
# Checks whether we need "-lnsl" to get "gethostby*()", which we use
# in "resolv.c".
#
# Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
# GNU Autoconf 2.13; the comment came from there.
# Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
#
AC_DEFUN([AC_WIRESHARK_GETHOSTBY_LIB_CHECK],
[
# msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
# to get the SysV transport functions.
# chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
# needs -lnsl.
# The nsl library prevents programs from opening the X display
# on Irix 5.2, according to dickey@clark.net.
AC_CHECK_FUNCS(gethostbyname, ,
AC_CHECK_LIB(nsl, gethostbyname,
[
NSL_LIBS="-lnsl"
AC_DEFINE(HAVE_GETHOSTBYNAME, 1, [Defined if we have gethostbyname])
]))
AC_SUBST(NSL_LIBS)
])
#
# AC_WIRESHARK_SOCKET_LIB_CHECK
#
# Checks whether we need "-lsocket" to get "socket()", which is used
# by libpcap on some platforms - and, in effect, "gethostbyname()" or
# "getaddrinfo()" on most if not all platforms (so that it can use NIS or
# DNS or... to look up host names).
#
# Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
# GNU Autoconf 2.13; the comment came from there.
# Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
#
# We use "connect" because that's what AC_PATH_XTRA did.
#
AC_DEFUN([AC_WIRESHARK_SOCKET_LIB_CHECK],
[
# lieder@skyler.mavd.honeywell.com says without -lsocket,
# socket/setsockopt and other routines are undefined under SCO ODT
# 2.0. But -lsocket is broken on IRIX 5.2 (and is not necessary
# on later versions), says simon@lia.di.epfl.ch: it contains
# gethostby* variants that don't use the nameserver (or something).
# -lsocket must be given before -lnsl if both are needed.
# We assume that if connect needs -lnsl, so does gethostbyname.
AC_CHECK_FUNC(connect, ,
AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
AC_SUBST(SOCKET_LIBS)
])
#
# AC_WIRESHARK_BREAKLOOP_TRY_LINK
#
@ -413,7 +342,7 @@ and did you also install that package?]]))
for extras in "-lcfg -lodm" "-lpfring"
do
AC_MSG_CHECKING([for pcap_open_live in -lpcap with $extras])
LIBS="-lpcap $extras"
LIBS="-lpcap $extras $ac_save_LIBS"
#
# XXX - can't we use AC_CHECK_LIB here?
#
@ -443,7 +372,7 @@ and did you also install that package?]]))
AC_MSG_ERROR([Can't link with library libpcap.])
fi
LIBS=$ac_save_LIBS
], $SOCKET_LIBS $NSL_LIBS)
])
fi
AC_SUBST(PCAP_LIBS)
@ -452,7 +381,7 @@ and did you also install that package?]]))
# libpcap.
#
ac_save_LIBS="$LIBS"
LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
LIBS="$PCAP_LIBS $LIBS"
AC_CHECK_FUNCS(pcap_open_dead pcap_freecode)
#
# pcap_breakloop may be present in the library but not declared
@ -572,7 +501,7 @@ install a newer version of the header file.])
AC_DEFUN([AC_WIRESHARK_PCAP_REMOTE_CHECK],
[
ac_save_LIBS="$LIBS"
LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
LIBS="$PCAP_LIBS $LIBS"
AC_DEFINE(HAVE_REMOTE, 1, [Define to 1 to enable remote
capturing feature in WinPcap library])
AC_CHECK_FUNCS(pcap_open)
@ -810,8 +739,7 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
# searches the specified directory.
#
# XXX - lib64?
wireshark_save_LIBS="$LIBS"
LIBS="$LIBS -L$lua_dir/lib"
LDFLAGS="-L$lua_dir/lib $LDFLAGS"
AC_SEARCH_LIBS(luaL_openlibs, [lua-${lua_ver} lua${lua_ver} lua],
[
LUA_LIBS="-L$lua_dir/lib $ac_cv_search_luaL_openlibs -lm"
@ -819,7 +747,6 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
],[
have_lua=no
], -lm)
LIBS="$wireshark_save_LIBS"
fi
fi
fi
@ -993,10 +920,9 @@ AC_DEFUN([AC_WIRESHARK_C_ARES_CHECK],
AC_CHECK_LIB(cares, ares_init,
[
C_ARES_LIBS=-lcares
AC_DEFINE(HAVE_C_ARES, 1, [Define to use c-ares library])
have_good_c_ares=yes
],, $SOCKET_LIBS $NSL_LIBS
)
AC_DEFINE(HAVE_C_ARES, 1, [Define to use c-ares library])
have_good_c_ares=yes
])
else
AC_MSG_RESULT(not required)
fi
@ -1158,7 +1084,7 @@ AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
found_krb5_kt_resolve=no
for extras in "" "-lresolv"
do
LIBS="$KRB5_LIBS $extras"
LIBS="$KRB5_LIBS $extras $wireshark_save_LIBS"
if test -z "$extras"
then
AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve])
@ -1173,11 +1099,12 @@ AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
],
[
#
# We found "krb5_kt_resolve()", and required
# the libraries in extras as well.
# We found "krb5_kt_resolve()".
#
AC_MSG_RESULT(yes)
KRB5_LIBS="$LIBS"
if test -n "$extras"; then
KRB5_LIBS="$KRB5_LIBS $extras"
fi
AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
if test "x$ac_krb5_version" = "xHEIMDAL"
then

View File

@ -539,6 +539,10 @@ AC_SUBST(FLOORL_LO)
AC_SEARCH_LIBS(lrint, m,
[AC_DEFINE(HAVE_LRINT, 1, [Define if you have the 'lrint' function.])])
#
# Check if we need to link with -lnsl and -lsocket
#
AX_LIB_SOCKET_NSL
#
# GUI toolkit options
@ -2176,10 +2180,6 @@ AC_SUBST(randpkt_man)
AC_SUBST(wiresharkfilter_man)
dnl Checks for "connect()", used as a proxy for "socket()" - and
dnl "-lsocket", if we need it to get "connect()".
AC_WIRESHARK_SOCKET_LIB_CHECK
dnl pcap check
AC_MSG_CHECKING(whether to use libpcap for packet capture)
@ -2664,30 +2664,8 @@ else
fi
AC_SUBST(C_ARES_LIBS)
if test "x$have_good_c_ares" != "xyes"; then
# We don't have an asynchronous name resolver, look for a synchronous one
dnl Checks for "getaddrinfo()" - and "-lnsl", if we need it to get
dnl "getaddrinfo()".
AC_WIRESHARK_GETADDRINFO_LIB_CHECK
if test "x$ac_cv_func_getaddrinfo" != "xyes" ; then
# We don't have the modern name resolver, try older stuff
dnl Checks for "gethostbyname()" - and "-lnsl", if we need it to get
dnl "gethostbyname()".
AC_WIRESHARK_GETHOSTBY_LIB_CHECK
if test "x$ac_cv_func_gethostbyname" != "xyes" ; then
# Hopefully this never actually happens.
# The code works even without name resolvers but we
# alert the user to this unusual condition.
AC_MSG_ERROR(Couldn't find any name resolvers!)
fi
AC_CHECK_FUNCS(gethostbyname2)
fi
fi
# Check for synchronous name resolvers
AC_CHECK_FUNCS([getaddrinfo gethostbyname gethostbyname2])
dnl GEOIP Check
GEOIP_LIBS=''

View File

@ -135,8 +135,6 @@ libwireshark_la_LIBADD = \
$(wslua_lib) \
${top_builddir}/wiretap/libwiretap.la \
${top_builddir}/wsutil/libwsutil.la \
@SOCKET_LIBS@ \
@NSL_LIBS@ \
@C_ARES_LIBS@ \
@LIBGCRYPT_LIBS@ \
@LIBGNUTLS_LIBS@ \

View File

@ -49,8 +49,7 @@ endif
androiddump_LDADD = \
../wiretap/libwiretap.la \
../wsutil/libwsutil.la \
@GLIB_LIBS@ \
@SOCKET_LIBS@
@GLIB_LIBS@
if ENABLE_STATIC
randpktdump_LDFLAGS = -Wl,-static -all-static
@ -63,8 +62,7 @@ randpktdump_LDADD = \
../randpkt_core/librandpkt_core.a \
../wiretap/libwiretap.la \
../wsutil/libwsutil.la \
@GLIB_LIBS@ \
@SOCKET_LIBS@
@GLIB_LIBS@
if ENABLE_STATIC
sshdump_LDFLAGS = -Wl,-static -all-static
@ -77,8 +75,7 @@ sshdump_LDADD = \
../wiretap/libwiretap.la \
../wsutil/libwsutil.la \
@GLIB_LIBS@ \
@LIBSSH_LIBS@ \
@SOCKET_LIBS@
@LIBSSH_LIBS@
if ENABLE_STATIC
ciscodump_LDFLAGS = -Wl,-static -all-static
@ -91,5 +88,4 @@ ciscodump_LDADD = \
../writecap/libwritecap.a \
../wsutil/libwsutil.la \
@GLIB_LIBS@ \
@LIBSSH_LIBS@ \
@SOCKET_LIBS@
@LIBSSH_LIBS@

40
m4/ax_lib_socket_nsl.m4 Normal file
View File

@ -0,0 +1,40 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_lib_socket_nsl.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_LIB_SOCKET_NSL
#
# DESCRIPTION
#
# This macro figures out what libraries are required on this platform to
# link sockets programs.
#
# The common cases are not to need any extra libraries, or to need
# -lsocket and -lnsl. We need to avoid linking with libnsl unless we need
# it, though, since on some OSes where it isn't necessary it will totally
# break networking. Unisys also includes gethostbyname() in libsocket but
# needs libnsl for socket().
#
# LICENSE
#
# Copyright (c) 2008 Russ Allbery <rra@stanford.edu>
# Copyright (c) 2008 Stepan Kasal <kasal@ucw.cz>
# Copyright (c) 2008 Warren Young <warren@etr-usa.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 6
AU_ALIAS([LIB_SOCKET_NSL], [AX_LIB_SOCKET_NSL])
AC_DEFUN([AX_LIB_SOCKET_NSL],
[
AC_SEARCH_LIBS([gethostbyname], [nsl])
AC_SEARCH_LIBS([socket], [socket], [], [
AC_CHECK_LIB([socket], [socket], [LIBS="-lsocket -lnsl $LIBS"],
[], [-lnsl])])
])