diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index aed90954e6c6efe173a25d5bda4095e3e51112f1..f653650ffb14c2dd28a42146a571b41b728a5224 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -19,6 +19,15 @@
  */
 #define FRONTEND 1
 #include "postgres.h"
+
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+/* for ntohl/htonl */
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
 #include "libpq-fe.h"
 #include "access/xlog_internal.h"
 #include "utils/datetime.h"
@@ -27,11 +36,6 @@
 #include "receivelog.h"
 #include "streamutil.h"
 
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
 
 /* fd for currently open WAL file */
 static int	walfile = -1;