Avoid altering TCP sockets

Co-authored-by: sepalani <sepalani@hotmail.fr>
This commit is contained in:
SMarioMan 2023-03-01 20:52:43 -05:00 committed by GitHub
parent 301e97f7f7
commit 078730c873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 2 deletions

View File

@ -873,8 +873,25 @@ s32 WiiSockMan::AddSocket(s32 fd, bool is_rw)
ERROR_LOG_FMT(IOS_NET, "Failed to set SO_NOSIGPIPE on socket"); ERROR_LOG_FMT(IOS_NET, "Failed to set SO_NOSIGPIPE on socket");
#endif #endif
int opt_broadcast = 1; // Wii UDP sockets can use broadcast address by default
setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char*)&opt_broadcast, sizeof(opt_broadcast)); if (!is_rw)
{
const auto state = Common::SaveNetworkErrorState();
Common::ScopeGuard guard([&state] { Common::RestoreNetworkErrorState(state); });
int socket_type;
socklen_t option_length = sizeof(socket_type);
const bool is_udp = getsockopt(fd, SOL_SOCKET, SO_TYPE, reinterpret_cast<char*>(&socket_type),
&option_length) == 0 &&
socket_type == SOCK_DGRAM;
const int opt_broadcast = 1;
if (is_udp &&
setsockopt(fd, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<const char*>(&opt_broadcast),
sizeof(opt_broadcast)) != 0)
{
ERROR_LOG_FMT(IOS_NET, "Failed to set SO_BROADCAST on socket");
}
}
} }
SetLastNetError(wii_fd); SetLastNetError(wii_fd);