aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilip Prindeville <philipp@redfish-solutions.com>2017-11-08 17:29:26 +0000
committerBruce A. Mah <bmah@kitchenlab.org>2017-11-08 09:29:26 -0800
commitd88f4cecf34f2b54ef3e4eab148991b276870f02 (patch)
tree65046b75e36f93d897cc74c021d20bb874620683 /src
parente44ec101bb932a96fa6f81bc8b94666b13e4ae73 (diff)
downloadiperf3-d88f4cecf34f2b54ef3e4eab148991b276870f02.tar.gz
Fix 3.3 build warnings (#664)
* Fix warnings about _GNU_SOURCE being redefined. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com> * Fix warnings of format-specified mismatching type Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com> * Simplify endianness checks Linux can be built with too many types of C run-time library and it's not reasonable to have to enumerate all of them, especially since at least one of them (MUSL) goes out of its way to not be easily detectable. Instead, leverage autoconf better for Linux/BSD to detect either <endian.h> or <sys/endian.h> directly. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com> * Sys headers should not be included directly There's usually a top-level header which then includes the sys/ descendent. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/iperf.h4
-rwxr-xr-xsrc/iperf_api.c4
-rw-r--r--src/iperf_config.h.in6
-rw-r--r--src/iperf_tcp.c10
-rw-r--r--src/iperf_udp.c12
-rw-r--r--src/net.c3
-rw-r--r--src/portable_endian.h59
7 files changed, 55 insertions, 43 deletions
diff --git a/src/iperf.h b/src/iperf.h
index bb951dc..b656784 100755
--- a/src/iperf.h
+++ b/src/iperf.h
@@ -36,7 +36,9 @@
#endif
#include <sys/select.h>
#include <sys/socket.h>
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
#include <netinet/tcp.h>
#if defined(HAVE_CPUSET_SETAFFINITY)
diff --git a/src/iperf_api.c b/src/iperf_api.c
index ab30b93..9e41238 100755
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -24,7 +24,9 @@
* This code is distributed under a BSD style license, see the LICENSE file
* for complete information.
*/
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
#define __USE_GNU
#include "iperf_config.h"
diff --git a/src/iperf_config.h.in b/src/iperf_config.h.in
index bd03935..a9e51ec 100644
--- a/src/iperf_config.h.in
+++ b/src/iperf_config.h.in
@@ -9,6 +9,9 @@
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
+/* Define to 1 if you have the <endian.h> header file. */
+#undef HAVE_ENDIAN_H
+
/* Have IPv6 flowlabel support. */
#undef HAVE_FLOWLABEL
@@ -54,6 +57,9 @@
/* Define to 1 if the system has the type `struct sctp_assoc_value'. */
#undef HAVE_STRUCT_SCTP_ASSOC_VALUE
+/* Define to 1 if you have the <sys/endian.h> header file. */
+#undef HAVE_SYS_ENDIAN_H
+
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
diff --git a/src/iperf_tcp.c b/src/iperf_tcp.c
index 91cf032..6f86d5d 100644
--- a/src/iperf_tcp.c
+++ b/src/iperf_tcp.c
@@ -24,8 +24,6 @@
* This code is distributed under a BSD style license, see the LICENSE
* file for complete information.
*/
-#include "iperf_config.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -44,6 +42,12 @@
#include "net.h"
#include "cjson.h"
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+#else
+# define PRIu64 "llu"
+#endif
+
#if defined(HAVE_FLOWLABEL)
#include "flowlabel.h"
#endif /* HAVE_FLOWLABEL */
@@ -90,7 +94,7 @@ iperf_tcp_send(struct iperf_stream *sp)
sp->result->bytes_sent_this_interval += r;
if (sp->test->debug)
- printf("sent %d bytes of %d, total %llu\n", r, sp->settings->blksize, sp->result->bytes_sent);
+ printf("sent %d bytes of %d, total %" PRIu64 "\n", r, sp->settings->blksize, sp->result->bytes_sent);
return r;
}
diff --git a/src/iperf_udp.c b/src/iperf_udp.c
index a2ea6d0..d04ae44 100644
--- a/src/iperf_udp.c
+++ b/src/iperf_udp.c
@@ -48,6 +48,12 @@
#include "cjson.h"
#include "portable_endian.h"
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+#else
+# define PRIu64 "llu"
+#endif
+
/* iperf_udp_recv
*
* receives the data for UDP
@@ -98,7 +104,7 @@ iperf_udp_recv(struct iperf_stream *sp)
}
if (sp->test->debug)
- fprintf(stderr, "pcount %llu packet_count %d\n", pcount, sp->packet_count);
+ fprintf(stderr, "pcount %" PRIu64 " packet_count %d\n", pcount, sp->packet_count);
/*
* Try to handle out of order packets. The way we do this
@@ -141,7 +147,7 @@ iperf_udp_recv(struct iperf_stream *sp)
/* Log the out-of-order packet */
if (sp->test->debug)
- fprintf(stderr, "OUT OF ORDER - incoming packet sequence %llu but expected sequence %d on stream %d", pcount, sp->packet_count, sp->socket);
+ fprintf(stderr, "OUT OF ORDER - incoming packet sequence %" PRIu64 " but expected sequence %d on stream %d", pcount, sp->packet_count, sp->socket);
}
/*
@@ -220,7 +226,7 @@ iperf_udp_send(struct iperf_stream *sp)
sp->result->bytes_sent_this_interval += r;
if (sp->test->debug)
- printf("sent %d bytes of %d, total %llu\n", r, sp->settings->blksize, sp->result->bytes_sent);
+ printf("sent %d bytes of %d, total %" PRIu64 "\n", r, sp->settings->blksize, sp->result->bytes_sent);
return r;
}
diff --git a/src/net.c b/src/net.c
index af456cb..afd0022 100644
--- a/src/net.c
+++ b/src/net.c
@@ -31,13 +31,12 @@
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
-#include <sys/errno.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <assert.h>
#include <netdb.h>
#include <string.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
#ifdef HAVE_SENDFILE
#ifdef linux
diff --git a/src/portable_endian.h b/src/portable_endian.h
index b86d37a..cd90375 100644
--- a/src/portable_endian.h
+++ b/src/portable_endian.h
@@ -10,18 +10,37 @@
#endif
-// GLIBC / Linux with endian(3) support, which was added in glibc 2.9.
-// Intended to support CentOS 6 and newer.
-#if defined(__linux__) && \
- ((__GLIBC__ > 3) || \
- (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9))
+#if defined(__CYGWIN__)
# include <endian.h>
-#elif defined(__CYGWIN__)
-
+#elif defined(HAVE_ENDIAN_H)
# include <endian.h>
+#elif defined(HAVE_SYS_ENDIAN_H)
+# include <sys/endian.h>
+
+# if defined(__OpenBSD__)
+
+# define be16toh(x) betoh16(x)
+# define le16toh(x) letoh16(x)
+
+# define be32toh(x) betoh32(x)
+# define le32toh(x) letoh32(x)
+
+# define be64toh(x) betoh64(x)
+# define le64toh(x) letoh64(x)
+
+# elif defined(__sgi)
+
+# include <netinet/in.h>
+# include <inttypes.h>
+
+# define be64toh(x) (x)
+# define htobe64(x) (x)
+
+# endif
+
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
@@ -46,32 +65,6 @@
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
-#elif defined(__OpenBSD__)
-
-# include <sys/endian.h>
-
-# define be16toh(x) betoh16(x)
-# define le16toh(x) letoh16(x)
-
-# define be32toh(x) betoh32(x)
-# define le32toh(x) letoh32(x)
-
-# define be64toh(x) betoh64(x)
-# define le64toh(x) letoh64(x)
-
-#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
-
-# include <sys/endian.h>
-
-#elif defined(__sgi)
-
-# include <sys/endian.h>
-# include <netinet/in.h>
-# include <inttypes.h>
-
-# define be64toh(x) (x)
-# define htobe64(x) (x)
-
#elif defined(__sun) && defined(__SVR4)
# include <sys/types.h>