]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use pcap_dump_ftell() rather than casting a pcap_dumper_t * to a FILE *
authorguy <guy>
Fri, 3 Jun 2005 22:08:51 +0000 (22:08 +0000)
committerguy <guy>
Fri, 3 Jun 2005 22:08:51 +0000 (22:08 +0000)
and using ftell(); that won't necessarily work on Windows (if libpcap
was built with a different version of the C runtime library than tcpdump
is), and, even on UN*X, would break if a pcap_dumper_t * were ever made
something other than a FILE *.

Provide a pcap_dump_ftell() implementation that does that cheating cast
for use if libpcap doesn't have it (a pcap_dumper_t * is just a FILE *
on those older versions of libpcap).

FILES
INSTALL
acconfig.h
aclocal.m4
config.h.in
configure
pcap-missing.h
pcap_dump_ftell.c [new file with mode: 0644]
tcpdump.c

diff --git a/FILES b/FILES
index 2a0aeb5dde0bd2dc24590fd1b3a0d72ea2c97e2b..ebd02cbd7a71e6a9e75e5d1264890b610de3d6d5 100644 (file)
--- a/FILES
+++ b/FILES
@@ -103,6 +103,7 @@ oui.c
 oui.h
 packetdat.awk
 parsenfsfh.c
+pcap_dump_ftell.c
 pcap-missing.h
 pf.h
 pmap_prot.h
