Defaults to 127.0.0.1 when failing to discover IP
This commit is contained in:
+18
-17
@@ -52,12 +52,7 @@ np_handler::np_handler()
|
|||||||
|
|
||||||
if (get_net_status() == CELL_NET_CTL_STATE_IPObtained)
|
if (get_net_status() == CELL_NET_CTL_STATE_IPObtained)
|
||||||
{
|
{
|
||||||
if (!discover_ip_address())
|
discover_ip_address();
|
||||||
{
|
|
||||||
nph_log.error("Failed to discover local IP!");
|
|
||||||
is_connected = false;
|
|
||||||
is_psn_active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!discover_ether_address())
|
if (!discover_ether_address())
|
||||||
{
|
{
|
||||||
@@ -103,30 +98,38 @@ np_handler::np_handler()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool np_handler::discover_ip_address()
|
void np_handler::discover_ip_address()
|
||||||
{
|
{
|
||||||
hostname.clear();
|
hostname.clear();
|
||||||
hostname.resize(1024);
|
hostname.resize(1024);
|
||||||
|
|
||||||
|
const auto use_default_ip_addr = [this](const std::string_view error_msg)
|
||||||
|
{
|
||||||
|
nph_log.error("discover_ip_address: %s", error_msg);
|
||||||
|
nph_log.error("discover_ip_address: Defaulting to 127.0.0.1!");
|
||||||
|
local_ip_addr = 0x0100007f;
|
||||||
|
public_ip_addr = local_ip_addr;
|
||||||
|
};
|
||||||
|
|
||||||
if (gethostname(hostname.data(), hostname.size()) == -1)
|
if (gethostname(hostname.data(), hostname.size()) == -1)
|
||||||
{
|
{
|
||||||
nph_log.error("gethostname failed in IP discovery!");
|
use_default_ip_addr("gethostname failed!");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nph_log.notice("Hostname was determined to be %s", hostname.c_str());
|
nph_log.notice("discover_ip_address: Hostname was determined to be %s", hostname.c_str());
|
||||||
|
|
||||||
hostent* host = gethostbyname(hostname.data());
|
hostent* host = gethostbyname(hostname.data());
|
||||||
if (!host)
|
if (!host)
|
||||||
{
|
{
|
||||||
nph_log.error("gethostbyname failed in IP discovery!");
|
use_default_ip_addr("gethostbyname failed!");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host->h_addrtype != AF_INET)
|
if (host->h_addrtype != AF_INET)
|
||||||
{
|
{
|
||||||
nph_log.error("Could only find IPv6 addresses for current host!");
|
use_default_ip_addr("Could only find IPv6 addresses for current host!");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First address is used for now, (TODO combobox with possible local addresses to use?)
|
// First address is used for now, (TODO combobox with possible local addresses to use?)
|
||||||
@@ -135,9 +138,7 @@ bool np_handler::discover_ip_address()
|
|||||||
// Set public address to local discovered address for now, may be updated later;
|
// Set public address to local discovered address for now, may be updated later;
|
||||||
public_ip_addr = local_ip_addr;
|
public_ip_addr = local_ip_addr;
|
||||||
|
|
||||||
nph_log.notice("IP was determined to be %s", ip_to_string(local_ip_addr));
|
nph_log.notice("discover_ip_address: IP was determined to be %s", ip_to_string(local_ip_addr));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool np_handler::discover_ether_address()
|
bool np_handler::discover_ether_address()
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Various generic helpers
|
// Various generic helpers
|
||||||
bool discover_ip_address();
|
void discover_ip_address();
|
||||||
bool discover_ether_address();
|
bool discover_ether_address();
|
||||||
bool error_and_disconnect(const std::string& error_msg);
|
bool error_and_disconnect(const std::string& error_msg);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user