diff -urN sane-backends-1.0.21/backend/dll.c sane-backends-1.0.21-haiku/backend/dll.c
--- sane-backends-1.0.21/backend/dll.c	2010-04-05 13:18:03.063700992 +0000
+++ sane-backends-1.0.21-haiku/backend/dll.c	2010-06-24 03:47:33.416022528 +0000
@@ -50,7 +50,7 @@
 # include "lalloca.h"		/* MUST come first for AIX! */
 #endif
 
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
 #include <kernel/OS.h>
 #include <storage/FindDirectory.h>
 #include <kernel/image.h>
@@ -210,7 +210,7 @@
   }                                             \
 }
 
-#ifndef __BEOS__
+#if !defined __BEOS__ && !defined __HAIKU__
 #include "dll-preload.h"
 #endif
 
@@ -238,7 +238,7 @@
 static SANE_Auth_Callback auth_callback;
 static struct backend *first_backend;
 
-#ifndef __BEOS__
+#if !defined __BEOS__ && !defined __HAIKU__
 static const char *op_name[] = {
   "init", "exit", "get_devices", "open", "close", "get_option_descriptor",
   "control_option", "get_parameters", "start", "read", "cancel",
@@ -250,7 +250,7 @@
   "sane_control_option", "sane_get_parameters", "sane_start", "sane_read", "sane_cancel",
   "sane_set_io_mode", "sane_get_select_fd"
 };
-#endif /* __BEOS__ */
+#endif /* __BEOS__ || __HAIKU__ */
 
 static void *
 op_unsupported (void)
@@ -320,7 +320,7 @@
 }
 #endif
 
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
 #include <FindDirectory.h>
 
 static SANE_Status
@@ -593,7 +593,7 @@
   return SANE_STATUS_UNSUPPORTED;
 #endif /* HAVE_DLL */
 }
-#endif /* __BEOS__ */
+#endif /* __BEOS__ || __HAIKU__ */
 
 static SANE_Status
 init (struct backend *be)
@@ -634,7 +634,7 @@
 static void
 add_alias (const char *line_param)
 {
-#ifndef __BEOS__
+#if !defined __BEOS__ && !defined __HAIKU__
   const char *command;
   enum
   { CMD_ALIAS, CMD_HIDE }
@@ -827,7 +827,7 @@
 SANE_Status
 sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
 {
-#ifndef __BEOS__
+#if !defined __BEOS__ && !defined __HAIKU__
   char config_line[PATH_MAX];
   size_t len;
   FILE *fp;
@@ -847,7 +847,7 @@
   DBG (1, "sane_init: SANE dll backend version %s from %s\n", DLL_VERSION,
        PACKAGE_STRING);
 
-#ifndef __BEOS__
+#if !defined __BEOS__ && !defined __HAIKU__
   /* chain preloaded backends together: */
   for (i = 0; i < NELEMS (preloaded_backends); ++i)
     {
@@ -909,7 +909,7 @@
 		}
 		closedir(dir);
 	}
-#endif /* __BEOS__ */
+#endif /* __BEOS__ || __HAIKU__ */
 
   return SANE_STATUS_GOOD;
 }
@@ -933,7 +933,7 @@
 		   be->name);
 	      (*(op_exit_t)be->op[OP_EXIT]) ();
 	    }
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
 	  /* use BeOS kernel functions to unload add-ons */
 	  if(be->handle) unload_add_on((image_id)be->handle);
 #else
@@ -957,7 +957,7 @@
 #endif /* HAVE_DLOPEN */
 
 #endif /* HAVE_DLL */
-#endif /* __BEOS__ */
+#endif /* __BEOS__ || __HAIKU__ */
 	}
       if (!be->permanent)
 	{
diff -urN sane-backends-1.0.21/configure.in sane-backends-1.0.21-haiku/configure.in
--- sane-backends-1.0.21/configure.in	2010-04-26 00:55:27.008912896 +0000
+++ sane-backends-1.0.21-haiku/configure.in	2010-06-24 02:11:07.556269568 +0000
@@ -227,6 +227,7 @@
 AC_CHECK_FUNC(gethostbyaddr,, [AC_CHECK_LIB(bind, gethostbyaddr, BIND_LIB="-lbind")])
 AC_CHECK_FUNC(gethostbyaddr,, [AC_CHECK_LIB(nsl, gethostbyaddr, NSL_LIB="-lnsl")])
 AC_CHECK_FUNC(socket, [SOCKET_LIBS=], [AC_CHECK_LIB(socket, socket, SOCKET_LIB="-lsocket")])
+AC_CHECK_FUNC(socket, [SOCKET_LIBS=], [AC_CHECK_LIB(network, socket, SOCKET_LIB="-lnetwork")])
 AC_CHECK_FUNC(inet_aton,, [AC_CHECK_LIB(resolv, inet_aton, RESOLV_LIB="-lresolv")])
 
 dnl Group related network libraries together so they can always be linked
@@ -293,7 +294,7 @@
 HAVE_USB=no
 if test "$enable_libusb" != "no"; then
   case ${host_os} in
-  beos*)
+  beos*|haiku*)
   AC_CHECK_HEADERS(be/drivers/USB_scanner.h, HAVE_USB=yes, AC_MSG_ERROR([USB_scanner.h is required on BeOS]))
   ;;
   os2*)
@@ -467,7 +468,7 @@
 
 dnl Windows (cygwin/mingw), BeOS, and OS/2 need this.
 case $host_os in
-  cygwin* | mingw* | beos* | os2*)
+  cygwin* | mingw* | beos* | haiku* | os2*)
   LDFLAGS="$LDFLAGS -no-undefined"
 esac
 
@@ -619,6 +620,9 @@
   beos*)
   libdir='${exec_prefix}/add-ons'
   ;;
+  haiku*)
+  libdir=`finddir B_COMMON_DIRECTORY/add-ons`
+  ;;
 esac
 
 AC_ARG_ENABLE(parport-directio,
diff -urN sane-backends-1.0.21/sanei/sanei_config.c sane-backends-1.0.21-haiku/sanei/sanei_config.c
--- sane-backends-1.0.21/sanei/sanei_config.c	2010-04-05 13:18:05.038273024 +0000
+++ sane-backends-1.0.21-haiku/sanei/sanei_config.c	2010-06-24 03:45:11.972816384 +0000
@@ -72,7 +72,7 @@
 
 #define DEFAULT_DIRS	"." DIR_SEP STRINGIFY(PATH_SANE_CONFIG_DIR)
 
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
 #include <FindDirectory.h>
 #endif
 
@@ -91,7 +91,7 @@
       DBG_INIT();
 
       dir_list = getenv ("SANE_CONFIG_DIR");
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
       /* ~/config/settings/SANE takes precedence over /etc/sane.d/ */
       if (!dir_list)
 	{
diff -urN sane-backends-1.0.21/sanei/sanei_pio.c sane-backends-1.0.21-haiku/sanei/sanei_pio.c
--- sane-backends-1.0.21/sanei/sanei_pio.c	2010-04-05 13:18:06.039321600 +0000
+++ sane-backends-1.0.21-haiku/sanei/sanei_pio.c	2010-06-24 03:45:37.013107200 +0000
@@ -534,7 +534,7 @@
 
 #else /* !HAVE_IOPERM */
 
-#ifdef __BEOS__
+#if defined __BEOS__ || defined __HAIKU__
 
 #include <fcntl.h>
 
@@ -571,7 +571,7 @@
   	return(write(fd,buf,n));
 }
 
-#else /* !__BEOS__ */
+#else /* !__BEOS__ || __HAIKU__ */
 
 SANE_Status
 sanei_pio_open (const char *dev, int *fdp)
@@ -598,6 +598,6 @@
 {
   return -1;
 }
-#endif /* __BEOS__ */
+#endif /* __BEOS__ || __HAIKU__ */
 
 #endif /* !HAVE_IOPERM */
diff -urN sane-backends-1.0.21/sanei/sanei_usb.c sane-backends-1.0.21-haiku/sanei/sanei_usb.c
--- sane-backends-1.0.21/sanei/sanei_usb.c	2010-04-05 13:18:06.041156608 +0000
+++ sane-backends-1.0.21-haiku/sanei/sanei_usb.c	2010-06-24 03:46:05.417595392 +0000
@@ -195,7 +195,7 @@
   void *data;
 }
 cmsg;
-#elif defined(__BEOS__)
+#elif defined(__BEOS__) || defined(__HAIKU__)
 #include <drivers/USB_scanner.h>
 #include <kernel/OS.h>
 #endif /* __linux__ */
@@ -260,7 +260,7 @@
 	DBG (3, "sanei_usb_get_vendor_product: ioctl (product) "
 	     "of device %s failed: %s\n", name, strerror (errno));
     }
-#elif defined(__BEOS__)
+#elif defined(__BEOS__) || defined(__HAIKU__)
   {
     uint16 vendor, product;
     if (ioctl (fd, B_SCANNER_IOCTL_VENDOR, &vendor) != B_OK)
@@ -440,7 +440,7 @@
     "/dev/usb/", "scanner",
 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__) || defined (__DragonFly__)
     "/dev/", "uscanner",
-#elif defined(__BEOS__)
+#elif defined(__BEOS__) || defined(__HAIKU__)
     "/dev/scanner/usb/", "",
 #endif
     0, 0
@@ -2344,7 +2344,7 @@
       if ((rtype & 0x80) && debug_level > 10)
 	print_buffer (data, len);
       return SANE_STATUS_GOOD;
-#elif defined(__BEOS__)
+#elif defined(__BEOS__) || defined(__HAIKU__)
       struct usb_scanner_ioctl_ctrlmsg c;
 
       c.req.request_type = rtype;
