If the maintainer ever decides to update the package, I've attached two
patches against lft 3.1 I use in my own internal lft 3.1 package.
poll is pretty important; it makes lft use poll instead of assuming that
the read timeout passed to pcap will work. On Linux, the read timeout
doesn't work, so lft blocks when there isn't any other traffic on the
network.
useless-dependencies avoids some unnecessary dependencies.
Vernon
pcap on Linux doesn't support the read timeout, so lft would hang without any
other traffic coming in on the network. Use poll and non-blocking sockets
instead of assuming that the read timeout will work.
Index: lft-3.1/lft_lib.c
===================================================================
--- lft-3.1.orig/lft_lib.c
+++ lft-3.1/lft_lib.c
@@ -2641,6 +2641,8 @@
#if !defined(__CYGWIN__) && !defined(WIN32) && !defined(_WIN32)
char ebuf[PCAP_ERRBUF_SIZE];
/*static pcap_t *pd;*/
+ struct pollfd pollinfo;
+ int ret;
#endif
#ifdef BSD_IP_STACK
#if !defined(DARWIN) && !defined(NETBSD)
@@ -2716,6 +2718,12 @@
LFTErrHandler(sess, ERR_PCAP_DEV_UNAVAILABLE, ebuf);
return;
}
+
+ if (pcap_setnonblock(sess->pcapdescr, 1, ebuf)) {
+ LFTErrHandler(sess, WRN_OCHECK_FCNTLSET, ebuf);
+ if(sess->exit_state<0)
+ return;
+ }
#ifdef BSD_IP_STACK
#if !defined(DARWIN) && !defined(NETBSD)
bpfimmflag = 1;
@@ -2818,7 +2826,11 @@
break;
}
#else
- while (pcap_dispatch (sess->pcapdescr, -1, pcap_process_packet,
(u_char *)sess) >= 0) {
+ pollinfo.fd = pcap_get_selectable_fd(sess->pcapdescr);
+ pollinfo.events = POLLIN | POLLPRI;
+ do {
+ poll(&pollinfo, 1, 20);
+ ret = pcap_dispatch (sess->pcapdescr, -1, pcap_process_packet,
(u_char *)sess);
if(sess->exit_state<0)
break;
if (sess->noisy > 6)
@@ -2831,7 +2843,7 @@
break;
if(sess->exit_state<0)
break;
- }
+ } while (ret >= 0);
#endif
}
else
Index: lft-3.1/lft_btcptrace.c
===================================================================
--- lft-3.1.orig/lft_btcptrace.c
+++ lft-3.1/lft_btcptrace.c
@@ -925,8 +925,13 @@
break;
}
#else
- while(pcap_dispatch(sess->pcapdescr, -1, pcap_tcp_base_process_packet,
(u_char *)sess) >= 0)
- {
+ struct pollfd pollinfo;
+ int ret;
+ pollinfo.fd = pcap_get_selectable_fd(sess->pcapdescr);
+ pollinfo.events = POLLIN | POLLPRI;
+ do {
+ poll(&pollinfo, 1, 20);
+ ret = pcap_dispatch(sess->pcapdescr, -1,
pcap_tcp_base_process_packet, (u_char *)sess);
if(sess->exit_state<0)
break;
if(sess->noisy > 6)
@@ -939,6 +944,6 @@
break;
if(sess->exit_state<0)
break;
- }
+ } while (ret >= 0);
#endif
}
Index: lft-3.1/lft_icmptrace.c
===================================================================
--- lft-3.1.orig/lft_icmptrace.c
+++ lft-3.1/lft_icmptrace.c
@@ -775,8 +775,13 @@
break;
}
#else
- while(pcap_dispatch(sess->pcapdescr, -1, pcap_icmp_process_packet,
(u_char *)sess) >= 0)
- {
+ struct pollfd pollinfo;
+ int ret;
+ pollinfo.fd = pcap_get_selectable_fd(sess->pcapdescr);
+ pollinfo.events = POLLIN | POLLPRI;
+ do {
+ poll(&pollinfo, 1, 20);
+ ret = pcap_dispatch(sess->pcapdescr, -1,
pcap_icmp_process_packet, (u_char *)sess);
if(sess->exit_state<0)
break;
if(sess->noisy > 6)
@@ -789,7 +794,7 @@
break;
if(sess->exit_state<0)
break;
- }
+ } while (ret >= 0);
#endif
}
Index: lft-3.1/lft_types.h
===================================================================
--- lft-3.1.orig/lft_types.h
+++ lft-3.1/lft_types.h
@@ -87,6 +87,7 @@
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
+#include <poll.h>
#ifdef BSD
#include <machine/limits.h>
#endif
Avoid unnecessary dependencies.
Index: lft-3.1/config/configure.ac
===================================================================
--- lft-3.1.orig/config/configure.ac
+++ lft-3.1/config/configure.ac
@@ -23,10 +23,9 @@
AC_PROG_MAKE_SET
AC_PROG_INSTALL
-AC_CHECK_LIB(nsl, gethostbyname)
-AC_CHECK_LIB(socket, connect)
-AC_CHECK_LIB(resolv, inet_aton)
-AC_CHECK_LIB(m, sin)
+AC_SEARCH_LIBS(gethostbyname, nsl)
+AC_SEARCH_LIBS(connect, socket)
+AC_SEARCH_LIBS(inet_aton, resolv)
# Checks for header files and functions
AC_HEADER_STDC
@@ -148,7 +147,10 @@
# include <sys/socket.h>]], [[u_int i = sizeof(((struct sockaddr
*)0)->sa_len)]])],[AC_DEFINE(HAVE_SOCKADDR_SA_LEN)],[])
-AC_CHECK_LIB(pcap, pcap_lookupdev, , [
+AC_CHECK_LIB(pcap, pcap_lookupdev, [
+ LIBPCAP="-lpcap $LIBPCAP"
+ AC_SUBST(LIBPCAP)
+], [
AC_MSG_ERROR([
Can't find the pcap library (libpcap.a); install the pcap library (from
ftp://ftp.ee.lbl.gov/libpcap.tar.Z ) and/or use
Index: lft-3.1/configure
===================================================================
--- lft-3.1.orig/configure
+++ lft-3.1/configure
@@ -675,6 +675,7 @@
EGREP
ALLOCA
LIBOBJS
+LIBPCAP
LTLIBOBJS'
ac_subst_files=''
ac_precious_vars='build_alias
@@ -2870,14 +2871,12 @@
-
-{ echo "$as_me:$LINENO: checking for gethostbyname in -lnsl" >&5
-echo $ECHO_N "checking for gethostbyname in -lnsl... $ECHO_C" >&6; }
-if test "${ac_cv_lib_nsl_gethostbyname+set}" = set; then
+{ echo "$as_me:$LINENO: checking for library containing gethostbyname" >&5
+echo $ECHO_N "checking for library containing gethostbyname... $ECHO_C" >&6; }
+if test "${ac_cv_search_gethostbyname+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lnsl $LIBS"
+ ac_func_search_save_LIBS=$LIBS
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@@ -2900,7 +2899,14 @@
return 0;
}
_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
+for ac_lib in '' nsl; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ rm -f conftest.$ac_objext conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
@@ -2918,37 +2924,42 @@
test ! -s conftest.err
} && test -s conftest$ac_exeext &&
$as_test_x conftest$ac_exeext; then
- ac_cv_lib_nsl_gethostbyname=yes
+ ac_cv_search_gethostbyname=$ac_res
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
- ac_cv_lib_nsl_gethostbyname=no
+
fi
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
- conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+ conftest$ac_exeext
+ if test "${ac_cv_search_gethostbyname+set}" = set; then
+ break
fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_nsl_gethostbyname" >&5
-echo "${ECHO_T}$ac_cv_lib_nsl_gethostbyname" >&6; }
-if test $ac_cv_lib_nsl_gethostbyname = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBNSL 1
-_ACEOF
-
- LIBS="-lnsl $LIBS"
-
+done
+if test "${ac_cv_search_gethostbyname+set}" = set; then
+ :
+else
+ ac_cv_search_gethostbyname=no
fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_search_gethostbyname" >&5
+echo "${ECHO_T}$ac_cv_search_gethostbyname" >&6; }
+ac_res=$ac_cv_search_gethostbyname
+if test "$ac_res" != no; then
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+fi
-{ echo "$as_me:$LINENO: checking for connect in -lsocket" >&5
-echo $ECHO_N "checking for connect in -lsocket... $ECHO_C" >&6; }
-if test "${ac_cv_lib_socket_connect+set}" = set; then
+{ echo "$as_me:$LINENO: checking for library containing connect" >&5
+echo $ECHO_N "checking for library containing connect... $ECHO_C" >&6; }
+if test "${ac_cv_search_connect+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lsocket $LIBS"
+ ac_func_search_save_LIBS=$LIBS
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@@ -2971,7 +2982,14 @@
return 0;
}
_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
+for ac_lib in '' socket; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ rm -f conftest.$ac_objext conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
@@ -2989,37 +3007,42 @@
test ! -s conftest.err
} && test -s conftest$ac_exeext &&
$as_test_x conftest$ac_exeext; then
- ac_cv_lib_socket_connect=yes
+ ac_cv_search_connect=$ac_res
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
- ac_cv_lib_socket_connect=no
+
fi
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
- conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+ conftest$ac_exeext
+ if test "${ac_cv_search_connect+set}" = set; then
+ break
fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_socket_connect" >&5
-echo "${ECHO_T}$ac_cv_lib_socket_connect" >&6; }
-if test $ac_cv_lib_socket_connect = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBSOCKET 1
-_ACEOF
-
- LIBS="-lsocket $LIBS"
-
+done
+if test "${ac_cv_search_connect+set}" = set; then
+ :
+else
+ ac_cv_search_connect=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
fi
+{ echo "$as_me:$LINENO: result: $ac_cv_search_connect" >&5
+echo "${ECHO_T}$ac_cv_search_connect" >&6; }
+ac_res=$ac_cv_search_connect
+if test "$ac_res" != no; then
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+fi
-{ echo "$as_me:$LINENO: checking for inet_aton in -lresolv" >&5
-echo $ECHO_N "checking for inet_aton in -lresolv... $ECHO_C" >&6; }
-if test "${ac_cv_lib_resolv_inet_aton+set}" = set; then
+{ echo "$as_me:$LINENO: checking for library containing inet_aton" >&5
+echo $ECHO_N "checking for library containing inet_aton... $ECHO_C" >&6; }
+if test "${ac_cv_search_inet_aton+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lresolv $LIBS"
+ ac_func_search_save_LIBS=$LIBS
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@@ -3042,7 +3065,14 @@
return 0;
}
_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
+for ac_lib in '' resolv; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ rm -f conftest.$ac_objext conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
@@ -3060,97 +3090,33 @@
test ! -s conftest.err
} && test -s conftest$ac_exeext &&
$as_test_x conftest$ac_exeext; then
- ac_cv_lib_resolv_inet_aton=yes
+ ac_cv_search_inet_aton=$ac_res
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
- ac_cv_lib_resolv_inet_aton=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
- conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_resolv_inet_aton" >&5
-echo "${ECHO_T}$ac_cv_lib_resolv_inet_aton" >&6; }
-if test $ac_cv_lib_resolv_inet_aton = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBRESOLV 1
-_ACEOF
-
- LIBS="-lresolv $LIBS"
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+ conftest$ac_exeext
+ if test "${ac_cv_search_inet_aton+set}" = set; then
+ break
fi
-
-
-{ echo "$as_me:$LINENO: checking for sin in -lm" >&5
-echo $ECHO_N "checking for sin in -lm... $ECHO_C" >&6; }
-if test "${ac_cv_lib_m_sin+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lm $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-
-/* Override any GCC internal prototype to avoid an error.
- Use char because int might match the return type of a GCC
- builtin and then its argument prototype would still apply. */
-#ifdef __cplusplus
-extern "C"
-#endif
-char sin ();
-int
-main ()
-{
-return sin ();
- ;
- return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
- *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
- *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
- (eval "$ac_link") 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } && {
- test -z "$ac_c_werror_flag" ||
- test ! -s conftest.err
- } && test -s conftest$ac_exeext &&
- $as_test_x conftest$ac_exeext; then
- ac_cv_lib_m_sin=yes
+done
+if test "${ac_cv_search_inet_aton+set}" = set; then
+ :
else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_cv_lib_m_sin=no
+ ac_cv_search_inet_aton=no
fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
- conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_m_sin" >&5
-echo "${ECHO_T}$ac_cv_lib_m_sin" >&6; }
-if test $ac_cv_lib_m_sin = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBM 1
-_ACEOF
-
- LIBS="-lm $LIBS"
+{ echo "$as_me:$LINENO: result: $ac_cv_search_inet_aton" >&5
+echo "${ECHO_T}$ac_cv_search_inet_aton" >&6; }
+ac_res=$ac_cv_search_inet_aton
+if test "$ac_res" != no; then
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
fi
@@ -5789,7 +5755,6 @@
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-
{ echo "$as_me:$LINENO: checking for pcap_lookupdev in -lpcap" >&5
echo $ECHO_N "checking for pcap_lookupdev in -lpcap... $ECHO_C" >&6; }
if test "${ac_cv_lib_pcap_pcap_lookupdev+set}" = set; then
@@ -5852,11 +5817,9 @@
{ echo "$as_me:$LINENO: result: $ac_cv_lib_pcap_pcap_lookupdev" >&5
echo "${ECHO_T}$ac_cv_lib_pcap_pcap_lookupdev" >&6; }
if test $ac_cv_lib_pcap_pcap_lookupdev = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBPCAP 1
-_ACEOF
- LIBS="-lpcap $LIBS"
+ LIBPCAP="-lpcap $LIBPCAP"
+
else
@@ -6740,10 +6703,11 @@
EGREP!$EGREP$ac_delim
ALLOCA!$ALLOCA$ac_delim
LIBOBJS!$LIBOBJS$ac_delim
+LIBPCAP!$LIBPCAP$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 63; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 64; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
Index: lft-3.1/Makefile.in
===================================================================
--- lft-3.1.orig/Makefile.in
+++ lft-3.1/Makefile.in
@@ -23,6 +23,7 @@
c...@cc@
cfla...@cflags@
li...@libs@
+libpc...@libpcap@
ldfla...@ldflags@
CAT=cat
@@ -43,7 +44,7 @@
all: lft whob
lft: $(OBJS)
- $(CC) -o lft $(OBJS) $(LDFLAGS) $(LIBS)
+ $(CC) -o lft $(OBJS) $(LDFLAGS) $(LIBS) $(LIBPCAP)
whob: whois.o
$(CC) -o whob whois.c -DSTANDALONE $(LDFLAGS) $(LIBS)