mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
IOS/Network/Net: Use a mapper function instead of a static array for SOCKOPT mapping.
Some platforms (e.g. Haiku) define SOL_SOCKET to be -1, which obviously does not work with static arrays. Plus, this is cleaner.
This commit is contained in:
@ -119,12 +119,34 @@ static int inet_pton(const char* src, unsigned char* dst)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maps SOCKOPT level from native to Wii
|
// Maps SOCKOPT level from Wii to native
|
||||||
static unsigned int opt_level_mapping[][2] = {{SOL_SOCKET, 0xFFFF}};
|
static s32 MapWiiSockOptLevelToNative(u32 level)
|
||||||
|
{
|
||||||
|
if (level == 0xFFFF)
|
||||||
|
return SOL_SOCKET;
|
||||||
|
|
||||||
|
INFO_LOG(IOS_NET, "SO_SETSOCKOPT: unknown level %u", level);
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
// Maps SOCKOPT optname from native to Wii
|
// Maps SOCKOPT optname from native to Wii
|
||||||
static unsigned int opt_name_mapping[][2] = {
|
static s32 MapWiiSockOptNameToNative(u32 optname)
|
||||||
{SO_REUSEADDR, 0x4}, {SO_SNDBUF, 0x1001}, {SO_RCVBUF, 0x1002}, {SO_ERROR, 0x1009}};
|
{
|
||||||
|
switch (optname)
|
||||||
|
{
|
||||||
|
case 0x4:
|
||||||
|
return SO_REUSEADDR;
|
||||||
|
case 0x1001:
|
||||||
|
return SO_SNDBUF;
|
||||||
|
case 0x1002:
|
||||||
|
return SO_RCVBUF;
|
||||||
|
case 0x1009:
|
||||||
|
return SO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
INFO_LOG(IOS_NET, "SO_SETSOCKOPT: unknown optname %u", optname);
|
||||||
|
return optname;
|
||||||
|
}
|
||||||
|
|
||||||
IPCCommandResult NetIPTop::IOCtl(const IOCtlRequest& request)
|
IPCCommandResult NetIPTop::IOCtl(const IOCtlRequest& request)
|
||||||
{
|
{
|
||||||
@ -216,15 +238,8 @@ IPCCommandResult NetIPTop::IOCtl(const IOCtlRequest& request)
|
|||||||
request.Log(GetDeviceName(), LogTypes::IOS_WC24);
|
request.Log(GetDeviceName(), LogTypes::IOS_WC24);
|
||||||
|
|
||||||
// Do the level/optname translation
|
// Do the level/optname translation
|
||||||
int nat_level = -1, nat_optname = -1;
|
int nat_level = MapWiiSockOptLevelToNative(level);
|
||||||
|
int nat_optname = MapWiiSockOptNameToNative(optname);
|
||||||
for (auto& map : opt_level_mapping)
|
|
||||||
if (level == map[1])
|
|
||||||
nat_level = map[0];
|
|
||||||
|
|
||||||
for (auto& map : opt_name_mapping)
|
|
||||||
if (optname == map[1])
|
|
||||||
nat_optname = map[0];
|
|
||||||
|
|
||||||
u8 optval[20];
|
u8 optval[20];
|
||||||
u32 optlen = 4;
|
u32 optlen = 4;
|
||||||
@ -274,24 +289,8 @@ IPCCommandResult NetIPTop::IOCtl(const IOCtlRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do the level/optname translation
|
// Do the level/optname translation
|
||||||
int nat_level = -1, nat_optname = -1;
|
int nat_level = MapWiiSockOptLevelToNative(level);
|
||||||
|
int nat_optname = MapWiiSockOptNameToNative(optname);
|
||||||
for (auto& map : opt_level_mapping)
|
|
||||||
if (level == map[1])
|
|
||||||
nat_level = map[0];
|
|
||||||
|
|
||||||
for (auto& map : opt_name_mapping)
|
|
||||||
if (optname == map[1])
|
|
||||||
nat_optname = map[0];
|
|
||||||
|
|
||||||
if (nat_level == -1 || nat_optname == -1)
|
|
||||||
{
|
|
||||||
INFO_LOG(IOS_NET, "SO_SETSOCKOPT: unknown level %d or optname %d", level, optname);
|
|
||||||
|
|
||||||
// Default to the given level/optname. They match on Windows...
|
|
||||||
nat_level = level;
|
|
||||||
nat_optname = optname;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = setsockopt(fd, nat_level, nat_optname, (char*)optval, optlen);
|
int ret = setsockopt(fd, nat_level, nat_optname, (char*)optval, optlen);
|
||||||
return_value = WiiSockMan::GetNetErrorCode(ret, "SO_SETSOCKOPT", false);
|
return_value = WiiSockMan::GetNetErrorCode(ret, "SO_SETSOCKOPT", false);
|
||||||
|
Reference in New Issue
Block a user