Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9101 from sepalani/fix-ip-fallback
IP/Top: Fix fallback IP address
  • Loading branch information
leoetlino committed Nov 27, 2020
2 parents 2a85534 + 79f50cd commit 9b03cdf
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Source/Core/Core/IOS/Network/IP/Top.cpp
Expand Up @@ -79,11 +79,6 @@ void NetIPTop::DoState(PointerWrap& p)
WiiSockMan::GetInstance().DoState(p);
}

static constexpr u32 inet_addr(u8 a, u8 b, u8 c, u8 d)
{
return (static_cast<u32>(a) << 24) | (static_cast<u32>(b) << 16) | (static_cast<u32>(c) << 8) | d;
}

static int inet_pton(const char* src, unsigned char* dst)
{
int saw_digit = 0;
Expand Down Expand Up @@ -165,11 +160,12 @@ static s32 MapWiiSockOptNameToNative(u32 optname)
return optname;
}

// u32 values are in little endian (i.e. 0x0100007f means 127.0.0.1)
struct DefaultInterface
{
u32 inet; ///< IPv4 address
u32 netmask; ///< IPv4 subnet mask
u32 broadcast; ///< IPv4 broadcast address
u32 inet; // IPv4 address
u32 netmask; // IPv4 subnet mask
u32 broadcast; // IPv4 broadcast address
};

static std::optional<DefaultInterface> GetSystemDefaultInterface()
Expand Down Expand Up @@ -233,7 +229,7 @@ static std::optional<DefaultInterface> GetSystemDefaultInterface()
addr.sin_family = AF_INET;
// The address and port are irrelevant -- no packet is actually sent. These just need to be set
// to a valid IP and port.
addr.sin_addr.s_addr = inet_addr(8, 8, 8, 8);
addr.sin_addr.s_addr = inet_addr("8.8.8.8");
addr.sin_port = htons(53);
if (connect(sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) == -1)
return {};
Expand Down Expand Up @@ -270,8 +266,10 @@ static std::optional<DefaultInterface> GetSystemDefaultInterface()

static DefaultInterface GetSystemDefaultInterfaceOrFallback()
{
static constexpr DefaultInterface FALLBACK_VALUES{
inet_addr(10, 0, 1, 30), inet_addr(255, 255, 255, 0), inet_addr(10, 0, 255, 255)};
static const u32 FALLBACK_IP = inet_addr("10.0.1.30");
static const u32 FALLBACK_NETMASK = inet_addr("255.255.255.0");
static const u32 FALLBACK_GATEWAY = inet_addr("10.0.255.255");
static const DefaultInterface FALLBACK_VALUES{FALLBACK_IP, FALLBACK_NETMASK, FALLBACK_GATEWAY};
return GetSystemDefaultInterface().value_or(FALLBACK_VALUES);
}

Expand Down

0 comments on commit 9b03cdf

Please sign in to comment.