Put pcapio.c into a writecap library, and use it.

Change-Id: Ib89f345c072a38bc01f0513366a4bdae3bf6f08e
Reviewed-on: https://code.wireshark.org/review/14615
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-03-24 13:00:07 -07:00
parent 67bd2cc511
commit a4aa8930bb
19 changed files with 352 additions and 15 deletions

1
.gitignore vendored
View File

@ -71,6 +71,7 @@ androiddump
autom4te.cache
capinfos
captype
ciscodump
compile
config.h
config.h.in

View File

@ -1020,6 +1020,7 @@ add_subdirectory( randpkt_core )
add_subdirectory( tools/lemon )
add_subdirectory( ui )
add_subdirectory( wiretap )
add_subdirectory( writecap )
add_subdirectory( wsutil )
if(NOT WIN32)
@ -1208,6 +1209,7 @@ set( IN_FILES
ui/gtk/doxygen.cfg.in
ui/qt/doxygen.cfg.in
wireshark.pc.in
writecap/doxygen.cfg.in
)
foreach( _in_file ${IN_FILES} )
get_filename_component( _path ${_in_file} PATH )
@ -1232,6 +1234,7 @@ link_directories(
${CMAKE_BINARY_DIR}/epan
${CMAKE_BINARY_DIR}/randpkt_core
${CMAKE_BINARY_DIR}/wiretap
${CMAKE_BINARY_DIR}/writecap
${CMAKE_BINARY_DIR}/wsutil
)
@ -2142,13 +2145,13 @@ endif()
if(BUILD_text2pcap)
set(text2pcap_LIBS
writecap
wsutil
${M_LIBRARIES}
${ZLIB_LIBRARIES}
)
set(text2pcap_CLEAN_FILES
text2pcap.c
pcapio.c
)
set(text2pcap_FILES
${text2pcap_CLEAN_FILES}
@ -2248,6 +2251,7 @@ endif()
if(BUILD_dumpcap AND PCAP_FOUND)
set(dumpcap_LIBS
writecap
wsutil
caputils
${PCAP_LIBRARIES}
@ -2267,7 +2271,6 @@ if(BUILD_dumpcap AND PCAP_FOUND)
conditions.c
dumpcap.c
filter_files.c
pcapio.c
ringbuffer.c
sync_pipe_write.c
${CMAKE_BINARY_DIR}/image/dumpcap.rc
@ -2376,6 +2379,7 @@ endif()
if(ENABLE_EXTCAP AND BUILD_ciscodump AND LIBSSH_FOUND)
set(ciscodump_LIBS
writecap
wsutil
${GLIB2_LIBRARIES}
${CMAKE_DL_LIBS}
@ -2388,7 +2392,6 @@ if(ENABLE_EXTCAP AND BUILD_ciscodump AND LIBSSH_FOUND)
extcap/ciscodump.c
extcap/extcap-base.c
extcap/ssh-base.c
pcapio.c
)
add_executable(ciscodump WIN32 ${ciscodump_FILES})

View File

@ -518,6 +518,7 @@ text2pcap_CFLAGS = $(GENERATED_CFLAGS)
# Libraries with which to link text2pcap.
text2pcap_LDADD = \
writecap/libwritecap.a \
wsutil/libwsutil.la \
@GLIB_LIBS@
@ -600,6 +601,7 @@ echld_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS)
echld_test_LDADD = \
epan/libwireshark.la \
echld/libechld.la \
writecap/libwritecap.a \
wsutil/libwsutil.la \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@ -620,6 +622,7 @@ dumpcap_LDFLAGS = $(AM_LDFLAGS) $(PIE_LDFLAGS)
# Libraries with which to link dumpcap.
dumpcap_LDADD = \
caputils/libcaputils.a \
writecap/libwritecap.a \
wsutil/libwsutil.la \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@ -775,6 +778,7 @@ DIST_SUBDIRS = \
randpkt_core \
tools \
wiretap \
writecap \
wsutil \
extcap \
docbook
@ -782,6 +786,7 @@ DIST_SUBDIRS = \
SUBDIRS = \
tools \
wsutil \
writecap \
wiretap \
epan \
capchild \
@ -1066,6 +1071,7 @@ checkapi: checkapi_local
cd epan/dissectors && $(MAKE) checkapi
cd plugins && $(MAKE) checkapi
cd randpkt_core && $(MAKE) checkapi
cd writecap && $(MAKE) checkapi
cd wsutil && $(MAKE) checkapi
wsar_html: doxygen.cfg doxygen_global.cfg FORCE

View File

@ -102,12 +102,10 @@ rawshark_SOURCES = \
# text2pcap specifics
text2pcap_SOURCES = \
pcapio.c \
text2pcap.c \
text2pcap-scanner.l
text2pcap_INCLUDES = \
pcapio.h \
text2pcap.h
# mergecap specifics
@ -141,7 +139,6 @@ echld_test_SOURCES = \
capture_stop_conditions.c \
cfile.c \
conditions.c \
pcapio.c \
ringbuffer.c \
sync_pipe_write.c
@ -156,7 +153,6 @@ dumpcap_SOURCES = \
conditions.c \
dumpcap.c \
filter_files.c \
pcapio.c \
ringbuffer.c \
sync_pipe_write.c
@ -164,7 +160,6 @@ dumpcap_SOURCES = \
dumpcap_INCLUDES = \
capture_stop_conditions.h \
conditions.h \
pcapio.h \
ringbuffer.h
# this target needed for distribution only

View File

@ -168,12 +168,14 @@ reordercap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
text2pcap_LIBS= \
wsock32.lib user32.lib \
writecap\libwritecap.lib \
wsutil\libwsutil.lib \
$(GLIB_LIBS)
dumpcap_LIBS= \
wsock32.lib user32.lib \
caputils\libcaputils.lib \
writecap\libwritecap.lib \
wsutil\libwsutil.lib \
$(GLIB_LIBS)
@ -393,10 +395,10 @@ reordercap.exe : $(LIBS_CHECK) config.h $(reordercap_OBJECTS) wsutil\libwsutil.
mt.exe -nologo -manifest "reordercap.exe.manifest" -outputresource:reordercap.exe;1
!ENDIF
text2pcap.exe : $(LIBS_CHECK) config.h text2pcap.obj text2pcap-scanner.obj pcapio.obj wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib image\text2pcap.res
text2pcap.exe : $(LIBS_CHECK) config.h text2pcap.obj text2pcap-scanner.obj writecap\libwritecap.lib wsutil\libwsutil.lib wiretap\wiretap-$(WTAP_VERSION).lib image\text2pcap.res
@echo Linking $@
$(LINK) @<<
/OUT:text2pcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) text2pcap.obj text2pcap-scanner.obj pcapio.obj $(text2pcap_LIBS) image\text2pcap.res
/OUT:text2pcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) text2pcap.obj text2pcap-scanner.obj $(text2pcap_LIBS) image\text2pcap.res
<<
!IFDEF MANIFEST_INFO_REQUIRED
mt.exe -nologo -manifest "text2pcap.exe.manifest" -outputresource:text2pcap.exe;1
@ -420,7 +422,7 @@ randpkt.exe : $(randpkt_OBJECTS) randpkt_core
mt.exe -nologo -manifest "randpkt.exe.manifest" -outputresource:randpkt.exe;1
!ENDIF
dumpcap.exe : $(LIBS_CHECK) config.h $(dumpcap_OBJECTS) caputils wsutil\libwsutil.lib image\dumpcap.res
dumpcap.exe : $(LIBS_CHECK) config.h $(dumpcap_OBJECTS) caputils writecap\libwritecap.lib wsutil\libwsutil.lib image\dumpcap.res
@echo Linking $@
$(LINK) @<<
/OUT:dumpcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) $(dumpcap_LIBS) $(dumpcap_OBJECTS) image\dumpcap.res

View File

@ -3329,6 +3329,8 @@ AC_OUTPUT(
tools/Makefile
tools/lemon/Makefile
wiretap/Makefile
writecap/Makefile
writecap/doxygen.cfg
wsutil/Makefile
echld/Makefile
_CUSTOM_AC_OUTPUT_

View File

@ -85,7 +85,7 @@
#include "caputils/capture-wpcap.h"
#endif /* _WIN32 */
#include "pcapio.h"
#include "writecap/pcapio.h"
#ifdef _WIN32
#include <wsutil/unicode-utils.h>

View File

@ -88,7 +88,7 @@ endif
# Libraries and plugin flags with which to link ciscodump.
ciscodump_LDADD = \
../wiretap/libwiretap.la \
../writecap/libwritecap.a \
../wsutil/libwsutil.la \
@GLIB_LIBS@ \
@LIBSSH_LIBS@ \

View File

@ -65,6 +65,7 @@ ciscodump_OBJECTS = $(ciscodump_SOURCES:.c=.obj)
ciscodump_WSLIBS = \
..\wiretap\wiretap-$(WTAP_VERSION).lib \
..\writecap\libwritecap.lib \
..\wsutil\libwsutil.lib
ciscodump_LIBS = $(ciscodump_WSLIBS) \

View File

@ -27,7 +27,7 @@
#include <extcap/extcap-base.h>
#include <wsutil/interface.h>
#include <extcap/ssh-base.h>
#include <pcapio.h>
#include <writecap/pcapio.h>
#include <errno.h>
#include <string.h>

View File

@ -138,7 +138,7 @@
# include "wsutil/strptime.h"
#endif
#include "pcapio.h"
#include "writecap/pcapio.h"
#include "text2pcap.h"
#ifdef _WIN32

21
writecap/.editorconfig Normal file
View File

@ -0,0 +1,21 @@
#
# Editor configuration
#
# http://editorconfig.org/
#
[capture-pcap-util-unix.[ch]]
indent_style = tab
indent_size = tab
[capture-pcap-util.[ch]]
indent_style = tab
indent_size = tab
[capture-wpcap.[ch]]
indent_style = tab
indent_size = tab
[ws80211_utils.[ch]]
indent_style = tab
indent_size = tab

45
writecap/CMakeLists.txt Normal file
View File

@ -0,0 +1,45 @@
# CMakeLists.txt
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
set(WRITECAP_SRC
pcapio.c
)
set(CLEAN_FILES
${WRITECAP_SRC}
)
if (WERROR_COMMON_FLAGS)
set_source_files_properties(
${CLEAN_FILES}
PROPERTIES
COMPILE_FLAGS ${WERROR_COMMON_FLAGS}
)
endif()
add_library(writecap STATIC
${WRITECAP_SRC}
)
set_target_properties(writecap PROPERTIES
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER "Libs")

81
writecap/Makefile.am Normal file
View File

@ -0,0 +1,81 @@
# Makefile.am
# Automake file for the "write capture file" routines for Wireshark
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include Makefile.common
include $(top_srcdir)/Makefile.am.inc
AM_CPPFLAGS = $(INCLUDEDIRS) $(WS_CPPFLAGS) $(GLIB_CFLAGS)
noinst_LIBRARIES = libwritecap.a
CLEANFILES = \
doxygen-writecap.tag \
libwritecap.a \
*~
MAINTAINERCLEANFILES = \
$(GENERATED_FILES) \
Makefile.in
EXTRA_DIST = \
.editorconfig \
$(GENERATOR_FILES) \
CMakeLists.txt \
doxygen.cfg.in \
Makefile.common \
Makefile.nmake
# All sources that should be put in the source distribution tarball
libwritecap_a_SOURCES = \
$(WRITECAP_SRC) \
$(noinst_HEADERS)
#
# This is used to build dumpcap, and dumpcap is, if possible, built as
# a position-independent executable (for address space layout randomization,
# as it might be running with extra privileges), so this library needs
# to be built that way as well.
#
libwritecap_a_CFLAGS = $(AM_CFLAGS) $(PIE_CFLAGS)
libwritecap_a_DEPENDENCIES =
doxygen:
if HAVE_DOXYGEN
$(DOXYGEN) doxygen.cfg
endif # HAVE_DOXYGEN
wsar_html: doxygen.cfg ../doxygen_global.cfg
if HAVE_DOXYGEN
(umask 022 ; $(DOXYGEN) doxygen.cfg)
endif
checkapi: checkapi-base checkapi-todo
checkapi-base:
$(PERL) $(top_srcdir)/tools/checkAPIs.pl -g deprecated-gtk -build \
-sourcedir=$(srcdir) \
$(WRITECAP_SRC)
checkapi-todo:
$(PERL) $(top_srcdir)/tools/checkAPIs.pl -M -g deprecated-gtk-todo -build \
-sourcedir=$(srcdir) \
$(WRITECAP_SRC)

28
writecap/Makefile.common Normal file
View File

@ -0,0 +1,28 @@
# Makefile.common
# Contains the stuff from Makefile.am and Makefile.nmake that is
# a) common to both files and
# b) portable between both files
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
WRITECAP_SRC = \
pcapio.c
noinst_HEADERS = \
pcapio.h

71
writecap/Makefile.nmake Normal file
View File

@ -0,0 +1,71 @@
## Makefile for building wireshark.exe with Microsoft C and nmake
## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake
#
include ..\config.nmake
include ..\Makefile.nmake.inc
include Makefile.common
############### no need to modify below this line #########
# We use GENERATED_CFLAGS to get around flex's non-LLP64-compliant output
GENERATED_CFLAGS=\
$(STANDARD_CFLAGS) \
/Zm800 \
/I.. $(GLIB_CFLAGS)
CFLAGS=$(WARNINGS_ARE_ERRORS) $(GENERATED_CFLAGS)
.c.obj::
$(CC) $(CFLAGS) $(WSUG_CFLAGS) -Fd.\ -c $<
# if you add files here, be sure to include them also in Makefile.am EXTRA_DIST
WRITECAP_OBJECTS = \
$(WRITECAP_SRC:.c=.obj)
RUNLEX=../tools/runlex.sh
libcaputils.lib : ..\config.h $(WRITECAP_OBJECTS)
link /lib /out:libcaputils.lib $(WRITECAP_OBJECTS)
clean:
rm -f $(WRITECAP_OBJECTS) $(WIRESHARK_TAP_OBJECTS) libcaputils.lib \
*.nativecodeanalysis.xml *.pdb *.sbr \
doxygen.cfg html/*.*
if exist html rmdir html
distclean: clean
maintainer-clean: distclean
rm -f $(GENERATED_FILES)
# convert doxygen.cfg.in to doxygen.cfg with stamped version info
doxygen.cfg: ..\config.nmake doxygen.cfg.in
!IFDEF DOXYGEN
sed -e s/@VERSION@/$(VERSION)/ \
< doxygen.cfg.in > $@
!ENDIF
doxygen-run:
!IFDEF DOXYGEN
$(DOXYGEN) doxygen.cfg
!ENDIF
# MS html help compiler hhc returns 1 on success, but as nmake expects 0 it would stop here.
# the prepended -1 will raise the accepted error levels of nmake, so it will continue
doxygen.chm:
!IFDEF HHC
-1 $(HHC) html\index.hhp
!ENDIF
doxygen: doxygen.cfg doxygen-run doxygen.chm
checkapi: checkapi-base checkapi-todo
checkapi-base:
$(PERL) ../tools/checkAPIs.pl -g deprecated-gtk -build \
$(WRITECAP_SRC)
checkapi-todo:
$(PERL) ../tools/checkAPIs.pl -M -g deprecated-gtk-todo -build \
$(WRITECAP_SRC)

81
writecap/doxygen.cfg.in Normal file
View File

@ -0,0 +1,81 @@
# @configure_input@
@INCLUDE = ../doxygen_global.cfg
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
PROJECT_NAME = "Wireshark Capture Utilities Library"
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER = @VERSION@
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
# If a relative path is entered, it will be relative to the location
# where doxygen was started. If left blank the current directory will be used.
OUTPUT_DIRECTORY = ../wsar_html
# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
# put in front of it. If left blank `html' will be used as the default path.
HTML_OUTPUT = caputils
# The TAGFILES option can be used to specify one or more tagfiles.
# Optionally an initial location of the external documentation
# can be added for each tagfile. The format of a tag file without
# this location is as follows:
#
# TAGFILES = file1 file2 ...
# Adding location for the tag files is done as follows:
#
# TAGFILES = file1=loc1 "file2 = loc2" ...
# where "loc1" and "loc2" can be relative or absolute paths or
# URLs. If a location is present for each tag, the installdox tool
# does not have to be run to correct the links.
# Note that each tag file must have a unique name
# (where the name does NOT include the path)
# If a tag file is not located in the directory in which doxygen
# is run, you must also specify the path to the tagfile here.
TAGFILES = ../doxygen-core.tag=..
# When a file name is specified after GENERATE_TAGFILE, doxygen will create
# a tag file that is based on the input files it reads.
GENERATE_TAGFILE = doxygen-caputils.tag
# The RECURSIVE tag can be used to turn specify whether or not subdirectories
# should be searched for input files as well. Possible values are YES and NO.
# If left blank NO is used.
RECURSIVE = YES
# The EXCLUDE tag can be used to specify files and/or directories that should
# excluded from the INPUT source files. This way you can easily exclude a
# subdirectory from a directory tree whose root is specified with the INPUT tag.
EXCLUDE =
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories
# that are symbolic links (a Unix filesystem feature) are excluded from the input.
EXCLUDE_SYMLINKS = NO
# If the value of the INPUT tag contains directories, you can use the
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
# certain files from those directories.
EXCLUDE_PATTERNS =
# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
# be used to specify the file name of the resulting .chm file. You
# can add a path in front of the file if the result should not be
# written to the html output directory.
CHM_FILE = wireshark-caputils.chm