mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-25 04:19:16 +02:00
requests are enum
git-svn-id: svn://elaine/murooma/trunk@304 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
e5f064a01f
commit
6fbabaae82
10 changed files with 80 additions and 48 deletions
|
@ -9,8 +9,12 @@
|
|||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
// trim from start
|
||||
static inline std::string <rim(std::string &s)
|
||||
|
@ -33,22 +37,52 @@ static inline std::string &trim(std::string &s)
|
|||
}
|
||||
|
||||
|
||||
static std::string getMacAddress()
|
||||
static std::string getMacAddress(int sock)
|
||||
{
|
||||
std::ifstream t("/sys/class/net/eth0/address");
|
||||
struct ifreq ifr;
|
||||
struct ifconf ifc;
|
||||
char buf[1024];
|
||||
int success = 0;
|
||||
|
||||
if (sock < 0)
|
||||
return "";
|
||||
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_buf = buf;
|
||||
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1)
|
||||
return "";
|
||||
|
||||
struct ifreq* it = ifc.ifc_req;
|
||||
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));
|
||||
|
||||
for (; it != end; ++it) {
|
||||
strcpy(ifr.ifr_name, it->ifr_name);
|
||||
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
|
||||
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
|
||||
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
|
||||
success = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* handle error */ }
|
||||
}
|
||||
|
||||
if (!success)
|
||||
return "";
|
||||
|
||||
char mac[19];
|
||||
sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
(unsigned char)ifr.ifr_hwaddr.sa_data[0], (unsigned char)ifr.ifr_hwaddr.sa_data[1], (unsigned char)ifr.ifr_hwaddr.sa_data[2],
|
||||
(unsigned char)ifr.ifr_hwaddr.sa_data[3], (unsigned char)ifr.ifr_hwaddr.sa_data[4], (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
|
||||
return mac;
|
||||
}
|
||||
/* std::ifstream t("/sys/class/net/eth0/address");
|
||||
std::string str((std::istreambuf_iterator<char>(t)),
|
||||
std::istreambuf_iterator<char>());
|
||||
return trim(str);
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> split(const std::string& str)
|
||||
{
|
||||
std::istringstream iss(str);
|
||||
std::vector<std::string> splitStr;
|
||||
std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(splitStr));
|
||||
return splitStr;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static void daemonize()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue