You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/03/31 06:36:06 UTC
[incubator-nuttx-apps] branch master updated: examples/tcpblaster:
When a host PC is used, take its implementation of hton/ntoh functions.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 5e245cf examples/tcpblaster: When a host PC is used, take its implementation of hton/ntoh functions.
5e245cf is described below
commit 5e245cf34b06393531bd3005b5368bd57188e5a6
Author: Ouss4 <ab...@gmail.com>
AuthorDate: Mon Mar 30 17:23:22 2020 +0100
examples/tcpblaster: When a host PC is used, take its implementation of hton/ntoh functions.
---
examples/tcpblaster/tcpblaster.h | 34 ++++-----------
examples/tcpblaster/tcpblaster_cmdline.c | 72 +++++++++++++++++++-------------
2 files changed, 51 insertions(+), 55 deletions(-)
diff --git a/examples/tcpblaster/tcpblaster.h b/examples/tcpblaster/tcpblaster.h
index 849bb9f..af442e4 100644
--- a/examples/tcpblaster/tcpblaster.h
+++ b/examples/tcpblaster/tcpblaster.h
@@ -52,33 +52,17 @@
****************************************************************************/
#ifdef TCPBLASTER_HOST
-#undef HTONS
-#ifdef CONFIG_ENDIAN_BIG
-# define HTONS(ns) (ns)
-#else
-# define HTONS(ns) \
- (unsigned short) \
- (((((unsigned short)(ns)) & 0x00ff) << 8) | \
- ((((unsigned short)(ns)) >> 8) & 0x00ff))
-#endif
-
-#undef HTONL
-#ifdef CONFIG_ENDIAN_BIG
-# define HTONL(nl) (nl)
-#else
-# define HTONL(nl) \
- (unsigned long) \
- (((((unsigned long)(nl)) & 0x000000ffUL) << 24) | \
- ((((unsigned long)(nl)) & 0x0000ff00UL) << 8) | \
- ((((unsigned long)(nl)) & 0x00ff0000UL) >> 8) | \
- ((((unsigned long)(nl)) & 0xff000000UL) >> 24))
-#endif
+/* HTONS/L macros are unique to NuttX */
-#undef NTOHS
-#define NTOHS(hs) HTONS(hs)
+# undef HTONS
+# undef HTONL
+# define HTONS(ns) htons(ns)
+# define HTONL(nl) htonl(nl)
-#undef NTOHL
-#define NTOHL(hl) HTONL(hl)
+# undef NTOHS
+# undef NTOHL
+# define NTOHS(hs) ntohs(hs)
+# define NTOHL(hl) ntohl(hl)
/* Have SO_LINGER */
diff --git a/examples/tcpblaster/tcpblaster_cmdline.c b/examples/tcpblaster/tcpblaster_cmdline.c
index 418f037..0d8915b 100644
--- a/examples/tcpblaster/tcpblaster_cmdline.c
+++ b/examples/tcpblaster/tcpblaster_cmdline.c
@@ -51,37 +51,10 @@
#ifdef CONFIG_EXAMPLES_TCPBLASTER_IPv6
-uint16_t g_tcpblasterserver_ipv6[8] =
-{
-#if defined(CONFIG_EXAMPLES_TCPBLASTER_LOOPBACK) && defined(CONFIG_NET_LOOPBACK)
- 0, /* Use the loopback address */
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- HTONS(1)
-#else
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_1),
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_2),
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_3),
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_4),
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_5),
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_6),
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_7),
- HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_8)
-#endif
-};
+uint16_t g_tcpblasterserver_ipv6[8];
#else
-
-#if defined(CONFIG_EXAMPLES_TCPBLASTER_LOOPBACK) && defined(CONFIG_NET_LOOPBACK)
-uint32_t g_tcpblasterserver_ipv4 = HTONL(0x7f000001);
-#else
-uint32_t g_tcpblasterserver_ipv4 = HTONL(CONFIG_EXAMPLES_TCPBLASTER_SERVERIP);
-#endif
-
+uint32_t g_tcpblasterserver_ipv4;
#endif
/****************************************************************************
@@ -108,8 +81,47 @@ static void show_usage(FAR const char *progname)
void tcpblaster_cmdline(int argc, char **argv)
{
+ /* Init the default IP address. */
+
+#ifdef CONFIG_EXAMPLES_TCPBLASTER_IPv6
+# if defined(CONFIG_EXAMPLES_TCPBLASTER_LOOPBACK) && \
+ defined(CONFIG_NET_LOOPBACK)
+ g_tcpblasterserver_ipv6[0] = 0;
+ g_tcpblasterserver_ipv6[1] = 0;
+ g_tcpblasterserver_ipv6[2] = 0;
+ g_tcpblasterserver_ipv6[3] = 0;
+ g_tcpblasterserver_ipv6[4] = 0;
+ g_tcpblasterserver_ipv6[5] = 0;
+ g_tcpblasterserver_ipv6[6] = 0;
+ g_tcpblasterserver_ipv6[7] = HTONS(1);
+# else
+ g_tcpblasterserver_ipv6[0] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_1);
+ g_tcpblasterserver_ipv6[1] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_2);
+ g_tcpblasterserver_ipv6[2] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_3);
+ g_tcpblasterserver_ipv6[3] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_4);
+ g_tcpblasterserver_ipv6[4] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_5);
+ g_tcpblasterserver_ipv6[5] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_6);
+ g_tcpblasterserver_ipv6[6] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_7);
+ g_tcpblasterserver_ipv6[7] =
+ HTONS(CONFIG_EXAMPLES_TCPBLASTER_SERVERIPv6ADDR_8);
+# endif
+#else
+# if defined(CONFIG_EXAMPLES_TCPBLASTER_LOOPBACK) && defined(CONFIG_NET_LOOPBACK)
+ g_tcpblasterserver_ipv4 = HTONL(0x7f000001);
+# else
+ g_tcpblasterserver_ipv4 = HTONL(CONFIG_EXAMPLES_TCPBLASTER_SERVERIP);
+# endif
+#endif
+
/* Currently only a single command line option is supported: The server
- * IP address.
+ * IP address. Used to override default.
*/
if (argc == 2)