[v2,5/7] eal/windows: improve compatibility networking headers
diff mbox series

Message ID 20200730210652.14568-6-dmitry.kozliuk@gmail.com
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • cmdline: support Windows
Related show

Checks

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

Commit Message

Dmitry Kozlyuk July 30, 2020, 9:06 p.m. UTC
Extend compatibility header system to support librte_cmdline.

pthread.h has to include windows.h, which exposes struct in_addr, etc.
conflicting with compatibility headers. WIN32_LEAN_AND_MEAN macro
is required to disable this behavior. Use rte_windows.h to define
WIN32_LEAN_AND_MEAN for pthread library.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/windows/include/arpa/inet.h  | 30 +++++++++++++++++++++
 lib/librte_eal/windows/include/netinet/in.h | 12 +++++++++
 lib/librte_eal/windows/include/sys/socket.h | 24 +++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 create mode 100644 lib/librte_eal/windows/include/sys/socket.h

Patch
diff mbox series

diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
new file mode 100644
index 000000000..96b698438
--- /dev/null
+++ b/lib/librte_eal/windows/include/arpa/inet.h
@@ -0,0 +1,30 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Dmitry Kozlyuk
+ */
+
+#ifndef _ARPA_INET_H_
+#define _ARPA_INET_H_
+
+/**
+ * @file
+ *
+ * Compatibility header
+ *
+ * Although symbols declared here are present on Windows,
+ * including <winsock2.h> would expose too much macros breaking common code.
+ */
+
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+/* defined in ws2_32.dll */
+__attribute__((stdcall))
+int
+inet_pton(int af, const char *src, void *dst);
+
+/* defined in ws2_32.dll */
+__attribute__((stdcall))
+const char *
+inet_ntop(int af, const void *src, char *dst, socklen_t size);
+
+#endif /* _ARPA_INET_H_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
index 2be25c8be..f7c486be6 100644
--- a/lib/librte_eal/windows/include/netinet/in.h
+++ b/lib/librte_eal/windows/include/netinet/in.h
@@ -5,6 +5,8 @@ 
 #ifndef _IN_H_
 #define _IN_H_
 
+#include <sys/socket.h>
+
 #define IPPROTO_IP 0               /* Dummy for IP */
 #define IPPROTO_HOPOPTS 0          /* IPv6 Hop-by-Hop options */
 #define IPPROTO_IPIP 4             /* IPIP tunnels (for compatibility) */
@@ -20,4 +22,14 @@ 
 #define IPPROTO_DSTOPTS 60         /* IPv6 destination option */
 #define IPPROTO_SCTP 132           /* Stream Control Transmission Protocol */
 
+#define INET6_ADDRSTRLEN 46
+
+struct in_addr {
+	uint32_t s_addr;
+};
+
+struct in6_addr {
+	uint8_t s6_addr[16];
+};
+
 #endif
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
new file mode 100644
index 000000000..9536cf8e6
--- /dev/null
+++ b/lib/librte_eal/windows/include/sys/socket.h
@@ -0,0 +1,24 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Dmitry Kozlyuk
+ */
+
+#ifndef _SYS_SOCKET_H_
+#define _SYS_SOCKET_H_
+
+/**
+ * @file
+ *
+ * Compatibility header
+ *
+ * Although symbols declared here are present on Windows,
+ * including <winsock2.h> would expose too much macros breaking common code.
+ */
+
+#include <stddef.h>
+
+#define AF_INET  2
+#define AF_INET6 23
+
+typedef size_t socklen_t;
+
+#endif /* _SYS_SOCKET_H_ */