feat(network): allow binding to specific interface (#4481)
This commit is contained in:
parent
1fa7457eab
commit
0aa7e3fd67
13 changed files with 205 additions and 9 deletions
|
|
@ -105,7 +105,7 @@ namespace net {
|
|||
return BOTH;
|
||||
}
|
||||
|
||||
std::string_view af_to_any_address_string(af_e af) {
|
||||
std::string_view af_to_any_address_string(const af_e af) {
|
||||
switch (af) {
|
||||
case IPV4:
|
||||
return "0.0.0.0"sv;
|
||||
|
|
@ -117,6 +117,16 @@ namespace net {
|
|||
return "::"sv;
|
||||
}
|
||||
|
||||
std::string get_bind_address(const af_e af) {
|
||||
// If bind_address is configured, use it
|
||||
if (!config::sunshine.bind_address.empty()) {
|
||||
return config::sunshine.bind_address;
|
||||
}
|
||||
|
||||
// Otherwise use the wildcard address for the given address family
|
||||
return std::string(af_to_any_address_string(af));
|
||||
}
|
||||
|
||||
boost::asio::ip::address normalize_address(boost::asio::ip::address address) {
|
||||
// Convert IPv6-mapped IPv4 addresses into regular IPv4 addresses
|
||||
if (address.is_v6()) {
|
||||
|
|
@ -159,8 +169,8 @@ namespace net {
|
|||
enet_initialize();
|
||||
});
|
||||
|
||||
auto any_addr = net::af_to_any_address_string(af);
|
||||
enet_address_set_host(&addr, any_addr.data());
|
||||
const auto bind_addr = net::get_bind_address(af);
|
||||
enet_address_set_host(&addr, bind_addr.c_str());
|
||||
enet_address_set_port(&addr, port);
|
||||
|
||||
// Maximum of 128 clients, which should be enough for anyone
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue