aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-09-29 14:49:22 -0700
committerGuy Harris <guy@alum.mit.edu>2017-09-29 14:49:22 -0700
commit8bac534951f44d0a3e3e7951c79c95d587fc234b (patch)
treec71e194a12214de9e845690b3f9650bc7a40f238
parentf00cf656dc7d58d18c26191ed0ae325dccb91031 (diff)
Add pcap_dump_ftell64().
If file offsets are 64-bit, this will return an un-truncated offset.
-rw-r--r--CMakeLists.txt13
-rw-r--r--Makefile.in1
-rw-r--r--cmake/FindFseeko.cmake85
-rw-r--r--pcap/pcap.h1
-rw-r--r--pcap_dump_ftell.3pcap17
-rw-r--r--sf-pcap.c39
6 files changed, 155 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f45f5ae8..adda6183 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -425,6 +425,19 @@ if(NOT WIN32)
#
add_definitions(${LFS_DEFINITIONS})
endif()
+
+ #
+ # Check for fseeko as well.
+ #
+ include(FindFseeko)
+ if(FSEEKO_FOUND)
+ set(HAVE_FSEEKO ON)
+
+ #
+ # Add the required #defines.
+ #
+ add_definitions(${FSEEKO_DEFINITIONS})
+ endif()
endif()
if(INET6)
diff --git a/Makefile.in b/Makefile.in
index d2b7d68c..0e51ce7d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -283,6 +283,7 @@ EXTRA_DIST = \
chmod_bpf \
cmake_uninstall.cmake.in \
cmakeconfig.h.in \
+ cmake/FindFseeko.cmake \
cmake/FindLFS.cmake \
cmake/FindPacket.cmake \
cmake/have_siocglifconf.c \
diff --git a/cmake/FindFseeko.cmake b/cmake/FindFseeko.cmake
new file mode 100644
index 00000000..ca53a5a6
--- /dev/null
+++ b/cmake/FindFseeko.cmake
@@ -0,0 +1,85 @@
+# CMake support for fseeko
+#
+# Based on FindLFS.cmake by
+# Copyright (C) 2016 Julian Andres Klode <jak@debian.org>.
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+# This defines the following variables
+#
+# FSEEKO_DEFINITIONS - List of definitions to pass to add_definitions()
+# FSEEKO_COMPILE_OPTIONS - List of definitions to pass to add_compile_options()
+# FSEEKO_LIBRARIES - List of libraries and linker flags
+# FSEEKO_FOUND - If there is Large files support
+#
+
+include(CheckCSourceCompiles)
+include(FindPackageHandleStandardArgs)
+include(CMakePushCheckState)
+
+# Check for the availability of fseeko()
+# The cases handled are:
+#
+# * Native fseeko()
+# * Preprocessor flag -D_LARGEFILE_SOURCE
+#
+function(_fseeko_check)
+ set(_fseeko_cppflags)
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_QUIET 1)
+ set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS})
+ message(STATUS "Looking for native fseeko support")
+ check_symbol_exists(fseeko stdio.h fseeko_native)
+ cmake_pop_check_state()
+ if (fseeko_native)
+ message(STATUS "Looking for native fseeko support - found")
+ set(FSEEKO_FOUND TRUE)
+ else()
+ message(STATUS "Looking for native fseeko support - not found")
+ endif()
+
+ if (NOT FSEEKO_FOUND)
+ # See if it's available with _LARGEFILE_SOURCE.
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_QUIET 1)
+ set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS} "-D_LARGEFILE_SOURCE")
+ check_symbol_exists(fseeko stdio.h fseeko_need_largefile_source)
+ cmake_pop_check_state()
+ if (fseeko_need_largefile_source)
+ message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - found")
+ set(FSEEKO_FOUND TRUE)
+ set(_fseeko_cppflags "-D_LARGEFILE_SOURCE")
+ else()
+ message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - not found")
+ endif()
+ endif()
+
+ set(FSEEKO_DEFINITIONS ${_fseeko_cppflags} CACHE STRING "Extra definitions for fseeko support")
+ set(FSEEKO_COMPILE_OPTIONS "" CACHE STRING "Extra compiler options for fseeko support")
+ set(FSEEKO_LIBRARIES "" CACHE STRING "Extra definitions for fseeko support")
+ set(FSEEKO_FOUND ${FSEEKO_FOUND} CACHE INTERNAL "Found fseeko")
+endfunction()
+
+if (NOT FSEEKO_FOUND)
+ _fseeko_check()
+endif()
+
+find_package_handle_standard_args(FSEEKO "Could not find fseeko. Set FSEEKO_DEFINITIONS, FSEEKO_COMPILE_OPTIONS, FSEEKO_LIBRARIES." FSEEKO_FOUND)
diff --git a/pcap/pcap.h b/pcap/pcap.h
index 67186a0b..7031ddc8 100644
--- a/pcap/pcap.h
+++ b/pcap/pcap.h
@@ -479,6 +479,7 @@ PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
PCAP_API FILE *pcap_dump_file(pcap_dumper_t *);
PCAP_API long pcap_dump_ftell(pcap_dumper_t *);
+PCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *);
PCAP_API int pcap_dump_flush(pcap_dumper_t *);
PCAP_API void pcap_dump_close(pcap_dumper_t *);
PCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
diff --git a/pcap_dump_ftell.3pcap b/pcap_dump_ftell.3pcap
index 757e9482..01dbc64c 100644
--- a/pcap_dump_ftell.3pcap
+++ b/pcap_dump_ftell.3pcap
@@ -19,7 +19,7 @@
.\"
.TH PCAP_DUMP_FTELL 3PCAP "3 January 2014"
.SH NAME
-pcap_dump_ftell \- get the current file offset for a savefile being written
+pcap_dump_ftell, pcap_dump_ftell64 \- get the current file offset for a savefile being written
.SH SYNOPSIS
.nf
.ft B
@@ -28,6 +28,8 @@ pcap_dump_ftell \- get the current file offset for a savefile being written
.LP
.ft B
long pcap_dump_ftell(pcap_dumper_t *p);
+.ft B
+int64_t pcap_dump_ftell64(pcap_dumper_t *p);
.ft
.fi
.SH DESCRIPTION
@@ -38,5 +40,18 @@ number of bytes written by
and
.BR pcap_dump() .
\-1 is returned on error.
+If the current file position does not fit in a
+.BR long ,
+it will be truncated; this can happen on 32-bit UNIX-like systems with
+large file support and on Windows.
+.B pcap_dump_ftell64()
+returns the current file position in a
+.BR int64_t ,
+so if file offsets that don't fit in a
+.B long
+but that fit in a
+.B int64_t
+are supported, this will return the file offset without truncation.
+\-1 is returned on error.
.SH SEE ALSO
pcap(3PCAP), pcap_dump_open(3PCAP), pcap_dump(3PCAP)
diff --git a/sf-pcap.c b/sf-pcap.c
index 38ddf17a..979b9c41 100644
--- a/sf-pcap.c
+++ b/sf-pcap.c
@@ -1009,6 +1009,45 @@ pcap_dump_ftell(pcap_dumper_t *p)
return (ftell((FILE *)p));
}
+#if defined(HAVE_FSEEKO)
+/*
+ * We have fseeko(), so we have ftello().
+ * If we have large file support (files larger than 2^31-1 bytes),
+ * ftello() will give us a current file position with more than 32
+ * bits.
+ */
+int64_t
+pcap_dump_ftell64(pcap_dumper_t *p)
+{
+ return (ftello((FILE *)p));
+}
+#elif defined(_MSC_VER)
+/*
+ * We have Visual Studio; we support only 2005 and later, so we have
+ * _ftelli64().
+ */
+int64_t
+pcap_dump_ftell64(pcap_dumper_t *p)
+{
+ return (_ftelli64((FILE *)p));
+}
+#else
+/*
+ * We don't have ftello() or _ftelli64(), so fall back on ftell().
+ * Either long is 64 bits, in which case ftell() should suffice,
+ * or this is probably an older 32-bit UN*X without large file
+ * support, which means you'll probably get errors trying to
+ * write files > 2^31-1, so it won't matter anyway.
+ *
+ * XXX - what about MinGW?
+ */
+int64_t
+pcap_dump_ftell64(pcap_dumper_t *p)
+{
+ return (ftell((FILE *)p));
+}
+#endif
+
int
pcap_dump_flush(pcap_dumper_t *p)
{