fi
 
 if test "$with_bonjour" = yes ; then
-  if test "${ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h+set}" = set; then
-  { $as_echo "$as_me:$LINENO: checking for DNSServiceDiscovery/DNSServiceDiscovery.h" >&5
-$as_echo_n "checking for DNSServiceDiscovery/DNSServiceDiscovery.h... " >&6; }
-if test "${ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h+set}" = set; then
+  if test "${ac_cv_header_dns_sd_h+set}" = set; then
+  { $as_echo "$as_me:$LINENO: checking for dns_sd.h" >&5
+$as_echo_n "checking for dns_sd.h... " >&6; }
+if test "${ac_cv_header_dns_sd_h+set}" = set; then
   $as_echo_n "(cached) " >&6
 fi
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&5
-$as_echo "$ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&6; }
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_dns_sd_h" >&5
+$as_echo "$ac_cv_header_dns_sd_h" >&6; }
 else
   # Is the header compilable?
-{ $as_echo "$as_me:$LINENO: checking DNSServiceDiscovery/DNSServiceDiscovery.h usability" >&5
-$as_echo_n "checking DNSServiceDiscovery/DNSServiceDiscovery.h usability... " >&6; }
+{ $as_echo "$as_me:$LINENO: checking dns_sd.h usability" >&5
+$as_echo_n "checking dns_sd.h usability... " >&6; }
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 $ac_includes_default
-#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
+#include <dns_sd.h>
 _ACEOF
 rm -f conftest.$ac_objext
 if { (ac_try="$ac_compile"
 $as_echo "$ac_header_compiler" >&6; }
 
 # Is the header present?
-{ $as_echo "$as_me:$LINENO: checking DNSServiceDiscovery/DNSServiceDiscovery.h presence" >&5
-$as_echo_n "checking DNSServiceDiscovery/DNSServiceDiscovery.h presence... " >&6; }
+{ $as_echo "$as_me:$LINENO: checking dns_sd.h presence" >&5
+$as_echo_n "checking dns_sd.h presence... " >&6; }
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
+#include <dns_sd.h>
 _ACEOF
 if { (ac_try="$ac_cpp conftest.$ac_ext"
 case "(($ac_try" in
 # So?  What about this header?
 case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
   yes:no: )
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: accepted by the compiler, rejected by the preprocessor!" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the compiler's result" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the compiler's result" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: dns_sd.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: dns_sd.h: proceeding with the compiler's result" >&2;}
     ac_header_preproc=yes
     ;;
   no:yes:* )
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: present but cannot be compiled" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: present but cannot be compiled" >&2;}
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h:     check for missing prerequisite headers?" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h:     check for missing prerequisite headers?" >&2;}
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: see the Autoconf documentation" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: see the Autoconf documentation" >&2;}
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h:     section \"Present But Cannot Be Compiled\"" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the preprocessor's result" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the preprocessor's result" >&2;}
-    { $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: in the future, the compiler will take precedence" >&5
-$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: in the future, the compiler will take precedence" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: dns_sd.h: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: dns_sd.h:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: dns_sd.h: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: dns_sd.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: proceeding with the preprocessor's result" >&5
+$as_echo "$as_me: WARNING: dns_sd.h: proceeding with the preprocessor's result" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: in the future, the compiler will take precedence" >&5
+$as_echo "$as_me: WARNING: dns_sd.h: in the future, the compiler will take precedence" >&2;}
     ( cat <<\_ASBOX
 ## ---------------------------------------- ##
 ## Report this to pgsql-bugs@postgresql.org ##
      ) | sed "s/^/$as_me: WARNING:     /" >&2
     ;;
 esac
-{ $as_echo "$as_me:$LINENO: checking for DNSServiceDiscovery/DNSServiceDiscovery.h" >&5
-$as_echo_n "checking for DNSServiceDiscovery/DNSServiceDiscovery.h... " >&6; }
-if test "${ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h+set}" = set; then
+{ $as_echo "$as_me:$LINENO: checking for dns_sd.h" >&5
+$as_echo_n "checking for dns_sd.h... " >&6; }
+if test "${ac_cv_header_dns_sd_h+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h=$ac_header_preproc
+  ac_cv_header_dns_sd_h=$ac_header_preproc
 fi
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&5
-$as_echo "$ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&6; }
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_dns_sd_h" >&5
+$as_echo "$ac_cv_header_dns_sd_h" >&6; }
 
 fi
