netenv: add redirectBroadcast configuration option to control UDP broadcast redirection

This commit is contained in:
グローランプ
2026-04-13 00:18:32 +10:00
parent f4841280e7
commit d0d470c679
4 changed files with 20 additions and 0 deletions
+5
View File
@@ -182,6 +182,11 @@ void netenv_config_load(struct netenv_config *cfg, const wchar_t *filename)
memset(cfg, 0, sizeof(*cfg));
cfg->enable = GetPrivateProfileIntW(L"netenv", L"enable", 0, filename);
cfg->redirect_broadcast = GetPrivateProfileIntW(
L"netenv",
L"redirectBroadcast",
1,
filename);
cfg->addr_suffix = GetPrivateProfileIntW(
L"netenv",
+6
View File
@@ -165,6 +165,7 @@ static uint32_t netenv_ip_bcast;
static uint32_t netenv_ip_iface;
static uint32_t netenv_ip_router;
static uint8_t netenv_mac_addr[6];
static bool netenv_redirect_broadcast;
static uint32_t netenv_last_logged_broadcast_src;
static uint32_t netenv_last_logged_broadcast_dest;
static bool netenv_broadcast_logged;
@@ -191,6 +192,7 @@ HRESULT netenv_hook_init(
netenv_ip_iface = kc_cfg->subnet | cfg->addr_suffix;
netenv_ip_router = kc_cfg->subnet | cfg->router_suffix;
memcpy(netenv_mac_addr, cfg->mac_addr, sizeof(netenv_mac_addr));
netenv_redirect_broadcast = cfg->redirect_broadcast;
netenv_hook_apply_hooks(NULL);
@@ -570,6 +572,10 @@ static int WINAPI hook_sendto(
const struct sockaddr_in* original_to = (struct sockaddr_in*)to;
if (!netenv_redirect_broadcast) {
return next_sendto(s, buf, len, flags, to, tolen);
}
uint32_t bc_addr = _byteswap_ulong(netenv_ip_prefix | 0xFF);
if (original_to->sin_addr.S_un.S_addr == bc_addr) {
+1
View File
@@ -9,6 +9,7 @@
struct netenv_config {
bool enable;
bool redirect_broadcast;
uint8_t addr_suffix;
uint8_t router_suffix;
uint8_t mac_addr[6];
+8
View File
@@ -589,6 +589,14 @@ Default: `01:02:03:04:05:06`
The MAC address of the virtualized Ethernet adapter. The exact value shouldn't
ever matter.
### `redirectBroadcast`
Default: `1`
Redirect UDP packets sent to the virtual keychip subnet's broadcast address to
the address configured by `broadcast`. Disable this if you want to preserve the
original subnet-local broadcast destination.
### `broadcast`
Default: `255.255.255.255`