From 68e38dcc85c4c1390a0303d45931042c83fd2625 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Fri, 15 Oct 2021 12:05:03 +0200
Subject: Haiku: port


diff --git a/CMakeLists.txt b/CMakeLists.txt
index 54c54aa..b6b495d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -146,16 +146,19 @@ ENDIF()
 
 CARES_FUNCTION_IN_LIBRARY (gethostbyname nsl HAVE_LIBNSL)
 CARES_FUNCTION_IN_LIBRARY (gethostbyname socket HAVE_GHBN_LIBSOCKET)
+CARES_FUNCTION_IN_LIBRARY (gethostbyname network HAVE_LIBNETWORK)
 CARES_FUNCTION_IN_LIBRARY (socket socket HAVE_SOCKET_LIBSOCKET)
 IF (HAVE_GHBN_LIBSOCKET OR HAVE_SOCKET_LIBSOCKET)
 	SET(HAVE_LIBSOCKET TRUE)
 ENDIF ()
+CARES_FUNCTION_IN_LIBRARY (socket network HAVE_LIBNETWORK)
 CARES_FUNCTION_IN_LIBRARY (clock_gettime rt HAVE_LIBRT)
 
 
 # Look for necessary includes
 CHECK_INCLUDE_FILES (sys/types.h           HAVE_SYS_TYPES_H)
 CHECK_INCLUDE_FILES (sys/socket.h          HAVE_SYS_SOCKET_H)
+CHECK_INCLUDE_FILES (sys/sockio.h          HAVE_SYS_SOCKIO_H)
 CHECK_INCLUDE_FILES (arpa/inet.h           HAVE_ARPA_INET_H)
 CHECK_INCLUDE_FILES (arpa/nameser_compat.h HAVE_ARPA_NAMESER_COMPAT_H)
 CHECK_INCLUDE_FILES (arpa/nameser.h        HAVE_ARPA_NAMESER_H)
@@ -229,6 +232,9 @@ ENDIF ()
 IF (HAVE_LIBSOCKET)
 	LIST (APPEND CARES_DEPENDENT_LIBS socket)
 ENDIF ()
+IF (HAVE_LIBNETWORK)
+	LIST (APPEND CARES_DEPENDENT_LIBS network)
+ENDIF ()
 IF (HAVE_LIBRT)
 	LIST (APPEND CARES_DEPENDENT_LIBS rt)
 ENDIF ()
@@ -267,6 +273,7 @@ CARES_EXTRAINCLUDE_IFSET (HAVE_STRINGS_H      strings.h)
 CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_IOCTL_H    sys/ioctl.h)
 CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SELECT_H   sys/select.h)
 CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SOCKET_H   sys/socket.h)
+CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SOCKIO_H	sys/sockio.h)
 CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_TIME_H     sys/time.h)
 CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_UIO_H      sys/uio.h)
 CARES_EXTRAINCLUDE_IFSET (HAVE_TIME_H         time.h)
@@ -520,7 +527,8 @@ IF (HAVE_GETSERVBYPORT_R)
 	IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
 		SET (GETSERVBYPORT_R_ARGS 5)
 	ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
-		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
+		HAIKU)
 		SET (GETSERVBYPORT_R_ARGS 4)
 	ELSE ()
 		# Probably linux
@@ -533,7 +541,8 @@ IF (HAVE_GETSERVBYNAME_R)
 	IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
 		SET (GETSERVBYNAME_R_ARGS 5)
 	ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
-		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
+		HAIKU)
 		SET (GETSERVBYNAME_R_ARGS 4)
 	ELSE ()
 		# Probably linux
diff --git a/include/ares.h b/include/ares.h
index b341d60..649b5a3 100644
--- a/include/ares.h
+++ b/include/ares.h
@@ -39,7 +39,7 @@
 #if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
     defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
     defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
-    defined(__QNXNTO__) || defined(__MVS__)
+    defined(__QNXNTO__) || defined(__MVS__) || defined(__HAIKU__)
 #include <sys/select.h>
 #endif
 #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
diff --git a/src/lib/ares_private.h b/src/lib/ares_private.h
index 09f6506..0a59b5b 100644
--- a/src/lib/ares_private.h
+++ b/src/lib/ares_private.h
@@ -85,6 +85,11 @@ W32_FUNC const char *_w32_GetHostsFile (void);
 
 #define PATH_HOSTS             "InetDBase:Hosts"
 
+#elif defined(__HAIKU__)
+
+#define PATH_RESOLV_CONF "/system/settings/network/resolv.conf"
+#define PATH_HOSTS              "/system/settings/network/hosts"
+
 #else
 
 #define PATH_RESOLV_CONF        "/etc/resolv.conf"
-- 
2.30.2

