diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c
index 7fa85b2abe28f00246b7b63de1ec87a09fe9b0ee..f69151467f38ee9db5f0b9491e556b9fcff889b8 100644
--- a/tests/libtest/lib571.c
+++ b/tests/libtest/lib571.c
@@ -10,11 +10,23 @@
 
 #include "test.h"
 
+#ifdef HAVE_SYS_SOCKET_H
+#  include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#  include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#  include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#  include <arpa/inet.h>
+#endif
 #ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
+#  include <sys/stat.h>
 #endif
 #ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+#  include <fcntl.h>
 #endif
 
 #include <curl/mprintf.h>