diff --git a/common/utils.h b/common/utils.h index e8e36265..9e2127ad 100644 --- a/common/utils.h +++ b/common/utils.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -100,8 +101,32 @@ static std::vector 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 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);