SOC: Fix setting TTL to default value when TTL = 0 (#6835)

This commit is contained in:
PabloMK7 2023-08-02 22:06:51 +02:00 committed by GitHub
parent b1b6f08926
commit 5b9f4d4129
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -301,7 +301,7 @@ std::pair<int, int> SOC_U::TranslateSockOpt(int level, int opt) {
return std::make_pair(SOL_SOCKET, opt);
}
static void TranslateSockOptDataToPlatform(std::vector<u8>& out, const std::vector<u8>& in,
void SOC_U::TranslateSockOptDataToPlatform(std::vector<u8>& out, const std::vector<u8>& in,
int platform_level, int platform_opt) {
// linger structure may be different between 3DS and platform
if (platform_level == SOL_SOCKET && platform_opt == SO_LINGER &&
@ -331,6 +331,10 @@ static void TranslateSockOptDataToPlatform(std::vector<u8>& out, const std::vect
out = in;
return;
}
// Setting TTL to 0 means resetting it to the default value.
if (platform_level == IPPROTO_IP && platform_opt == IP_TTL && value == 0) {
value = SOC_TTL_DEFAULT;
}
out.resize(sizeof(int));
std::memcpy(out.data(), &value, sizeof(int));
}

View file

@ -61,8 +61,12 @@ private:
static constexpr u32 SOC_SOL_CONFIG = 0xFFFE;
static constexpr u32 SOC_SOL_SOCKET = 0xFFFF;
static constexpr int SOC_TTL_DEFAULT = 64;
static const std::unordered_map<u64, std::pair<int, int>> sockopt_map;
static std::pair<int, int> TranslateSockOpt(int level, int opt);
static void TranslateSockOptDataToPlatform(std::vector<u8>& out, const std::vector<u8>& in,
int platform_level, int platform_opt);
bool GetSocketBlocking(const SocketHolder& socket_holder);
u32 SetSocketBlocking(SocketHolder& socket_holder, bool blocking);