core/socket_proxy: Correct broadcast behavior

Broadcasts should only be sent when the broadcast IP is used.
They should also only be received when SO_BROADCAST is enabled.
This commit is contained in:
FearlessTobi 2022-08-27 03:39:02 +02:00
parent 839e1faf49
commit 339758c9fc

View File

@ -26,6 +26,12 @@ void ProxySocket::HandleProxyPacket(const ProxyPacket& packet) {
closed) { closed) {
return; return;
} }
if (!broadcast && packet.broadcast) {
LOG_INFO(Network, "Received broadcast packet, but not configured for broadcast mode");
return;
}
std::lock_guard guard(packets_mutex); std::lock_guard guard(packets_mutex);
received_packets.push(packet); received_packets.push(packet);
} }
@ -203,7 +209,7 @@ std::pair<s32, Errno> ProxySocket::SendTo(u32 flags, const std::vector<u8>& mess
packet.local_endpoint = local_endpoint; packet.local_endpoint = local_endpoint;
packet.remote_endpoint = *addr; packet.remote_endpoint = *addr;
packet.protocol = protocol; packet.protocol = protocol;
packet.broadcast = broadcast; packet.broadcast = broadcast && packet.remote_endpoint.ip[3] == 255;
auto& ip = local_endpoint.ip; auto& ip = local_endpoint.ip;
auto ipv4 = Network::GetHostIPv4Address(); auto ipv4 = Network::GetHostIPv4Address();