From 38f935ead88fa57f12b1dcf5419d70030c559066 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 20 Jul 2020 20:59:28 +0800 Subject: [PATCH] Support get hostname --- trunk/src/protocol/srs_service_utility.cpp | 18 ++++++++++++++++++ trunk/src/protocol/srs_service_utility.hpp | 3 +++ 2 files changed, 21 insertions(+) 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