<android-base/endian.h>: fix interoperability issue
<winsock2.h> has defined htonl(), ntohl(), htons() and ntohs() with
different return type that cannot be replaced by those macro definitions
in <android-base/endian.h>.
Includes <winsock2.h> first to prevent them from being replaced.
Then defines the macro later so we don't need to call into DLL
when using those functions.
Bug: 139639521
Test: m libbase_test && wine out/host/windows-x86/nativetest64/libbase_test/libbase_test64.exe
Test: m checkbuild
Change-Id: I672f23a31c6800df10e04d36695d446bca4c91e9
diff --git a/base/include/android-base/endian.h b/base/include/android-base/endian.h
index 2d0f614..8fa6365 100644
--- a/base/include/android-base/endian.h
+++ b/base/include/android-base/endian.h
@@ -51,8 +51,10 @@
/* macOS has some of the basics. */
#include <sys/_endian.h>
#else
-/* Windows has even less. */
+/* Windows has some of the basics as well. */
#include <sys/param.h>
+#include <winsock2.h>
+/* winsock2.h *must* be included before the following four macros. */
#define htons(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohs(x) __builtin_bswap16(x)