From af2937e046b1ca6f1121a424ee0adc84569eb83d Mon Sep 17 00:00:00 2001 From: "F. Duncanh" Date: Tue, 13 Dec 2022 19:34:44 -0500 Subject: [PATCH] add error message if dnssd_register_airplay or _raop fails --- README.html | 30 ++++++++++++++++++++---------- README.md | 10 +++++++++- README.txt | 31 ++++++++++++++++++++++--------- lib/dnssd.c | 11 ++++++----- uxplay.cpp | 28 ++++++++++++++++++++++------ 5 files changed, 79 insertions(+), 31 deletions(-) diff --git a/README.html b/README.html index 84fd8c1..de5852e 100644 --- a/README.html +++ b/README.html @@ -823,18 +823,28 @@ correct one; on 64-bit Ubuntu, this is done by running export OPENSSL_ROOT_DIR=/usr/lib/X86_64-linux-gnu/ before running cmake.

1. -uxplay starts, but stalls after “Initialized server socket(s)” appears, -without any server name showing on the client.

+id="uxplay-starts-but-stalls-or-stops-after-initialized-server-sockets-appears-without-any-server-name-showing-on-the-client.">1. +uxplay starts, but stalls or stops after “Initialized server socket(s)” +appears, without any server name showing on the client.

Stalling this way, with no server name showing on the client as available, probably means that your network does -not have a running Bonjour/zeroconf DNS-SD server. On Linux, -make sure Avahi is installed, and start the avahi-daemon service on the -system running uxplay (your distribution will document how to do this). -Some systems may instead use the mdnsd daemon as an alternative to -provide DNS-SD service. (FreeBSD offers both alternatives, but only -Avahi was tested: one of the steps needed for getting Avahi running on a -FreeBSD system is to edit +not have a running Bonjour/zeroconf DNS-SD server.

+

UxPlay used to stall silently if DNS-SD service registration failed, +but now stops with an error message returned by the DNSServiceRegister +function, which will probably be -65537 (0xFFFE FFFF, or +kDNSServiceErr_Unknown) if no DNS-SD server was found: mDNS error codes +are in the range FFFE FF00 (-65792) to FFFE FFFF (-65537), and are +listed in Apple’s dnssd.h file. An older version of this (the one used +by avahi) is found here. +A few additional error codes are defined in a later version from Apple.

+

On Linux, make sure Avahi is installed, and start the avahi-daemon +service on the system running uxplay (your distribution will document +how to do this). Some systems may instead use the mdnsd daemon as an +alternative to provide DNS-SD service. (FreeBSD offers both +alternatives, but only Avahi was tested: one of the steps needed for +getting Avahi running on a FreeBSD system is to edit /usr/local/etc/avahi/avahi-daemon.conf to uncomment a line for airplay support.)

After starting uxplay, use the utility diff --git a/README.md b/README.md index 4a49155..9df32cd 100644 --- a/README.md +++ b/README.md @@ -692,10 +692,18 @@ Solution: when more than one installation of OpenSSL is present, set the environ on 64-bit Ubuntu, this is done by running `export OPENSSL_ROOT_DIR=/usr/lib/X86_64-linux-gnu/` before running cmake. -### 1. uxplay starts, but stalls after "Initialized server socket(s)" appears, *without any server name showing on the client*. +### 1. uxplay starts, but stalls or stops after "Initialized server socket(s)" appears, *without any server name showing on the client*. Stalling this way, with _no_ server name showing _on the client_ as available, probably means that your network **does not have a running Bonjour/zeroconf DNS-SD server.** + +UxPlay used to stall silently if DNS-SD service registration failed, but now stops with an error message returned by the +DNSServiceRegister function, which will probably be -65537 (0xFFFE FFFF, or kDNSServiceErr_Unknown) if no DNS-SD server was found: +mDNS error codes are in the range FFFE FF00 (-65792) to FFFE FFFF (-65537), and are listed in Apple's +dnssd.h file. An older version of this (the one used by avahi) is found [here](https://github.com/lathiat/avahi/blob/master/avahi-compat-libdns_sd/dns_sd.h). +A few additional error codes are defined in a later version +from [Apple](https://opensource.apple.com/source/mDNSResponder/mDNSResponder-544/mDNSShared/dns_sd.h.auto.html). + On Linux, make sure Avahi is installed, and start the avahi-daemon service on the system running uxplay (your distribution will document how to do this). Some systems may instead use the mdnsd daemon as an alternative to provide DNS-SD service. diff --git a/README.txt b/README.txt index ef7c68e..632519f 100644 --- a/README.txt +++ b/README.txt @@ -844,18 +844,31 @@ correct one; on 64-bit Ubuntu, this is done by running `export OPENSSL_ROOT_DIR=/usr/lib/X86_64-linux-gnu/` before running cmake. -### 1. uxplay starts, but stalls after "Initialized server socket(s)" appears, *without any server name showing on the client*. +### 1. uxplay starts, but stalls or stops after "Initialized server socket(s)" appears, *without any server name showing on the client*. Stalling this way, with *no* server name showing *on the client* as available, probably means that your network **does not have a running -Bonjour/zeroconf DNS-SD server.** On Linux, make sure Avahi is -installed, and start the avahi-daemon service on the system running -uxplay (your distribution will document how to do this). Some systems -may instead use the mdnsd daemon as an alternative to provide DNS-SD -service. *(FreeBSD offers both alternatives, but only Avahi was tested: -one of the steps needed for getting Avahi running on a FreeBSD system is -to edit `/usr/local/etc/avahi/avahi-daemon.conf` to uncomment a line for -airplay support.*) +Bonjour/zeroconf DNS-SD server.** + +UxPlay used to stall silently if DNS-SD service registration failed, but +now stops with an error message returned by the DNSServiceRegister +function, which will probably be -65537 (0xFFFE FFFF, or +kDNSServiceErr_Unknown) if no DNS-SD server was found: mDNS error codes +are in the range FFFE FF00 (-65792) to FFFE FFFF (-65537), and are +listed in Apple's dnssd.h file. An older version of this (the one used +by avahi) is found +[here](https://github.com/lathiat/avahi/blob/master/avahi-compat-libdns_sd/dns_sd.h). +A few additional error codes are defined in a later version from +[Apple](https://opensource.apple.com/source/mDNSResponder/mDNSResponder-544/mDNSShared/dns_sd.h.auto.html). + +On Linux, make sure Avahi is installed, and start the avahi-daemon +service on the system running uxplay (your distribution will document +how to do this). Some systems may instead use the mdnsd daemon as an +alternative to provide DNS-SD service. *(FreeBSD offers both +alternatives, but only Avahi was tested: one of the steps needed for +getting Avahi running on a FreeBSD system is to edit +`/usr/local/etc/avahi/avahi-daemon.conf` to uncomment a line for airplay +support.*) After starting uxplay, use the utility `avahi-browse -a -t` in a different terminal window on the server to verify that the UxPlay diff --git a/lib/dnssd.c b/lib/dnssd.c index e6e5cbd..2a93790 100644 --- a/lib/dnssd.c +++ b/lib/dnssd.c @@ -255,6 +255,7 @@ int dnssd_register_raop(dnssd_t *dnssd, unsigned short port) { char servname[MAX_SERVNAME]; + DNSServiceErrorType retval; assert(dnssd); @@ -295,7 +296,7 @@ dnssd_register_raop(dnssd_t *dnssd, unsigned short port) strncat(servname, dnssd->name, sizeof(servname)-strlen(servname)-1); /* Register the service */ - dnssd->DNSServiceRegister(&dnssd->raop_service, 0, 0, + retval = dnssd->DNSServiceRegister(&dnssd->raop_service, 0, 0, servname, "_raop._tcp", NULL, NULL, htons(port), @@ -303,14 +304,14 @@ dnssd_register_raop(dnssd_t *dnssd, unsigned short port) dnssd->TXTRecordGetBytesPtr(&dnssd->raop_record), NULL, NULL); - - return 1; + return (int) retval; /* error codes are listed in Apple's dns_sd.h */ } int dnssd_register_airplay(dnssd_t *dnssd, unsigned short port) { char device_id[3 * MAX_HWADDR_LEN]; + DNSServiceErrorType retval; assert(dnssd); @@ -332,7 +333,7 @@ dnssd_register_airplay(dnssd_t *dnssd, unsigned short port) dnssd->TXTRecordSetValue(&dnssd->airplay_record, "vv", strlen(AIRPLAY_VV), AIRPLAY_VV); /* Register the service */ - dnssd->DNSServiceRegister(&dnssd->airplay_service, 0, 0, + retval = dnssd->DNSServiceRegister(&dnssd->airplay_service, 0, 0, dnssd->name, "_airplay._tcp", NULL, NULL, htons(port), @@ -340,7 +341,7 @@ dnssd_register_airplay(dnssd_t *dnssd, unsigned short port) dnssd->TXTRecordGetBytesPtr(&dnssd->airplay_record), NULL, NULL); - return 1; + return (int) retval; /* error codes are listed in Apple's dns_sd.h */ } const char * diff --git a/uxplay.cpp b/uxplay.cpp index f80b098..2694286 100644 --- a/uxplay.cpp +++ b/uxplay.cpp @@ -1260,6 +1260,7 @@ extern "C" void log_callback (void *cls, int level, const char *msg) { int start_raop_server (std::vector hw_addr, std::string name, unsigned short display[5], unsigned short tcp[3], unsigned short udp[3], bool debug_log) { + int dnssd_error; raop_callbacks_t raop_cbs; memset(&raop_cbs, 0, sizeof(raop_cbs)); raop_cbs.conn_init = conn_init; @@ -1306,9 +1307,8 @@ int start_raop_server (std::vector hw_addr, std::string name, unsigned sho raop_start(raop, &port); raop_set_port(raop, port); - int error; - dnssd = dnssd_init(name.c_str(), strlen(name.c_str()), hw_addr.data(), hw_addr.size(), &error); - if (error) { + dnssd = dnssd_init(name.c_str(), strlen(name.c_str()), hw_addr.data(), hw_addr.size(), &dnssd_error); + if (dnssd_error) { LOGE("Could not initialize dnssd library!"); stop_raop_server(); return -2; @@ -1316,13 +1316,29 @@ int start_raop_server (std::vector hw_addr, std::string name, unsigned sho raop_set_dnssd(raop, dnssd); - dnssd_register_raop(dnssd, port); + if ((dnssd_error = dnssd_register_raop(dnssd, port))) { + if (dnssd_error == -65537) { + LOGE("No DNS-SD Server found (DNSServiceRegister call returned kDNSServiceErr_Unknown)"); + } else { + LOGE("dnssd_register_raop failed with error code %d\n" + "mDNS Error codes are in range FFFE FF00 (-65792) to FFFE FFFF (-65537) " + "(see Apple's dns_sd.h)", dnssd_error); + } + stop_raop_server(); + return -3; + } if (tcp[2]) { port = tcp[2]; } else { - port = (port != HIGHEST_PORT ? port + 1 : port - 1); + port = (port != HIGHEST_PORT ? port + 1 : port - 1); + } + if ((dnssd_error = dnssd_register_airplay(dnssd, port))) { + LOGE("dnssd_register_airplay failed with error code %d\n" + "mDNS Error codes are in range FFFE FF00 (-65792) to FFFE FFFF (-65537) " + "(see Apple's dns_sd.h)", dnssd_error); + stop_raop_server(); + return -4; } - dnssd_register_airplay(dnssd, port); return 0; }