diff --git a/INSTALL b/INSTALL
index 1ace724d670428dc886a133eab7e15a303ea5229..fd3c0f208ec8e697048a7a06a7cfa330ce83dfd6 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -1,4 +1,4 @@
-@(#) $Header: /tcpdump/master/tcpdump/Attic/INSTALL,v 1.64 2005-05-21 20:18:12 guy Exp $ (LBL)
+@(#) $Header: /tcpdump/master/tcpdump/Attic/INSTALL,v 1.65 2005-06-03 22:08:51 guy Exp $ (LBL)
 
 If you have not built libpcap, do so first.  See the README
 file in this directory for the ftp location.
@@ -124,6 +124,8 @@ ospf.h              - Open Shortest Path First definitions
 ospf6.h                - IPv6 Open Shortest Path First definitions
 packetdat.awk  - TCP chunk summary awk script
 parsenfsfh.c   - Network File System file parser routines
+pcap_dump_ftell.c - pcap_dump_ftell() implementation, in case libpcap
+               doesn't have it
 pcap-missing.h - declarations of functions possibly missing from libpcap
 pf.h           - OpenBSD PF definitions
 pmap_prot.h    - definitions for ONC RPC portmapper protocol
index 2f462e1b5bc37b4043ab585de5a3e75ad94c7ff3..f28d52c23043db46ca097847b92008d18b8c6932 100644 (file)
@@ -85,6 +85,9 @@
 /* define if libpcap has pcap_datalink_val_to_description() */
 #undef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
 
+/* define if libpcap has pcap_dump_ftell() */
+#undef HAVE_PCAP_DUMP_FTELL
+
 /* define if you have getrpcbynumber() */
 #undef HAVE_GETRPCBYNUMBER
 
index 80c0ac4dce9c8fea37928d0f51744bf390601a06..aec2cfd18d2ae372b786191d42f2769e2af3cccc 100644 (file)
@@ -1,4 +1,4 @@
-dnl @(#) $Header: /tcpdump/master/tcpdump/aclocal.m4,v 1.111 2005-06-03 21:36:41 guy Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/tcpdump/aclocal.m4,v 1.112 2005-06-03 22:08:51 guy Exp $ (LBL)
 dnl
 dnl Copyright (c) 1995, 1996, 1997, 1998
 dnl    The Regents of the University of California.  All rights reserved.
@@ -352,6 +352,15 @@ AC_DEFUN(AC_LBL_LIBPCAP,
     dnl so just define the HAVE_ value if it's there.
     dnl
     AC_CHECK_FUNCS(pcap_breakloop)
+
+    dnl
+    dnl Check for "pcap_dump_ftell()" and use a substitute version
+    dnl if it's not present.
+    AC_CHECK_FUNC(pcap_dump_ftell,
+       AC_DEFINE(HAVE_PCAP_DUMP_FTELL),
+       [
+           AC_LIBOBJ(pcap_dump_ftell)
+       ])
 ])
 
 dnl
index 1088e51fabddcc1ad78fe5c24b56686b7eb84bf9..dbda50501ec08e87c71227953c3f5a6947c7d034 100644 (file)
@@ -85,6 +85,9 @@
 /* define if libpcap has pcap_datalink_val_to_description() */
 #undef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
 
+/* define if libpcap has pcap_dump_ftell() */
+#undef HAVE_PCAP_DUMP_FTELL
+
 /* define if you have getrpcbynumber() */
 #undef HAVE_GETRPCBYNUMBER
 
index d02ea5d4571b7b2cac303fd4e13accb5ec866379..93f6f7ef4bd80075ea917fbf681ec455786a1f34 100755 (executable)
--- a/configure
+++ b/configure
@@ -9749,6 +9749,115 @@ fi
 done
 
 
+                echo "$as_me:$LINENO: checking for pcap_dump_ftell" >&5
+echo $ECHO_N "checking for pcap_dump_ftell... $ECHO_C" >&6
+if test "${ac_cv_func_pcap_dump_ftell+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define pcap_dump_ftell to an innocuous variant, in case <limits.h> declares pcap_dump_ftell.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define pcap_dump_ftell innocuous_pcap_dump_ftell
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char pcap_dump_ftell (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef pcap_dump_ftell
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char pcap_dump_ftell ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_pcap_dump_ftell) || defined (__stub___pcap_dump_ftell)
+choke me
+#else
+char (*f) () = pcap_dump_ftell;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != pcap_dump_ftell;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&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); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_pcap_dump_ftell=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_pcap_dump_ftell=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_pcap_dump_ftell" >&5
+echo "${ECHO_T}$ac_cv_func_pcap_dump_ftell" >&6
+if test $ac_cv_func_pcap_dump_ftell = yes; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_PCAP_DUMP_FTELL 1
+_ACEOF
+
+else
+
+           case $LIBOBJS in
+    "pcap_dump_ftell.$ac_objext"   | \
+  *" pcap_dump_ftell.$ac_objext"   | \
+    "pcap_dump_ftell.$ac_objext "* | \
+  *" pcap_dump_ftell.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS pcap_dump_ftell.$ac_objext" ;;
+esac
+
+
+fi
+
+
 
 #
 # Check for these after AC_LBL_LIBPCAP, so we link with the appropriate
index 64e5b00bd2e6a4b825d578055b5ee30e3587e2e4..5c0ece25b313ae0da2e74d983ecd71a51ecdc829 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/pcap-missing.h,v 1.2 2003-11-18 23:09:42 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/pcap-missing.h,v 1.3 2005-06-03 22:08:52 guy Exp $ (LBL)
  */
 
 #ifndef tcpdump_pcap_missing_h
@@ -44,6 +44,10 @@ extern const char *pcap_datalink_val_to_name(int);
 extern const char *pcap_datalink_val_to_description(int);
 #endif
 
+#ifndef HAVE_PCAP_DUMP_FTELL
+extern long pcap_dump_ftell(pcap_dumper_t *);
+#endif
+
 #endif
 
 
diff --git a/pcap_dump_ftell.c b/pcap_dump_ftell.c
new file mode 100644 (file)
index 0000000..6eb3a4a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/tcpdump/pcap_dump_ftell.c,v 1.1 2005-06-03 22:08:52 guy Exp $ (LBL)";
+#endif
+
+#include <stdio.h>
+#include <pcap.h>
+
+#include "pcap-missing.h"
+
+long
+pcap_dump_ftell(pcap_dumper_t *p)
+{
+       return (ftell((FILE *)p));
+}
index b4d41c97c1f45724c5ee67da21e0d294e33b184d..bb6b88b7a81ac69c49a3a237e46cfdb86ce005d7 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -30,7 +30,7 @@ static const char copyright[] _U_ =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.257 2005-05-22 21:19:40 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.258 2005-06-03 22:08:53 guy Exp $ (LBL)";
 #endif
 
 /*
@@ -1151,7 +1151,7 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
         * larger than Cflag - the last packet written to the
         * file could put it over Cflag.
         */
-       if (ftell((FILE *)dump_info->p) > Cflag) {
+       if (pcap_dump_ftell(dump_info->p) > Cflag) {
                /*
                 * Close the current file and open a new one.
                 */