diff --git a/trunk/src/protocol/srs_service_utility.cpp b/trunk/src/protocol/srs_service_utility.cpp index 51ae86ecb..8cdb738ff 100644 --- a/trunk/src/protocol/srs_service_utility.cpp +++ b/trunk/src/protocol/srs_service_utility.cpp @@ -382,3 +382,21 @@ string srs_get_original_ip(ISrsHttpMessage* r) return ""; } + +std::string _srs_system_hostname; + +string srs_get_system_hostname() +{ + if (!_srs_system_hostname.empty()) { + return _srs_system_hostname; + } + + char buf[256]; + if (-1 == gethostname(buf, sizeof(buf))) { + srs_warn("gethostbyname fail"); + return ""; + } + + _srs_system_hostname = std::string(buf); + return _srs_system_hostname; +} \ No newline at end of file diff --git a/trunk/src/protocol/srs_service_utility.hpp b/trunk/src/protocol/srs_service_utility.hpp index f6c9ccf1b..8b35016fc 100644 --- a/trunk/src/protocol/srs_service_utility.hpp +++ b/trunk/src/protocol/srs_service_utility.hpp @@ -76,5 +76,8 @@ extern bool srs_net_device_is_internet(const sockaddr* addr); // Get the original ip from query and header by proxy. extern std::string srs_get_original_ip(ISrsHttpMessage* r); +// Get hostname +extern std::string srs_get_system_hostname(void); + #endif