Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#299 updates for code climate and codacy #301

Merged
merged 7 commits into from
Mar 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
engines:
fixme:
enabled: false

ratings:
paths:
- "**.c"
- "**.h"

exclude_paths:
- libopts/
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#Tcpreplay
[![Build Status](https://travis-ci.org/appneta/tcpreplay.svg?branch=master)](https://travis-ci.org/appneta/tcpreplay)
[![Code Climate](https://codeclimate.com/github/appneta/tcpreplay.png)](https://codeclimate.com/github/appneta/tcpreplay)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/0e49d208c69e440182ba21109ecaf31d)](https://www.codacy.com/app/fklassen/tcpreplay?utm_source=github.com&utm_medium=referral&utm_content=appneta/tcpreplay&utm_campaign=badger)

Tcpreplay is a suite of [GPLv3] licensed utilities for UNIX (and Win32 under
[Cygwin]) operating systems for editing and replaying network traffic which
was previously captured by tools like [tcpdump] and [Ethereal]/[Wireshark].
Expand Down Expand Up @@ -230,10 +235,6 @@ Please visit our [wiki](http://tcpreplay.appneta.com).

or visit our [developers wiki](https://github.com/appneta/tcpreplay/wiki)

Build Status
============
[![Build Status](https://travis-ci.org/appneta/tcpreplay.svg?branch=master)](https://travis-ci.org/appneta/tcpreplay)

[GPLv3]: http://www.gnu.org/licenses/gpl-3.0.html
[netmap]: http://info.iet.unipi.it/~luigi/netmap/
[flow]: http://en.wikipedia.org/wiki/Traffic_flow_%28computer_networking%29
Expand Down
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rm -f config/config.guess config/config.sub config/ltmain.sh 2>/dev/null
rm -f aclocal.m4 2>/dev/null
aclocal -I libopts/m4/
if test -x "`which glibtoolize`" ; then
if test -x "$(which glibtoolize)" ; then
# Necessary under OS X
glibtoolize --copy --automake --force
else
Expand Down
40 changes: 20 additions & 20 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ case "$host_os" in
AC_MSG_CHECKING([what macOS compiler to use])

for _macosx_sdk in $with_macosx_sdk 10.8 10.9 10.10 10.11 10.12 10.13 10.14 10.15 10.16.10.17 10.18 10.19 10.20 11.0 11.1 11.2 11.3 11.4 11.5; do
MACOSX_SDK_PATH=`xcrun --sdk macosx${_macosx_sdk} --show-sdk-path 2> /dev/null`
MACOSX_SDK_PATH=$(xcrun --sdk macosx${_macosx_sdk} --show-sdk-path 2> /dev/null)
if test -d "$MACOSX_SDK_PATH"; then
with_macosx_sdk="${_macosx_sdk}"
break
else
MACOSX_SDK_PATH="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_macosx_sdk}.sdk"
MACOSX_SDK_PATH="$(xcode-select -print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_macosx_sdk}.sdk"
if test -d "$MACOSX_SDK_PATH"; then
with_macosx_sdk="${_macosx_sdk}"
break
fi
fi
done
if test -d "$MACOSX_SDK_PATH"; then
CC="`xcrun -find clang` -m64 -isysroot $MACOSX_SDK_PATH"
INSTALL_NAME_TOOL=`xcrun -find install_name_tool`
AR=`xcrun -find ar`
NM=`xcrun -find nm`
STRIP=`xcrun -find strip`
LIBTOOL=`xcrun -find libtool`
RANLIB=`xcrun -find ranlib`
CC="$(xcrun -find clang) -m64 -isysroot $MACOSX_SDK_PATH"
INSTALL_NAME_TOOL=$(xcrun -find install_name_tool)
AR=$(xcrun -find ar)
NM=$(xcrun -find nm)
STRIP=$(xcrun -find strip)
LIBTOOL=$(xcrun -find libtool)
RANLIB=$(xcrun -find ranlib)
AC_MSG_RESULT([$CC])
else
AC_MSG_RESULT([legacy])
Expand Down Expand Up @@ -132,7 +132,7 @@ AC_ARG_WITH(pfring-lib,

have_cygwin=no
AC_MSG_CHECKING([for cygwin development environment])
if test `echo $target | grep -c cygwin` -gt 0 ; then
if test $(echo $target | grep -c cygwin) -gt 0 ; then
AC_DEFINE([HAVE_WIN32], [1], [Windows/Cygwin])
AC_MSG_RESULT(yes)
have_cygwin=yes
Expand Down Expand Up @@ -171,9 +171,9 @@ AUTOGEN_VERSION="unknown - man pages will not be built"
if test -n "${AUTOGEN}" ; then
AC_MSG_CHECKING(for autogen version >= 5.18.x)
${AUTOGEN} -v >autogen.version
AUTOGEN_VERSION=`cat autogen.version | ${SED} 's|.* \([[0-9\.]]\{5,\}\).*|\1|'`
AUTOGEN_MAJOR=`echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 1`
AUTOGEN_MINOR=`echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 2`
AUTOGEN_VERSION=$(cat autogen.version | ${SED} 's|.* \([[0-9\.]]\{5,\}\).*|\1|')
AUTOGEN_MAJOR=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 1)
AUTOGEN_MINOR=$(echo ${AUTOGEN_VERSION} | ${CUT} -d '.' -f 2)
if ( test ${AUTOGEN_MAJOR} -eq 5 && test ${AUTOGEN_MINOR} -lt 18 ) || test ${AUTOGEN_MAJOR} -lt 5 ; then
AC_MSG_RESULT(no)
AC_MSG_WARN([${AUTOGEN} is too old (${AUTOGEN_VERSION}) for building from source code. Please upgrade to 5.18.4)])
Expand Down Expand Up @@ -1420,7 +1420,7 @@ if test x${disable_quick_tx} != xyes; then
dnl * Set destination directory for kernel modules

if test x${kerneluname} = x ; then
kerneluname=`uname -r`
kerneluname=$(uname -r)
fi
default_moduledir=/lib/modules/${kerneluname}/misc
AC_ARG_WITH(moduledir,
Expand Down Expand Up @@ -1466,9 +1466,9 @@ if test $have_cygwin = no ; then

for testdir in $trydnetdir /usr/local /opt/local $MACOSX_SDK_PATH/usr /usr ; do
if test -x ${testdir}/bin/dnet-config -a $founddnet = no ; then
LDNETINC="`$testdir/bin/dnet-config --cflags`"
LDNETLIB="`$testdir/bin/dnet-config --libs`"
libdnet_version="`$testdir/bin/dnet-config --version`"
LDNETINC="$($testdir/bin/dnet-config --cflags)"
LDNETLIB="$($testdir/bin/dnet-config --libs)"
libdnet_version="$($testdir/bin/dnet-config --version)"
founddnet=$testdir
fi
done
Expand Down Expand Up @@ -1612,9 +1612,9 @@ AC_ARG_WITH(pcapnav-config,
)

if test $pcncfg != no ; then
LNAVLIB=`$pcncfg --libs`
LNAV_CFLAGS=`$pcncfg --cflags`
PCAPNAV_VERSION=`$pcncfg --version`
LNAVLIB=$($pcncfg --libs)
LNAV_CFLAGS=$($pcncfg --cflags)
PCAPNAV_VERSION=$($pcncfg --version)
AC_SUBST(LNAVLIB)
AC_SUBST(LNAV_CFLAGS)
AC_DEFINE_UNQUOTED(PCAPNAV_VERSION, "$PCAPNAV_VERSION",
Expand Down
1 change: 1 addition & 0 deletions kernel/linux/example/pcapsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ bool read_pcap_file(char* filename, void** buffer, long *length) {
/* memory error */
if(*buffer == NULL) {
printf("Could not allocate %ld bytes of memory!\n", *length);
fclose(infile);
return false;
}

Expand Down
9 changes: 6 additions & 3 deletions src/common/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ parse_services(const char *file, tcpr_services_t *services)
uint16_t portc;
size_t nmatch = 3;
regmatch_t pmatch[3];
char regex[] = "([0-9]+)/(tcp|udp)"; /* matches the port as pmatch[1], service pmatch[2] */
static const char regex[] = "([0-9]+)/(tcp|udp)"; /* matches the port as pmatch[1], service pmatch[2] */

assert(file);
assert(services);

dbgx(1, "Parsing %s", file);
memset(service_line, '\0', MAXLINE);

/* mark all ports not a service */
memset(services->tcp, '\0', NUM_PORTS);
memset(services->udp, '\0', NUM_PORTS);
memset(&services->tcp[0], '\0', sizeof(services->tcp));
memset(&services->udp[0], '\0', sizeof(services->udp));

if ((service = fopen(file, "r")) == NULL) {
errx(-1, "Unable to open service file: %s\n%s", file, strerror(errno));
Expand Down
2 changes: 2 additions & 0 deletions src/fragroute/fragroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
void
fragroute_close(fragroute_t *ctx)
{
assert(ctx);
free(ctx->pktq);
free(ctx);
ctx = NULL;
pkt_close();
}


Expand Down
14 changes: 12 additions & 2 deletions src/fragroute/pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
#include "bget.h"
#include "pkt.h"

static struct pkt **pvbase;
static int pvlen;

void
pkt_init(int size)
{
bectl(NULL, malloc, free, sizeof(struct pkt) * size);
}

void
pkt_close(void)
{
if (pvbase) {
pvlen = 0;
free (pvbase);
}
}

struct pkt *
pkt_new(void)
{
Expand Down Expand Up @@ -273,8 +285,6 @@ pktq_reverse(struct pktq *pktq)
void
pktq_shuffle(rand_t *r, struct pktq *pktq)
{
static struct pkt **pvbase;
static int pvlen;
struct pkt *pkt;
int i;

Expand Down
1 change: 1 addition & 0 deletions src/fragroute/pkt.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct pkt {
TAILQ_HEAD(pktq, pkt);

void pkt_init(int size);
void pkt_close(void);

struct pkt *pkt_new(void);
struct pkt *pkt_dup(struct pkt *);
Expand Down
1 change: 0 additions & 1 deletion src/tcpedit/plugins/dlt_raw/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "tcpedit_stub.h"
#include "raw.h"

/* FIXME: edit these variables to taste */
static char dlt_name[] = "raw";
static char _U_ dlt_prefix[] = "raw";
static uint16_t dlt_value = DLT_RAW;
Expand Down
4 changes: 2 additions & 2 deletions src/tcpedit/plugins/dlt_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ done

# Files to have their name changed
for i in plugin.c.tmpl plugin.h plugin_opts.def plugin_api.c.tmpl plugin_api.h plugin_types.h ; do
OUTFILE=`echo $i | sed -E "s/plugin/${PLUGIN}/"`
OUTFILE=`echo $OUTFILE | sed -E "s/\.tmpl//"`
OUTFILE=$(echo $i | sed -E "s/plugin/${PLUGIN}/")
OUTFILE=$(echo $OUTFILE | sed -E "s/\.tmpl//")
OUTFILE="${PLUGINDIR}/${OUTFILE}"
if [ -f $OUTFILE ]; then
echo "Skipping $OUTFILE"
Expand Down
12 changes: 12 additions & 0 deletions src/tcprewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ main(int argc, char *argv[])
tcpdump_close(&tcpdump);
#endif

#ifdef ENABLE_FRAGROUTE
if (options.frag_ctx) {
fragroute_close(options.frag_ctx);
}
#endif

#ifdef ENABLE_DMALLOC
dmalloc_shutdown();
#endif
Expand Down Expand Up @@ -230,6 +236,9 @@ rewrite_packets(tcpedit_t *tcpedit, pcap_t *pin, pcap_dumper_t *pout)
int rcode;
#ifdef ENABLE_FRAGROUTE
int frag_len, proto;
#ifdef DEBUG
int i;
#endif
#endif

pkthdr_ptr = &pkthdr;
Expand Down Expand Up @@ -301,6 +310,9 @@ rewrite_packets(tcpedit_t *tcpedit, pcap_t *pin, pcap_dumper_t *pout)
(cache_result == TCPR_DIR_C2S && options.fragroute_dir == FRAGROUTE_DIR_C2S) ||
(cache_result == TCPR_DIR_S2C && options.fragroute_dir == FRAGROUTE_DIR_S2C))) {

#ifdef DEBUG
i = 0;
#endif
if (fragroute_process(options.frag_ctx, *pktdata, pkthdr_ptr->caplen) < 0)
errx(-1, "Error processing packet via fragroute: %s", options.frag_ctx->errbuf);

Expand Down