diff --git a/include/opendht/infohash.h b/include/opendht/infohash.h
index d1df76981852f8bd4453cb6287dd9e1f19bbc6fe..e09648308e42d46df42ec9060824ea095530f7d3 100644
--- a/include/opendht/infohash.h
+++ b/include/opendht/infohash.h
@@ -22,16 +22,11 @@
 #include <msgpack.hpp>
 
 #ifndef _WIN32
-#include <netinet/in.h>
-#include <netdb.h>
-#ifdef __ANDROID__
-typedef uint16_t in_port_t;
-#endif
+#include <sys/socket.h>
 #else
 #include <iso646.h>
 #include <ws2tcpip.h>
-typedef uint16_t sa_family_t;
-typedef uint16_t in_port_t;
+#include <ws2def.h>
 #endif
 
 #include <iostream>
diff --git a/include/opendht/utils.h b/include/opendht/utils.h
index ae634d9ab924e994fb37aa133fd46d3de327038e..ef6de45dca85a9a672eb6747036ecb81a63b4886 100644
--- a/include/opendht/utils.h
+++ b/include/opendht/utils.h
@@ -26,9 +26,16 @@
 
 #ifndef _WIN32
 #include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#ifdef __ANDROID__
+typedef uint16_t in_port_t;
+#endif
 #else
-#include <ws2def.h>
 #include <ws2tcpip.h>
+#include <ws2def.h>
+typedef uint16_t sa_family_t;
+typedef uint16_t in_port_t;
 #endif
 
 #include <chrono>