-if test "x$ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" = x""yes; then
+if test "x$ac_cv_header_dns_sd_h" = x""yes; then
   :
 else
-  { { $as_echo "$as_me:$LINENO: error: header file <DNSServiceDiscovery/DNSServiceDiscovery.h> is required for Bonjour" >&5
-$as_echo "$as_me: error: header file <DNSServiceDiscovery/DNSServiceDiscovery.h> is required for Bonjour" >&2;}
+  { { $as_echo "$as_me:$LINENO: error: header file <dns_sd.h> is required for Bonjour" >&5
+$as_echo "$as_me: error: header file <dns_sd.h> is required for Bonjour" >&2;}
    { (exit 1); exit 1; }; }
 fi
 
 
 #endif
 
 #ifdef USE_BONJOUR
-#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
+#include <dns_sd.h>
 #endif
 
 #include "access/transam.h"
 extern int     optreset;                       /* might not be declared by system headers */
 #endif
 
+#ifdef USE_BONJOUR
+static DNSServiceRef bonjour_sdref = NULL;
+#endif
+
 /*
  * postmaster.c - function prototypes
  */
 static void getInstallationPaths(const char *argv0);
 static void checkDataDir(void);
-
-#ifdef USE_BONJOUR
-static void reg_reply(DNSServiceRegistrationReplyErrorType errorCode,
-                 void *context);
-#endif
 static void pmdaemonize(void);
 static Port *ConnCreate(int serverFd);
 static void ConnFree(Port *port);
 
 #ifdef USE_BONJOUR
        /* Register for Bonjour only if we opened TCP socket(s) */
-       if (ListenSocket[0] != -1 && bonjour_name != NULL)
+       if (ListenSocket[0] != -1)
        {
-               DNSServiceRegistrationCreate(bonjour_name,
-                                                                        "_postgresql._tcp.",
-                                                                        "",
-                                                                        htons(PostPortNumber),
-                                                                        "",
-                                                                        (DNSServiceRegistrationReply) reg_reply,
-                                                                        NULL);
+               DNSServiceErrorType err;
+
+               /*
+                * We pass 0 for interface_index, which will result in registering on
+                * all "applicable" interfaces.  It's not entirely clear from the
+                * DNS-SD docs whether this would be appropriate if we have bound to
+                * just a subset of the available network interfaces.
+                */
+               err = DNSServiceRegister(&bonjour_sdref,
+                                                                0,
+                                                                0,
+                                                                bonjour_name,
+                                                                "_postgresql._tcp.",
+                                                                NULL,
+                                                                NULL,
+                                                                htons(PostPortNumber),
+                                                                0,
+                                                                NULL,
+                                                                NULL,
+                                                                NULL);
+               if (err != kDNSServiceErr_NoError)
+                       elog(LOG, "DNSServiceRegister() failed: error code %ld",
+                                (long) err);
+               /*
+                * We don't bother to read the mDNS daemon's reply, and we expect
+                * that it will automatically terminate our registration when the
+                * socket is closed at postmaster termination.  So there's nothing
+                * more to be done here.  However, the bonjour_sdref is kept around
+                * so that forked children can close their copies of the socket.
+                */
        }
 #endif
 
 }
 
 
-#ifdef USE_BONJOUR
-
-/*
- * empty callback function for DNSServiceRegistrationCreate()
- */
-static void
-reg_reply(DNSServiceRegistrationReplyErrorType errorCode, void *context)
-{
-}
-#endif   /* USE_BONJOUR */
-
-
 /*
  * Fork away from the controlling terminal (silent_mode option)
  *
                syslogPipe[0] = 0;
 #endif
        }
+
+#ifdef USE_BONJOUR
+       /* If using Bonjour, close the connection to the mDNS daemon */
+       if (bonjour_sdref)
+               close(DNSServiceRefSockFD(bonjour_sdref));
+#endif
 }