mirror of
https://github.com/thinkonmay/sunshine-sdk.git
synced 2026-01-06 18:58:32 +00:00
fix(hostname): fix handling of non-ASCII hostnames on Windows (#3382)
This commit is contained in:
parent
d552073eaf
commit
fb1f5b5a89
@ -410,7 +410,7 @@ namespace config {
|
||||
PRIVATE_KEY_FILE,
|
||||
CERTIFICATE_FILE,
|
||||
|
||||
boost::asio::ip::host_name(), // sunshine_name,
|
||||
platf::get_host_name(), // sunshine_name,
|
||||
"sunshine_state.json"s, // file_state
|
||||
{}, // external_ip
|
||||
};
|
||||
|
||||
@ -858,6 +858,13 @@ namespace platf {
|
||||
[[nodiscard]] std::unique_ptr<deinit_t>
|
||||
init();
|
||||
|
||||
/**
|
||||
* @brief Returns the current computer name in UTF-8.
|
||||
* @return Computer name or a placeholder upon failure.
|
||||
*/
|
||||
std::string
|
||||
get_host_name();
|
||||
|
||||
/**
|
||||
* @brief Gets the supported gamepads for this platform backend.
|
||||
* @details This may be called prior to `platf::input()`!
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
// lib includes
|
||||
#include <arpa/inet.h>
|
||||
#include <boost/asio/ip/address.hpp>
|
||||
#include <boost/asio/ip/host_name.hpp>
|
||||
#include <boost/process/v1.hpp>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
@ -797,6 +798,17 @@ namespace platf {
|
||||
return std::make_unique<qos_t>(sockfd, reset_options);
|
||||
}
|
||||
|
||||
std::string
|
||||
get_host_name() {
|
||||
try {
|
||||
return boost::asio::ip::host_name();
|
||||
}
|
||||
catch (boost::system::system_error &err) {
|
||||
BOOST_LOG(error) << "Failed to get hostname: "sv << err.what();
|
||||
return "Sunshine"s;
|
||||
}
|
||||
}
|
||||
|
||||
namespace source {
|
||||
enum source_e : std::size_t {
|
||||
#ifdef SUNSHINE_BUILD_CUDA
|
||||
|
||||
@ -426,7 +426,7 @@ namespace platf::publish {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto instance_name = net::mdns_instance_name(boost::asio::ip::host_name());
|
||||
auto instance_name = net::mdns_instance_name(platf::get_host_name());
|
||||
name.reset(avahi::strdup(instance_name.c_str()));
|
||||
|
||||
client.reset(
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "src/platform/common.h"
|
||||
|
||||
#include <boost/asio/ip/address.hpp>
|
||||
#include <boost/asio/ip/host_name.hpp>
|
||||
#include <boost/process/v1.hpp>
|
||||
|
||||
using namespace std::literals;
|
||||
@ -538,6 +539,17 @@ namespace platf {
|
||||
return std::make_unique<qos_t>(sockfd, reset_options);
|
||||
}
|
||||
|
||||
std::string
|
||||
get_host_name() {
|
||||
try {
|
||||
return boost::asio::ip::host_name();
|
||||
}
|
||||
catch (boost::system::system_error &err) {
|
||||
BOOST_LOG(error) << "Failed to get hostname: "sv << err.what();
|
||||
return "Sunshine"s;
|
||||
}
|
||||
}
|
||||
|
||||
class macos_high_precision_timer: public high_precision_timer {
|
||||
public:
|
||||
void
|
||||
|
||||
@ -1846,6 +1846,16 @@ namespace platf {
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string
|
||||
get_host_name() {
|
||||
WCHAR hostname[256];
|
||||
if (GetHostNameW(hostname, ARRAYSIZE(hostname)) == SOCKET_ERROR) {
|
||||
BOOST_LOG(error) << "GetHostNameW() failed: "sv << WSAGetLastError();
|
||||
return "Sunshine"s;
|
||||
}
|
||||
return to_utf8(hostname);
|
||||
}
|
||||
|
||||
class win32_high_precision_timer: public high_precision_timer {
|
||||
public:
|
||||
win32_high_precision_timer() {
|
||||
|
||||
@ -9,8 +9,6 @@
|
||||
#include <windns.h>
|
||||
#include <winerror.h>
|
||||
|
||||
#include <boost/asio/ip/host_name.hpp>
|
||||
|
||||
#include "misc.h"
|
||||
#include "src/config.h"
|
||||
#include "src/logging.h"
|
||||
@ -108,7 +106,7 @@ namespace platf::publish {
|
||||
|
||||
std::wstring domain { SERVICE_TYPE_DOMAIN.data(), SERVICE_TYPE_DOMAIN.size() };
|
||||
|
||||
auto hostname = boost::asio::ip::host_name();
|
||||
auto hostname = platf::get_host_name();
|
||||
auto name = from_utf8(net::mdns_instance_name(hostname) + '.') + domain;
|
||||
auto host = from_utf8(hostname + ".local");
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
*/
|
||||
#include <src/platform/common.h>
|
||||
|
||||
#include <boost/asio/ip/host_name.hpp>
|
||||
|
||||
#include "../../tests_common.h"
|
||||
|
||||
struct SetEnvTest: ::testing::TestWithParam<std::tuple<std::string, std::string, int>> {
|
||||
@ -47,3 +49,8 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
std::make_tuple("SUNSHINE_UNIT_TEST_ENV_VAR", "test_value_0", 0),
|
||||
std::make_tuple("SUNSHINE_UNIT_TEST_ENV_VAR", "test_value_1", 0),
|
||||
std::make_tuple("", "test_value", -1)));
|
||||
|
||||
TEST(HostnameTests, TestAsioEquality) {
|
||||
// These should be equivalent on all platforms for ASCII hostnames
|
||||
ASSERT_EQ(platf::get_host_name(), boost::asio::ip::host_name());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user