sys/socket.h is required.
Switched include order for netinet/in.h and netinet/ip.h to avoid compiler errors on FreeBSD.
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
-#include <netinet/ip.h>
#include <netinet/in.h>
+#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include "htsbuf.h"
#include "htsmsg.h"
+#if defined(PLATFORM_FREEBSD)
+#include <sys/socket.h>
+#endif
+
#define IP_AS_V4(storage, f) ((struct sockaddr_in *)&(storage))->sin_##f
#define IP_AS_V6(storage, f) ((struct sockaddr_in6 *)&(storage))->sin6_##f
#define IP_IN_ADDR(storage) \