From 3b1f96d28a2806562ae4ce73dade4d601f9389a9 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 21 Nov 2020 18:45:54 +0100
Subject: Haiku patch


diff --git a/avahi-core/socket.c b/avahi-core/socket.c
index 7583dae..64ea8a7 100644
--- a/avahi-core/socket.c
+++ b/avahi-core/socket.c
@@ -318,8 +318,8 @@ int avahi_open_socket_ipv4(int no_reuse) {
         goto fail;
     }
 
-    ttl = 255;
-    if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
+    ttl = ittl = 255;
+    if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ittl, sizeof(ittl)) < 0) {
         avahi_log_warn("IP_MULTICAST_TTL failed: %s", strerror(errno));
         goto fail;
     }
@@ -330,11 +330,13 @@ int avahi_open_socket_ipv4(int no_reuse) {
         goto fail;
     }
 
+#ifndef __HAIKU__
     cyes = 1;
     if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &cyes, sizeof(cyes)) < 0) {
         avahi_log_warn("IP_MULTICAST_LOOP failed: %s", strerror(errno));
         goto fail;
     }
+#endif
 
     memset(&local, 0, sizeof(local));
     local.sin_family = AF_INET;
diff --git a/avahi-daemon/Makefile.am b/avahi-daemon/Makefile.am
index 9645e6e..aaf45d1 100644
--- a/avahi-daemon/Makefile.am
+++ b/avahi-daemon/Makefile.am
@@ -168,8 +168,10 @@ xmllint:
 		xmllint --noout --valid $$F ; \
 	done
 
+if ! TARGET_HAIKU
 install-data-local:
 	test -z "$(avahi_runtime_dir)" || $(MKDIR_P) "$(DESTDIR)$(avahi_runtime_dir)"
+endif
 
 update-systemd:
 	curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c > sd-daemon.c
diff --git a/avahi-daemon/sd-daemon.c b/avahi-daemon/sd-daemon.c
index 6d1eebf..032a739 100644
--- a/avahi-daemon/sd-daemon.c
+++ b/avahi-daemon/sd-daemon.c
@@ -32,7 +32,11 @@
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#ifdef __HAIKU__
+#include <fcntl.h>
+#else
 #include <sys/fcntl.h>
+#endif
 #include <netinet/in.h>
 #include <stdlib.h>
 #include <errno.h>
diff --git a/configure.ac b/configure.ac
index 58db8c7..9650bcc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -178,6 +178,9 @@ AC_DEFINE([HAVE_PF_ROUTE],[],[Support for PF_ROUTE])
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <net/if_dl.h>
+#ifdef __HAIKU__
+#error Haiku doesn't have PF_ROUTE
+#endif
 ])
 
 AM_CONDITIONAL(HAVE_PF_ROUTE, [ test x"$HAVE_PF_ROUTE" = xyes ])
@@ -274,7 +277,7 @@ fi
 with_distro=`echo ${with_distro} | tr '[[:upper:]]' '[[:lower:]]' `
 
 case $with_distro in
-    lfs|debian|gentoo|archlinux|suse|fedora|mandriva|darwin|freebsd|slackware|none)
+    lfs|debian|gentoo|archlinux|suse|fedora|mandriva|darwin|freebsd|slackware|haiku|none)
      ;;
     netbsd)
      AC_MSG_WARN([Your distribution (${with_distro}) is supported but no init script exist yet! (patches welcome)])
@@ -298,6 +301,7 @@ AM_CONDITIONAL(TARGET_DARWIN, test x"$with_distro" = xdarwin)
 AM_CONDITIONAL(TARGET_NETBSD, test x"$with_distro" = xnetbsd)
 AM_CONDITIONAL(TARGET_FREEBSD, test x"$with_distro" = xfreebsd)
 AM_CONDITIONAL(TARGET_SLACKWARE, test x"$with_distro" = xslackware)
+AM_CONDITIONAL(TARGET_HAIKU, test x"$with_distro" = xhaiku)
 
 test_gcc_flag() {
     AC_LANG_CONFTEST([int main() {}])
@@ -356,9 +360,9 @@ AC_TYPE_SIZE_T
 AC_HEADER_TIME
 AC_HEADER_SYS_WAIT
 
- # Solaris stuff
+ # Haiku, Solaris stuff
  AC_SEARCH_LIBS([inet_ntop],[nsl])
- AC_SEARCH_LIBS([recv],[socket])
+ AC_SEARCH_LIBS([recv],[socket network])
  AC_CHECK_DECL([CMSG_SPACE],,CFLAGS="$CFLAGS -D_XOPEN_SOURCE=500 -D__EXTENSIONS__", [[#include <sys/socket.h>]])
 
 # Checks for library functions.
@@ -1004,7 +1008,7 @@ AC_DEFINE_UNQUOTED(AVAHI_AUTOIPD_GROUP,"$AVAHI_AUTOIPD_GROUP", [Group for runnin
 #
 # Avahi runtime dir
 #
-avahi_runtime_dir="/run"
+avahi_runtime_dir="/var/run"
 avahi_socket="${avahi_runtime_dir}/avahi-daemon/socket"
 AC_SUBST(avahi_runtime_dir)
 AC_SUBST(avahi_socket)
-- 
2.28.0

