mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-06 10:09:33 +02:00
use MAC address as default host id
This commit is contained in:
parent
1176cfd9df
commit
034c7f5f98
1 changed files with 18 additions and 18 deletions
|
@ -296,13 +296,14 @@ static std::string getMacAddress(int sock)
|
||||||
|
|
||||||
static std::string getHostId(const std::string defaultId = "")
|
static std::string getHostId(const std::string defaultId = "")
|
||||||
{
|
{
|
||||||
std::string result = "";
|
std::string result = strutils::trim_copy(defaultId);
|
||||||
#ifdef OPENWRT
|
|
||||||
/// on OpenWRT the dbus uid exists (/var/lib/dbus/machine-id),
|
/// the Android API will return "02:00:00:00:00:00" for WifiInfo.getMacAddress().
|
||||||
/// but seems to be recreated with every reboot
|
/// Maybe this could also happen with native code
|
||||||
if (!defaultId.empty())
|
if (!result.empty() && (result != "02:00:00:00:00:00") && (result != "00:00:00:00:00:00"))
|
||||||
return defaultId;
|
return result;
|
||||||
#elif MACOS
|
|
||||||
|
#ifdef MACOS
|
||||||
/// https://stackoverflow.com/questions/933460/unique-hardware-id-in-mac-os-x
|
/// https://stackoverflow.com/questions/933460/unique-hardware-id-in-mac-os-x
|
||||||
/// About this Mac, Hardware-UUID
|
/// About this Mac, Hardware-UUID
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
@ -314,22 +315,21 @@ static std::string getHostId(const std::string defaultId = "")
|
||||||
CFRelease(uuidCf);
|
CFRelease(uuidCf);
|
||||||
#elif ANDROID
|
#elif ANDROID
|
||||||
result = getProp("ro.serialno");
|
result = getProp("ro.serialno");
|
||||||
#else
|
|
||||||
/// TODO: store the id somewhere and reuse it (see OpenWRT)
|
|
||||||
std::ifstream infile("/var/lib/dbus/machine-id");
|
|
||||||
if (infile.good())
|
|
||||||
std::getline(infile, result);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//#else
|
||||||
|
// // on embedded platforms it's
|
||||||
|
// // - either not there
|
||||||
|
// // - or not unique, or changes during boot
|
||||||
|
// // - or changes during boot
|
||||||
|
// std::ifstream infile("/var/lib/dbus/machine-id");
|
||||||
|
// if (infile.good())
|
||||||
|
// std::getline(infile, result);
|
||||||
|
//#endif
|
||||||
strutils::trim(result);
|
strutils::trim(result);
|
||||||
if (!result.empty())
|
if (!result.empty())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
result = defaultId;
|
|
||||||
/// the Android API will return "02:00:00:00:00:00" for WifiInfo.getMacAddress().
|
|
||||||
/// Maybe this could also happen with native code
|
|
||||||
if (!result.empty() && (result != "02:00:00:00:00:00") && (result != "00:00:00:00:00:00"))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
/// The host name should be unique enough in a LAN
|
/// The host name should be unique enough in a LAN
|
||||||
return getHostName();
|
return getHostName();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue