Skip to content

Commit 11d4f84

Browse files
fklassenGabriel Ganne
authored and
Gabriel Ganne
committed
appneta#299 updates for code climate and codacy (appneta#301)
* appneta#299 update README.md for code climate * Update README.md * Add Codacy badge * Update .codeclimate.yml disable fixme
1 parent 2646d69 commit 11d4f84

File tree

12 files changed

+73
-33
lines changed

12 files changed

+73
-33
lines changed

.codeclimate.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
engines:
2+
fixme:
3+
enabled: false
4+
5+
ratings:
6+
paths:
7+
- "**.c"
8+
- "**.h"
9+
10+
exclude_paths:
11+
- libopts/

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#Tcpreplay
2+
[![Build Status](https://travis-ci.org/appneta/tcpreplay.svg?branch=master)](https://travis-ci.org/appneta/tcpreplay)
3+
[![Code Climate](https://codeclimate.com/github/appneta/tcpreplay.png)](https://codeclimate.com/github/appneta/tcpreplay)
4+
[![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)
5+
16
Tcpreplay is a suite of [GPLv3] licensed utilities for UNIX (and Win32 under
27
[Cygwin]) operating systems for editing and replaying network traffic which
38
was previously captured by tools like [tcpdump] and [Ethereal]/[Wireshark].
@@ -230,10 +235,6 @@ Please visit our [wiki](http://tcpreplay.appneta.com).
230235

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

233-
Build Status
234-
============
235-
[![Build Status](https://travis-ci.org/appneta/tcpreplay.svg?branch=master)](https://travis-ci.org/appneta/tcpreplay)
236-
237238
[GPLv3]: http://www.gnu.org/licenses/gpl-3.0.html
238239
[netmap]: http://info.iet.unipi.it/~luigi/netmap/
239240
[flow]: http://en.wikipedia.org/wiki/Traffic_flow_%28computer_networking%29

autogen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
rm -f config/config.guess config/config.sub config/ltmain.sh 2>/dev/null
33
rm -f aclocal.m4 2>/dev/null
44
aclocal -I libopts/m4/
5-
if test -x "`which glibtoolize`" ; then
5+
if test -x "$(which glibtoolize)" ; then
66
# Necessary under OS X
77
glibtoolize --copy --automake --force
88
else

configure.ac

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,26 @@ case "$host_os" in
8484
AC_MSG_CHECKING([what macOS compiler to use])
8585

8686
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
87-
MACOSX_SDK_PATH=`xcrun --sdk macosx${_macosx_sdk} --show-sdk-path 2> /dev/null`
87+
MACOSX_SDK_PATH=$(xcrun --sdk macosx${_macosx_sdk} --show-sdk-path 2> /dev/null)
8888
if test -d "$MACOSX_SDK_PATH"; then
8989
with_macosx_sdk="${_macosx_sdk}"
9090
break
9191
else
92-
MACOSX_SDK_PATH="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_macosx_sdk}.sdk"
92+
MACOSX_SDK_PATH="$(xcode-select -print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_macosx_sdk}.sdk"
9393
if test -d "$MACOSX_SDK_PATH"; then
9494
with_macosx_sdk="${_macosx_sdk}"
9595
break
9696
fi
9797
fi
9898
done
9999
if test -d "$MACOSX_SDK_PATH"; then
100-
CC="`xcrun -find clang` -m64 -isysroot $MACOSX_SDK_PATH"
101-
INSTALL_NAME_TOOL=`xcrun -find install_name_tool`
102-
AR=`xcrun -find ar`
103-
NM=`xcrun -find nm`
104-
STRIP=`xcrun -find strip`
105-
LIBTOOL=`xcrun -find libtool`
106-
RANLIB=`xcrun -find ranlib`
100+
CC="$(xcrun -find clang) -m64 -isysroot $MACOSX_SDK_PATH"
101+
INSTALL_NAME_TOOL=$(xcrun -find install_name_tool)
102+
AR=$(xcrun -find ar)
103+
NM=$(xcrun -find nm)
104+
STRIP=$(xcrun -find strip)
105+
LIBTOOL=$(xcrun -find libtool)
106+
RANLIB=$(xcrun -find ranlib)
107107
AC_MSG_RESULT([$CC])
108108
else
109109
AC_MSG_RESULT([legacy])
@@ -132,7 +132,7 @@ AC_ARG_WITH(pfring-lib,
132132

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

14221422
if test x${kerneluname} = x ; then
1423-
kerneluname=`uname -r`
1423+
kerneluname=$(uname -r)
14241424
fi
14251425
default_moduledir=/lib/modules/${kerneluname}/misc
14261426
AC_ARG_WITH(moduledir,
@@ -1466,9 +1466,9 @@ if test $have_cygwin = no ; then
14661466

14671467
for testdir in $trydnetdir /usr/local /opt/local $MACOSX_SDK_PATH/usr /usr ; do
14681468
if test -x ${testdir}/bin/dnet-config -a $founddnet = no ; then
1469-
LDNETINC="`$testdir/bin/dnet-config --cflags`"
1470-
LDNETLIB="`$testdir/bin/dnet-config --libs`"
1471-
libdnet_version="`$testdir/bin/dnet-config --version`"
1469+
LDNETINC="$($testdir/bin/dnet-config --cflags)"
1470+
LDNETLIB="$($testdir/bin/dnet-config --libs)"
1471+
libdnet_version="$($testdir/bin/dnet-config --version)"
14721472
founddnet=$testdir
14731473
fi
14741474
done
@@ -1612,9 +1612,9 @@ AC_ARG_WITH(pcapnav-config,
16121612
)
16131613

16141614
if test $pcncfg != no ; then
1615-
LNAVLIB=`$pcncfg --libs`
1616-
LNAV_CFLAGS=`$pcncfg --cflags`
1617-
PCAPNAV_VERSION=`$pcncfg --version`
1615+
LNAVLIB=$($pcncfg --libs)
1616+
LNAV_CFLAGS=$($pcncfg --cflags)
1617+
PCAPNAV_VERSION=$($pcncfg --version)
16181618
AC_SUBST(LNAVLIB)
16191619
AC_SUBST(LNAV_CFLAGS)
16201620
AC_DEFINE_UNQUOTED(PCAPNAV_VERSION, "$PCAPNAV_VERSION",

kernel/linux/example/pcapsend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ bool read_pcap_file(char* filename, void** buffer, long *length) {
8888
/* memory error */
8989
if(*buffer == NULL) {
9090
printf("Could not allocate %ld bytes of memory!\n", *length);
91+
fclose(infile);
9192
return false;
9293
}
9394

src/common/services.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ parse_services(const char *file, tcpr_services_t *services)
4040
uint16_t portc;
4141
size_t nmatch = 3;
4242
regmatch_t pmatch[3];
43-
char regex[] = "([0-9]+)/(tcp|udp)"; /* matches the port as pmatch[1], service pmatch[2] */
43+
static const char regex[] = "([0-9]+)/(tcp|udp)"; /* matches the port as pmatch[1], service pmatch[2] */
44+
45+
assert(file);
46+
assert(services);
4447

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

4851
/* mark all ports not a service */
49-
memset(services->tcp, '\0', NUM_PORTS);
50-
memset(services->udp, '\0', NUM_PORTS);
52+
memset(&services->tcp[0], '\0', sizeof(services->tcp));
53+
memset(&services->udp[0], '\0', sizeof(services->udp));
5154

5255
if ((service = fopen(file, "r")) == NULL) {
5356
errx(-1, "Unable to open service file: %s\n%s", file, strerror(errno));

src/fragroute/fragroute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
void
4040
fragroute_close(fragroute_t *ctx)
4141
{
42+
assert(ctx);
4243
free(ctx->pktq);
4344
free(ctx);
4445
ctx = NULL;
46+
pkt_close();
4547
}
4648

4749

src/fragroute/pkt.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,24 @@
1717
#include "bget.h"
1818
#include "pkt.h"
1919

20+
static struct pkt **pvbase;
21+
static int pvlen;
22+
2023
void
2124
pkt_init(int size)
2225
{
2326
bectl(NULL, malloc, free, sizeof(struct pkt) * size);
2427
}
2528

29+
void
30+
pkt_close(void)
31+
{
32+
if (pvbase) {
33+
pvlen = 0;
34+
free (pvbase);
35+
}
36+
}
37+
2638
struct pkt *
2739
pkt_new(void)
2840
{
@@ -273,8 +285,6 @@ pktq_reverse(struct pktq *pktq)
273285
void
274286
pktq_shuffle(rand_t *r, struct pktq *pktq)
275287
{
276-
static struct pkt **pvbase;
277-
static int pvlen;
278288
struct pkt *pkt;
279289
int i;
280290

src/fragroute/pkt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct pkt {
7474
TAILQ_HEAD(pktq, pkt);
7575

7676
void pkt_init(int size);
77+
void pkt_close(void);
7778

7879
struct pkt *pkt_new(void);
7980
struct pkt *pkt_dup(struct pkt *);

src/tcpedit/plugins/dlt_raw/raw.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "tcpedit_stub.h"
2929
#include "raw.h"
3030

31-
/* FIXME: edit these variables to taste */
3231
static char dlt_name[] = "raw";
3332
static char _U_ dlt_prefix[] = "raw";
3433
static uint16_t dlt_value = DLT_RAW;

src/tcpedit/plugins/dlt_template.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ done
4040

4141
# Files to have their name changed
4242
for i in plugin.c.tmpl plugin.h plugin_opts.def plugin_api.c.tmpl plugin_api.h plugin_types.h ; do
43-
OUTFILE=`echo $i | sed -E "s/plugin/${PLUGIN}/"`
44-
OUTFILE=`echo $OUTFILE | sed -E "s/\.tmpl//"`
43+
OUTFILE=$(echo $i | sed -E "s/plugin/${PLUGIN}/")
44+
OUTFILE=$(echo $OUTFILE | sed -E "s/\.tmpl//")
4545
OUTFILE="${PLUGINDIR}/${OUTFILE}"
4646
if [ -f $OUTFILE ]; then
4747
echo "Skipping $OUTFILE"

src/tcprewrite.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ main(int argc, char *argv[])
136136
tcpdump_close(&tcpdump);
137137
#endif
138138

139+
#ifdef ENABLE_FRAGROUTE
140+
if (options.frag_ctx) {
141+
fragroute_close(options.frag_ctx);
142+
}
143+
#endif
144+
139145
#ifdef ENABLE_DMALLOC
140146
dmalloc_shutdown();
141147
#endif
@@ -230,6 +236,9 @@ rewrite_packets(tcpedit_t *tcpedit, pcap_t *pin, pcap_dumper_t *pout)
230236
int rcode;
231237
#ifdef ENABLE_FRAGROUTE
232238
int frag_len, proto;
239+
#ifdef DEBUG
240+
int i;
241+
#endif
233242
#endif
234243

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

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

0 commit comments

Comments
 (0)