mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-29 08:56:18 +02:00
fallback for getting the MAC address
This commit is contained in:
parent
4eb77a2384
commit
2923a7d456
2 changed files with 22 additions and 5 deletions
|
@ -72,7 +72,7 @@ void ClientConnection::start()
|
||||||
std::string mac = getMacAddress(socket_->native());
|
std::string mac = getMacAddress(socket_->native());
|
||||||
if (mac.empty())
|
if (mac.empty())
|
||||||
mac = "00:00:00:00:00:00";
|
mac = "00:00:00:00:00:00";
|
||||||
logO << "My MAC: \"" << mac << "\"\n";
|
logO << "My MAC: \"" << mac << "\", socket: " << socket_->native() << "\n";
|
||||||
msg::Hello hello(mac);
|
msg::Hello hello(mac);
|
||||||
send(&hello);
|
send(&hello);
|
||||||
connected_ = true;
|
connected_ = true;
|
||||||
|
|
|
@ -160,14 +160,31 @@ static std::string getMacAddress(int sock)
|
||||||
struct ifreq* it = ifc.ifc_req;
|
struct ifreq* it = ifc.ifc_req;
|
||||||
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));
|
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));
|
||||||
|
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it)
|
||||||
|
{
|
||||||
strcpy(ifr.ifr_name, it->ifr_name);
|
strcpy(ifr.ifr_name, it->ifr_name);
|
||||||
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
|
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0)
|
||||||
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
|
{
|
||||||
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
|
if (!(ifr.ifr_flags & IFF_LOOPBACK)) // don't count loopback
|
||||||
|
{
|
||||||
|
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0)
|
||||||
|
{
|
||||||
success = 1;
|
success = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "/sys/class/net/" << ifr.ifr_name << "/address";
|
||||||
|
std::ifstream infile(ss.str().c_str());
|
||||||
|
std::string line;
|
||||||
|
if (infile.good() && std::getline(infile, line))
|
||||||
|
{
|
||||||
|
trim(line);
|
||||||
|
if ((line.size() == 17) && (line[2] == ':'))
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { /* handle error */ }
|
else { /* handle error */ }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue