mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-03 19:31:43 +02:00
get proper host name on Android
This commit is contained in:
parent
ac11f01528
commit
65f239b359
1 changed files with 25 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <iterator>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
|
@ -100,8 +101,32 @@ static std::vector<std::string> split(const std::string &s, char delim)
|
|||
}
|
||||
|
||||
|
||||
#ifdef ANDROID
|
||||
static std::string getProp(const std::string& prop)
|
||||
{
|
||||
std::string cmd = "getprop " + prop;
|
||||
std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose);
|
||||
if (!pipe)
|
||||
return "";
|
||||
char buffer[512];
|
||||
std::string result = "";
|
||||
while (!feof(pipe.get()))
|
||||
{
|
||||
if (fgets(buffer, 512, pipe.get()) != NULL)
|
||||
result += buffer;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static std::string getHostName()
|
||||
{
|
||||
#ifdef ANDROID
|
||||
std::string result = getProp("net.hostname");
|
||||
if (!result.empty())
|
||||
return result;
|
||||
#endif
|
||||
char hostname[1024];
|
||||
hostname[1023] = '\0';
|
||||
gethostname(hostname, 1023);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue