[v2,2/3] net: add htons to minGW for Windows

Message ID 20200610120040.17968-3-fady@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series compile librte_net for windows |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Fady Bader June 10, 2020, noon UTC
  htons wasnt defined in Windows for the minGW compiler.
Definition of htons was added in order to use htons.

Signed-off-by: Fady Bader <fady@mellanox.com>
---
 lib/librte_eal/windows/include/rte_os.h | 4 ++++
 lib/librte_net/rte_arp.c                | 2 ++
 2 files changed, 6 insertions(+)
  

Comments

Jerin Jacob June 10, 2020, 12:33 p.m. UTC | #1
On Wed, Jun 10, 2020 at 5:31 PM Fady Bader <fady@mellanox.com> wrote:
>
> htons wasnt defined in Windows for the minGW compiler.
> Definition of htons was added in order to use htons.
>
> Signed-off-by: Fady Bader <fady@mellanox.com>
> ---
>  lib/librte_eal/windows/include/rte_os.h | 4 ++++
>  lib/librte_net/rte_arp.c                | 2 ++
>  2 files changed, 6 insertions(+)
>
> diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
> index bab011a5c..95525123f 100644
> --- a/lib/librte_eal/windows/include/rte_os.h
> +++ b/lib/librte_eal/windows/include/rte_os.h
> @@ -28,6 +28,10 @@ extern "C" {
>
>  #define strerror_r(a, b, c) strerror_s(b, c, a)
>
> +#ifdef RTE_TOOLCHAIN_GCC
> +#define htons(x) (rte_cpu_to_be_16(x))
> +#endif
> +
>  /* strdup is deprecated in Microsoft libc and _strdup is preferred */
>  #define strdup(str) _strdup(str)
>
> diff --git a/lib/librte_net/rte_arp.c b/lib/librte_net/rte_arp.c
> index 784b7f48f..8fd431c54 100644
> --- a/lib/librte_net/rte_arp.c
> +++ b/lib/librte_net/rte_arp.c
> @@ -2,7 +2,9 @@
>   * Copyright(c) 2018 Intel Corporation
>   */
>
> +#ifndef RTE_EXEC_ENV_WINDOWS
>  #include <arpa/inet.h>
> +#endif

I think, replacing  htons() with rte_cpu_to_be_16() in rte_arp.c will
the clean solution to avoid #ifndef.


>
>  #include <rte_arp.h>
>
> --
> 2.16.1.windows.4
>
  

Patch

diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index bab011a5c..95525123f 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -28,6 +28,10 @@  extern "C" {
 
 #define strerror_r(a, b, c) strerror_s(b, c, a)
 
+#ifdef RTE_TOOLCHAIN_GCC
+#define htons(x) (rte_cpu_to_be_16(x))
+#endif
+
 /* strdup is deprecated in Microsoft libc and _strdup is preferred */
 #define strdup(str) _strdup(str)
 
diff --git a/lib/librte_net/rte_arp.c b/lib/librte_net/rte_arp.c
index 784b7f48f..8fd431c54 100644
--- a/lib/librte_net/rte_arp.c
+++ b/lib/librte_net/rte_arp.c
@@ -2,7 +2,9 @@ 
  * Copyright(c) 2018 Intel Corporation
  */
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <arpa/inet.h>
+#endif
 
 #include <rte_arp.h>