Skip to content

Commit

Permalink
Found I could not build both debug and timestamp modes. Fixed CFLAGS,
Browse files Browse the repository at this point in the history
including adding automake default CC flags. This exposed many
warnings which had to get cleaned up.
  • Loading branch information
fklassen committed Jan 28, 2018
1 parent b663095 commit f4ed4bd
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 78 deletions.
21 changes: 13 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AC_INIT([tcpreplay],[4.3.0-beta1],
[tcpreplay],
[http://tcpreplay.sourceforge.net/])
AC_CONFIG_SRCDIR([src/tcpreplay.c])
AC_CONFIG_HEADERS([src/config.h])
AM_CONFIG_HEADER([src/config.h])
AC_CONFIG_AUX_DIR(config)
AM_MAINTAINER_MODE
AM_WITH_DMALLOC
Expand All @@ -29,9 +29,6 @@ TCPREPLAY_RELEASE=1
AC_SUBST(TCPREPLAY_VERSION)
AC_SUBST(TCPREPLAY_RELEASE)

USER_CFLAGS=$CFLAGS
CFLAGS="-Wall -std=gnu99 ${CFLAGS}"

dnl Determine OS
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
Expand Down Expand Up @@ -153,7 +150,7 @@ AM_SILENT_RULES([yes])
dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AM_PROG_CC_C_O
AC_PROG_CC
AC_PROG_CC_STDC
AC_PROG_CXX
AC_PROG_CPP
Expand Down Expand Up @@ -372,6 +369,10 @@ AM_CONDITIONAL(SYSTEM_STRLCPY, [test x$have_strlcpy = xtrue])
AC_C_BIGENDIAN
AM_CONDITIONAL([WORDS_BIGENDIAN], [ test x$ac_cv_c_bigendian = xyes ])

dnl remove '-g' flag
changequote({,})
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-g[0-9]*//g'`
changequote([,])

dnl Enable debugging in code/compiler options
debug=no
Expand All @@ -381,7 +382,11 @@ AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug], [Enable debugging code and support for the -d option]),
[ if test x$enableval = xyes; then
debug=yes
CFLAGS="${USER_CFLAGS} -g -O0 -std=gnu99 -Wall $wextra $wfatal_errors $wno_variadic_macros $wno_format_contains_nul $wno_format"
dnl replace '-0X' and add '-g' flags
changequote({,})
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'`
changequote([,])
CFLAGS="${CFLAGS} -g -O0 -std=gnu99 -Wall $wextra $wfatal_errors $wno_variadic_macros $wno_format_contains_nul $wno_format"
# We may also want to add:
# -Wformat-security -Wswitch-default -Wunused-paramter -Wpadded"
debug_flag=DEBUG
Expand Down Expand Up @@ -409,10 +414,10 @@ AC_ARG_ENABLE(timestamp-trace,
AC_HELP_STRING([--timestamp-trace], [Enable dumping of trace timestamps at the end of a test]),
[ if test x$enableval = xyes; then
timestamp_trace=yes
CFLAGS="${USER_CFLAGS} -DTIMESTAMP_TRACE"
AC_SUBST(timestamp_trace_flag)
CFLAGS="${CFLAGS} -DTIMESTAMP_TRACE"
AC_DEFINE([TIMESTAMP_TRACE], [1], [Enable dumping of trace timestamps at the end of a test])
fi])
AC_SUBST(timestamp_trace_flag)


AC_ARG_ENABLE(dmalloc,
Expand Down
2 changes: 1 addition & 1 deletion src/common/flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr *
sll_hdr_t *sll_hdr;
struct tcpr_pppserial_hdr *ppp;
flow_entry_data_t entry;
int l2_len = 0;
uint32_t l2_len = 0;
int ip_len;
uint8_t protocol;
uint32_t hash;
Expand Down
16 changes: 8 additions & 8 deletions src/common/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ get_l2protocol(const u_char *pktdata, const int datalen, const int datalink)
}
/* fall through */
case DLT_EN10MB:
if (datalen >= (sizeof(eth_hdr_t) + eth_hdr_offset)) {
if (datalen >= (int)(sizeof(eth_hdr_t) + eth_hdr_offset)) {
eth_hdr = (eth_hdr_t *)(pktdata + eth_hdr_offset);
ether_type = ntohs(eth_hdr->ether_type);
switch (ether_type) {
Expand All @@ -127,7 +127,7 @@ get_l2protocol(const u_char *pktdata, const int datalen, const int datalink)
break;

case DLT_PPP_SERIAL:
if (datalen >= sizeof(struct tcpr_pppserial_hdr)) {
if (datalen >= (int)sizeof(struct tcpr_pppserial_hdr)) {
ppp = (struct tcpr_pppserial_hdr *)pktdata;
if (ntohs(ppp->protocol) == 0x0021)
return htons(ETHERTYPE_IP);
Expand All @@ -137,14 +137,14 @@ get_l2protocol(const u_char *pktdata, const int datalen, const int datalink)
break;

case DLT_C_HDLC:
if (datalen >= sizeof(hdlc_hdr_t)) {
if (datalen >= (int)sizeof(hdlc_hdr_t)) {
hdlc_hdr = (hdlc_hdr_t *)pktdata;
return hdlc_hdr->protocol;
}
break;

case DLT_LINUX_SLL:
if (datalen >= sizeof(sll_hdr_t)) {
if (datalen >= (int)sizeof(sll_hdr_t)) {
sll_hdr = (sll_hdr_t *)pktdata;
return sll_hdr->sll_protocol;
}
Expand Down Expand Up @@ -182,14 +182,14 @@ get_l2len(const u_char *pktdata, const int datalen, const int datalink)
l2_len = 24;
/* fall through */
case DLT_EN10MB:
if (datalen >= sizeof(eth_hdr_t) + l2_len) {
if (datalen >= (int)sizeof(eth_hdr_t) + l2_len) {
ether_type = ntohs(((eth_hdr_t*)(pktdata + l2_len))->ether_type);

while (ether_type == ETHERTYPE_VLAN) {
vlan_hdr = (vlan_hdr_t *)(pktdata + l2_len);
ether_type = ntohs(vlan_hdr->vlan_len);
l2_len += 4;
if (datalen < sizeof(vlan_hdr_t) + l2_len) {
if (datalen < (int)sizeof(vlan_hdr_t) + l2_len) {
l2_len = -1;
break;
}
Expand Down Expand Up @@ -660,7 +660,7 @@ get_name2addr6(const char *hostname, bool dnslookup, struct tcpr_in6_addr *addr)
* is available on your system. Does not support DNS.
*/
const char *
get_addr2name4(const uint32_t ip, bool dnslookup)
get_addr2name4(const uint32_t ip, bool _U_ dnslookup)
{
struct in_addr addr;
static char *new_string = NULL;
Expand Down Expand Up @@ -690,7 +690,7 @@ get_addr2name4(const uint32_t ip, bool dnslookup)
* Does not support DNS.
*/
const char *
get_addr2name6(const struct tcpr_in6_addr *addr, bool dnslookup)
get_addr2name6(const struct tcpr_in6_addr *addr, _U_ bool dnslookup)
{
static char *new_string = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/common/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr
*/
sendpacket_t *
sendpacket_open(const char *device, char *errbuf, tcpr_dir_t direction,
sendpacket_type_t sendpacket_type, void *arg)
sendpacket_type_t _U_ sendpacket_type, void _U_ *arg)
{
sendpacket_t *sp;
struct stat sdata;
Expand Down
23 changes: 16 additions & 7 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
}
#endif
/* stop sending based on the duration limit... */
if ((end_us > 0 && TIMEVAL_TO_MICROSEC(&now) > end_us) ||
if ((end_us > 0 && (COUNTER)TIMEVAL_TO_MICROSEC(&now) > end_us) ||
/* ... or stop sending based on the limit -L? */
(limit_send > 0 && ctx->stats.pkts_sent >= limit_send)) {
ctx->abort = true;
Expand Down Expand Up @@ -941,7 +941,7 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
}

/* stop sending based on the duration limit... */
if ((end_us > 0 && TIMEVAL_TO_MICROSEC(&now) > end_us) ||
if ((end_us > 0 && (COUNTER)TIMEVAL_TO_MICROSEC(&now) > end_us) ||
/* ... or stop sending based on the limit -L? */
(limit_send > 0 && ctx->stats.pkts_sent >= limit_send)) {
ctx->abort = true;
Expand Down Expand Up @@ -1143,16 +1143,22 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta,
if (timercmp(pkt_time_delta, last_delta, >) && (delta_pkt_time > delta_us)) {
/* pkt_time_delta has increased, so handle normally */
timersub(pkt_time_delta, last_delta, &nap_for);
dbgx(3, "original packet delta pkt_time: " TIMEVAL_FORMAT, nap_for.tv_sec, nap_for.tv_usec);
dbgx(3, "original packet delta pkt_time: " TIMEVAL_FORMAT,
nap_for.tv_sec, nap_for.tv_usec);

TIMEVAL_TO_TIMESPEC(&nap_for, &ctx->nap);
dbgx(3, "original packet delta time: " TIMESPEC_FORMAT, ctx->nap.tv_sec, ctx->nap.tv_nsec);
dbgx(3, "original packet delta time: " TIMESPEC_FORMAT,
ctx->nap.tv_sec, ctx->nap.tv_nsec);
timesdiv_float(&ctx->nap, options->speed.multiplier);
dbgx(3, "original packet delta/div: " TIMESPEC_FORMAT, ctx->nap.tv_sec, ctx->nap.tv_nsec);
dbgx(3, "original packet delta/div: " TIMESPEC_FORMAT,
ctx->nap.tv_sec, ctx->nap.tv_nsec);
} else {
/* Don't sleep if this packet is late or in the past */
update_time = false;
}

update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len,
now_us, delta_us, delta_pkt_time);
} else {
/* Don't sleep if this is our first packet */
update_time = false;
Expand Down Expand Up @@ -1185,7 +1191,9 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta,
tx_us = now_us - *start_us;
*skip_length = ((tx_us - next_tx_us) * bps) / 8000000;
}
update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len, now_us, tx_us, next_tx_us);

update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len,
now_us, tx_us, next_tx_us);
}

dbgx(3, "packet size=" COUNTER_SPEC "\t\tnap=" TIMESPEC_FORMAT, len,
Expand All @@ -1212,7 +1220,8 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta,
else
ctx->skip_packets = options->speed.pps_multi;

update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len, now_us, tx_us, next_tx_us);
update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len,
now_us, tx_us, next_tx_us);
}

dbgx(3, "packet count=" COUNTER_SPEC "\t\tnap=" TIMESPEC_FORMAT, ctx->stats.pkts_sent,
Expand Down
2 changes: 1 addition & 1 deletion src/sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ nanosleep_sleep(struct timespec *nap)
static inline void
gettimeofday_sleep(sendpacket_t *sp _U_,
struct timespec *nap, struct timeval *now,
bool flush)
_U_ bool flush)
{
struct timeval sleep_until, nap_for;
#ifdef HAVE_NETMAP
Expand Down
2 changes: 1 addition & 1 deletion src/tcpcapinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ main(int argc, char *argv[])
}

/* read the frame */
maxread = min(caplen, sizeof(buf));
maxread = min(caplen, (int)sizeof(buf));
if ((ret = read(fd, &buf, maxread)) != maxread) {
if (ret < 0) {
printf("Error reading file: %s: %s\n", argv[i], strerror(errno));
Expand Down
4 changes: 2 additions & 2 deletions src/tcpedit/edit_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ ipv6_header_length(ipv6_hdr_t const * ip6_hdr, int pkt_len)
{
struct tcpr_ipv6_ext_hdr_base const * nhdr;
uint8_t next_header;
int offset;
uint32_t offset;

offset = sizeof(*ip6_hdr);
next_header = ip6_hdr->ip_nh;

while (sizeof(*nhdr) + offset < pkt_len)
while (sizeof(*nhdr) + offset < (uint32_t)pkt_len)
{
if (next_header != TCPR_IPV6_NH_HBH
&& next_header != TCPR_IPV6_NH_ROUTING
Expand Down
4 changes: 2 additions & 2 deletions src/tcpedit/fuzzing.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fuzzing(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,
* fuzz random-size segment at the beginning of the packet payload
* with random bytes
*/
int i;
uint32_t i;
uint32_t sgt_size = fuzz_get_sgt_size(r, l4len);
if (!sgt_size)
goto done;
Expand Down Expand Up @@ -290,7 +290,7 @@ fuzzing(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr,
case FUZZING_CHANGE_MID_RANDOM:
{
/* fuzz random-size segment inside the packet with random Bytes */
int i;
uint32_t i;
uint32_t offset = ((r >> 16) % (l4len - 1)) + 1;
uint32_t sgt_size = fuzz_get_sgt_size(r, l4len - offset);
if (!sgt_size)
Expand Down
4 changes: 2 additions & 2 deletions src/tcpedit/plugins/dlt_hdlc/hdlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ dlt_hdlc_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen)
assert(ctx);
assert(packet);

if (pktlen < sizeof(*hdlc))
if ((uint32_t)pktlen < sizeof(*hdlc))
return TCPEDIT_ERROR;

if (ctx->decoded_extra_size < sizeof(*extra))
Expand Down Expand Up @@ -234,7 +234,7 @@ dlt_hdlc_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, _U_ tcpr_dir_t di
assert(ctx);
assert(packet);

if (pktlen < sizeof(*hdlc))
if ((uint32_t)pktlen < sizeof(*hdlc))
return TCPEDIT_ERROR;

if (ctx->decoded_extra_size < sizeof(*extra))
Expand Down
3 changes: 1 addition & 2 deletions src/tcpedit/plugins/dlt_ieee80211/ieee80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ dlt_ieee80211_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen)
* Returns: total packet len or TCPEDIT_ERROR
*/
int
dlt_ieee80211_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, _U_ tcpr_dir_t dir)
dlt_ieee80211_encode(tcpeditdlt_t *ctx, _U_ u_char *packet, _U_ int pktlen, _U_ tcpr_dir_t dir)
{
assert(ctx);
assert(packet);

tcpedit_seterr(ctx->tcpedit, "%s", "DLT_IEEE802_11 plugin does not support packet encoding");
return TCPEDIT_ERROR;
Expand Down
3 changes: 1 addition & 2 deletions src/tcpedit/plugins/dlt_linuxsll/linuxsll.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,9 @@ dlt_linuxsll_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen)
* Returns: total packet len or TCPEDIT_ERROR
*/
int
dlt_linuxsll_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, _U_ tcpr_dir_t dir)
dlt_linuxsll_encode(tcpeditdlt_t *ctx, _U_ u_char *packet, _U_ int pktlen, _U_ tcpr_dir_t dir)
{
assert(ctx);
assert(packet);

tcpedit_seterr(ctx->tcpedit, "%s", "DLT_LINUX_SLL plugin does not support packet encoding");
return TCPEDIT_ERROR;
Expand Down
7 changes: 3 additions & 4 deletions src/tcpedit/plugins/dlt_null/null.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ dlt_null_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen)
* Returns: total packet len or TCPEDIT_ERROR
*/
int
dlt_null_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, _U_ tcpr_dir_t dir)
dlt_null_encode(tcpeditdlt_t *ctx, u_char *packet, _U_ int pktlen, _U_ tcpr_dir_t dir)
{
assert(ctx);
assert(packet);
Expand Down Expand Up @@ -295,10 +295,9 @@ dlt_null_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen)
* return NULL on error/address doesn't exist
*/
u_char *
dlt_null_get_mac(tcpeditdlt_t *ctx, _U_ tcpeditdlt_mac_type_t mac, const u_char *packet, const int pktlen)
dlt_null_get_mac(_U_ tcpeditdlt_t *ctx, _U_ tcpeditdlt_mac_type_t mac,
_U_ const u_char *packet, _U_ const int pktlen)
{
assert(ctx);
assert(packet);

return(NULL);

Expand Down
6 changes: 2 additions & 4 deletions src/tcpedit/plugins/dlt_pppserial/pppserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,9 @@ dlt_pppserial_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen,
* return NULL on error/address doesn't exist
*/
u_char *
dlt_pppserial_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t UNUSED(mac), const u_char *packet, const int pktlen)
dlt_pppserial_get_mac(_U_ tcpeditdlt_t *ctx, _U_ tcpeditdlt_mac_type_t mac,
_U_ const u_char *packet, _U_ const int pktlen)
{
assert(ctx);
assert(packet);

return NULL;
}

Expand Down
5 changes: 2 additions & 3 deletions src/tcpedit/plugins/dlt_radiotap/radiotap.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ dlt_radiotap_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen)
* Returns: total packet len or TCPEDIT_ERROR
*/
int
dlt_radiotap_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, _U_ tcpr_dir_t dir)
dlt_radiotap_encode(tcpeditdlt_t *ctx, _U_ u_char *packet, _U_ int pktlen, _U_ tcpr_dir_t dir)
{
assert(ctx);
assert(packet);

tcpedit_seterr(ctx->tcpedit, "%s", "DLT_IEEE802_11_RADIO plugin does not support packet encoding");
return TCPEDIT_ERROR;
Expand Down Expand Up @@ -359,7 +358,7 @@ dlt_radiotap_get_80211(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen
return NULL;

extra = (radiotap_extra_t *)(ctx->decoded_extra);
if (pktlen >= radiolen && (pktlen - radiolen) >= sizeof(extra->packet) &&
if (pktlen >= radiolen && (pktlen - radiolen) >= (int)sizeof(extra->packet) &&
lastpacket != ctx->tcpedit->runtime.packetnum) {
memcpy(extra->packet, &packet[radiolen], pktlen - radiolen);
lastpacket = ctx->tcpedit->runtime.packetnum;
Expand Down
Loading

0 comments on commit f4ed4bd

Please sign in to comment.