mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-07 05:11:43 +02:00
zeroconf works with IPv6
This commit is contained in:
parent
e9ff66e78b
commit
b34f8a6e00
5 changed files with 57 additions and 38 deletions
|
@ -15,6 +15,9 @@ endif()
|
||||||
|
|
||||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
set(MACOSX TRUE)
|
set(MACOSX TRUE)
|
||||||
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||||
|
set (ANDROID TRUE)
|
||||||
|
message(FATAL_ERROR "Android not yet supported")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Configure paths
|
# Configure paths
|
||||||
|
@ -87,6 +90,8 @@ if(MACOSX)
|
||||||
endif (BONJOUR_FOUND)
|
endif (BONJOUR_FOUND)
|
||||||
|
|
||||||
add_definitions(-DFREEBSD -DHAS_DAEMON)
|
add_definitions(-DFREEBSD -DHAS_DAEMON)
|
||||||
|
elseif(ANDROID)
|
||||||
|
add_definitions("-DNO_CPP11_STRING")
|
||||||
else()
|
else()
|
||||||
pkg_search_module(ALSA REQUIRED alsa)
|
pkg_search_module(ALSA REQUIRED alsa)
|
||||||
if (ALSA_FOUND)
|
if (ALSA_FOUND)
|
||||||
|
@ -97,6 +102,8 @@ else()
|
||||||
if (AVAHI_FOUND)
|
if (AVAHI_FOUND)
|
||||||
add_definitions(-DHAS_AVAHI)
|
add_definitions(-DHAS_AVAHI)
|
||||||
endif (AVAHI_FOUND)
|
endif (AVAHI_FOUND)
|
||||||
|
|
||||||
|
add_definitions(-DHAS_DAEMON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
pkg_search_module(FLAC flac)
|
pkg_search_module(FLAC flac)
|
||||||
|
|
|
@ -90,11 +90,13 @@ void BrowseAvahi::resolve_callback(
|
||||||
LOG(INFO) << "Service '" << name << "' of type '" << type << "' in domain '" << domain << "':\n";
|
LOG(INFO) << "Service '" << name << "' of type '" << type << "' in domain '" << domain << "':\n";
|
||||||
|
|
||||||
avahi_address_snprint(a, sizeof(a), address);
|
avahi_address_snprint(a, sizeof(a), address);
|
||||||
browseAvahi->result_.host_ = host_name;
|
browseAvahi->result_.host = host_name;
|
||||||
browseAvahi->result_.ip_ = a;
|
browseAvahi->result_.ip = a;
|
||||||
browseAvahi->result_.port_ = port;
|
browseAvahi->result_.port = port;
|
||||||
browseAvahi->result_.proto_ = protocol;
|
// protocol seems to be unreliable (0 for IPv4 and for IPv6)
|
||||||
browseAvahi->result_.valid_ = true;
|
browseAvahi->result_.ip_version = (browseAvahi->result_.ip.find(":") == std::string::npos)?(IPVersion::IPv4):(IPVersion::IPv6);
|
||||||
|
browseAvahi->result_.valid = true;
|
||||||
|
browseAvahi->result_.iface_idx = interface;
|
||||||
|
|
||||||
t = avahi_string_list_to_string(txt);
|
t = avahi_string_list_to_string(txt);
|
||||||
LOG(INFO) << "\t" << host_name << ":" << port << " (" << a << ")\n";
|
LOG(INFO) << "\t" << host_name << ":" << port << " (" << a << ")\n";
|
||||||
|
@ -196,12 +198,12 @@ bool BrowseAvahi::browse(const std::string& serviceName, mDNSResult& result, int
|
||||||
if (!(sb_ = avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, serviceName.c_str(), NULL, (AvahiLookupFlags)0, browse_callback, this)))
|
if (!(sb_ = avahi_service_browser_new(client_, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, serviceName.c_str(), NULL, (AvahiLookupFlags)0, browse_callback, this)))
|
||||||
throw SnapException("BrowseAvahi - Failed to create service browser: " + std::string(avahi_strerror(avahi_client_errno(client_))));
|
throw SnapException("BrowseAvahi - Failed to create service browser: " + std::string(avahi_strerror(avahi_client_errno(client_))));
|
||||||
|
|
||||||
result_.valid_ = false;
|
result_.valid = false;
|
||||||
while (timeout > 0)
|
while (timeout > 0)
|
||||||
{
|
{
|
||||||
avahi_simple_poll_iterate(simple_poll, 100);
|
avahi_simple_poll_iterate(simple_poll, 100);
|
||||||
timeout -= 100;
|
timeout -= 100;
|
||||||
if (result_.valid_)
|
if (result_.valid)
|
||||||
{
|
{
|
||||||
result = result_;
|
result = result_;
|
||||||
cleanUp();
|
cleanUp();
|
||||||
|
|
|
@ -237,8 +237,9 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int ti
|
||||||
{
|
{
|
||||||
auto result = static_cast<mDNSResult*>(context);
|
auto result = static_cast<mDNSResult*>(context);
|
||||||
|
|
||||||
result->host_ = string(hostname);
|
result->host = string(hostname);
|
||||||
result->proto_ = address->sa_family;
|
result->ip_version = (address->sa_family == AF_INET)?(IPVersion::IPv4):(IPVersion::IPv6);
|
||||||
|
result->iface_idx = static_cast<int>(interfaceIndex);
|
||||||
|
|
||||||
char hostIP[NI_MAXHOST];
|
char hostIP[NI_MAXHOST];
|
||||||
char hostService[NI_MAXSERV];
|
char hostService[NI_MAXSERV];
|
||||||
|
@ -252,7 +253,6 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int ti
|
||||||
result->valid_ = true;
|
result->valid_ = true;
|
||||||
}, &resultCollection[i++]));
|
}, &resultCollection[i++]));
|
||||||
}
|
}
|
||||||
|
|
||||||
runService(service);
|
runService(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,21 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
enum IPVersion
|
||||||
|
{
|
||||||
|
IPv4 = 0,
|
||||||
|
IPv6 = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct mDNSResult
|
struct mDNSResult
|
||||||
{
|
{
|
||||||
int proto_;
|
IPVersion ip_version;
|
||||||
std::string ip_;
|
int iface_idx;
|
||||||
std::string host_;
|
std::string ip;
|
||||||
uint16_t port_;
|
std::string host;
|
||||||
bool valid_;
|
uint16_t port;
|
||||||
|
bool valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BrowsemDNS
|
class BrowsemDNS
|
||||||
|
|
|
@ -218,8 +218,10 @@ int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (browser.browse("_snapcast._tcp", avahiResult, 5000))
|
if (browser.browse("_snapcast._tcp", avahiResult, 5000))
|
||||||
{
|
{
|
||||||
host = avahiResult.ip_;
|
host = avahiResult.ip;
|
||||||
port = avahiResult.port_;
|
port = avahiResult.port;
|
||||||
|
if (avahiResult.ip_version == IPVersion::IPv6)
|
||||||
|
host += "%" + cpt::to_string(avahiResult.iface_idx);
|
||||||
LOG(INFO) << "Found server " << host << ":" << port << "\n";
|
LOG(INFO) << "Found server " << host << ":" << port << "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue