Malik Akbar Hashemi Rafsanjani | 4d7b5dd | 2025-02-26 13:14:30 -0800 | [diff] [blame] | 1 | #include <unistd.h> |
2 | |||||
3 | #include <array> | ||||
4 | #include <climits> | ||||
5 | #include <string> | ||||
6 | |||||
7 | inline std::string getHostName() | ||||
8 | { | ||||
9 | std::string hostName; | ||||
10 | |||||
11 | std::array<char, HOST_NAME_MAX> hostNameCStr{}; | ||||
12 | if (gethostname(hostNameCStr.data(), hostNameCStr.size()) == 0) | ||||
13 | { | ||||
14 | hostName = hostNameCStr.data(); | ||||
15 | } | ||||
16 | return hostName; | ||||
17 | } |