--- source3/wscript.orig	2020-09-07 06:52:25.000000000 -0400
+++ source3/wscript	2020-12-11 19:16:08.629997000 -0500
@@ -71,6 +71,7 @@
     opt.samba_add_onoff_option('sendfile-support', default=None)
     opt.samba_add_onoff_option('utmp')
     opt.samba_add_onoff_option('avahi', with_name="enable", without_name="disable")
+    opt.samba_add_onoff_option('dnssd', with_name="enable", without_name="disable")
     opt.samba_add_onoff_option('iconv')
     opt.samba_add_onoff_option('acl-support')
     opt.samba_add_onoff_option('dnsupdate')
@@ -499,7 +500,7 @@
         conf.DEFINE('DARWINOS', 1)
         conf.ADD_CFLAGS('-fno-common')
         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
-    elif (host_os.rfind('freebsd') > -1):
+    elif (host_os.rfind('midnightbsd') > -1):
         conf.DEFINE('FREEBSD', 1)
         if conf.CHECK_HEADERS('sunacl.h'):
             conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
@@ -851,34 +852,39 @@
 
     if Options.options.with_utmp:
         conf.env.with_utmp = True
-        if not conf.CHECK_HEADERS('utmp.h'): conf.env.with_utmp = False
-        conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
+        if not conf.CHECK_HEADERS('utmpx.h') and not conf.CHECK_HEADERS('utmp.h'):
+            conf.env.with_utmp = False
+        if conf.CONFIG_SET('HAVE_UTMPX_H'):
+            conf.DEFINE('STRUCT_UTMP', 'struct utmpx')
+        elif conf.CONFIG_SET('HAVE_UTMP_H'):
+            conf.DEFINE('STRUCT_UTMP', 'struct utmp')
+        conf.CHECK_FUNCS('pututxline getutxid getutxline updwtmpx getutmpx setutxent endutxent')
+        conf.CHECK_FUNCS('pututline getutid getutline updwtmp getutmp setutent endutent')
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_name', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_NAME')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
+
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_user', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_USER')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_id', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_ID')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_host', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_HOST')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_time', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_TIME')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_tv', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_TV')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_type', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_TYPE')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_pid', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_PID')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_exit.e_exit', headers='utmpx.h utmp.h',
                                     define='HAVE_UT_UT_EXIT')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
-                                    define='HAVE_UX_UT_SYSLEN')
-        conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_host', headers='utmpx.h',
-                                    define='HAVE_UX_UT_HOST')
+        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_syslen', headers='utmpx.h utmp.h',
+                                    define='HAVE_UT_UT_SYSLEN')
         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
                         msg="Checking whether pututline returns pointer")
-        conf.CHECK_SIZEOF(['((struct utmp *)NULL)->ut_line'], headers='utmp.h',
+        conf.CHECK_SIZEOF(['((STRUCT_UTMP *)NULL)->ut_line'], headers='utmpx.h utmp.h',
                           define='SIZEOF_UTMP_UT_LINE', critical=False)
         if not conf.CONFIG_SET('SIZEOF_UTMP_UT_LINE'):
             conf.env.with_utmp = False
@@ -900,6 +906,17 @@
         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
 
+    if Options.options.with_dnssd:
+        conf.env.with_dnssd = True
+        if not conf.CHECK_HEADERS('dns_sd.h'):
+            conf.env.with_dnssd = False
+        if not conf.CHECK_FUNCS_IN('DNSServiceRegister', 'dns_sd'):
+            conf.env.with_dnssd = False
+        if conf.env.with_dnssd:
+            conf.DEFINE('WITH_DNSSD_SUPPORT', 1)
+    else:
+        conf.SET_TARGET_TYPE('dns_sd', 'EMPTY')
+
     if Options.options.with_iconv:
         conf.env.with_iconv = True
         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
@@ -1445,7 +1462,7 @@
             if conf.CONFIG_SET('_HAVE_SENDFILE'):
                 conf.DEFINE('HAVE_SENDFILE', '1')
                 conf.DEFINE('LINUX_SENDFILE_API', '1')
-        elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
+        elif (host_os.rfind('midnightbsd') > -1) or (host_os.rfind('dragonfly') > -1):
             conf.CHECK_CODE('''
                             #include <sys/types.h>
                             #include <unistd.h>
@@ -1464,7 +1481,7 @@
                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
                             ''',
                             '_HAVE_SENDFILE',
-                            msg='Checking for freebsd sendfile support')
+                            msg='Checking for bsd sendfile support')
             if conf.CONFIG_SET('_HAVE_SENDFILE'):
                 conf.DEFINE('HAVE_SENDFILE', '1')
                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
