From 97203568e7d5540ae2cefffed0881be4966c2d05 Mon Sep 17 00:00:00 2001 From: hiura Date: Sun, 31 Mar 2024 23:07:16 +0900 Subject: [PATCH] Fix 'RemoveDefGwOnDhcpForLocalhost' function: Change to exclude unplugged device from MAC address list. --- src/Mayaqua/Microsoft.c | 1 + src/Mayaqua/Microsoft.h | 1 + src/Mayaqua/Network.c | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/src/Mayaqua/Microsoft.c b/src/Mayaqua/Microsoft.c index 5f9e015e9..4579b3010 100644 --- a/src/Mayaqua/Microsoft.c +++ b/src/Mayaqua/Microsoft.c @@ -2568,6 +2568,7 @@ MS_ADAPTER_LIST *MsCreateAdapterListInnerExVista(bool no_info) UniStrCpy(a->TitleW, sizeof(a->TitleW), title); UniToStr(a->Title, sizeof(a->Title), title); a->Index = r->InterfaceIndex; + a->MediaConnectState = r->MediaConnectState; a->Type = r->Type; a->Status = ConvertMidStatusVistaToXp(r->OperStatus); a->Mtu = r->Mtu; diff --git a/src/Mayaqua/Microsoft.h b/src/Mayaqua/Microsoft.h index c0d6a5ab7..0044bbda0 100644 --- a/src/Mayaqua/Microsoft.h +++ b/src/Mayaqua/Microsoft.h @@ -281,6 +281,7 @@ typedef struct MS_ADAPTER char Title[MAX_PATH]; // Display name wchar_t TitleW[MAX_PATH]; // Display Name (Unicode) UINT Index; // Index + UINT MediaConnectState; // Media Connect State UINT Type; // Type UINT Status; // Status UINT Mtu; // MTU diff --git a/src/Mayaqua/Network.c b/src/Mayaqua/Network.c index 465ae836d..c9ea75957 100644 --- a/src/Mayaqua/Network.c +++ b/src/Mayaqua/Network.c @@ -540,6 +540,13 @@ LIST *Win32GetNicList() if (a->Type == 6 && a->AddressSize == 6) { + // If the connection state of the interface is unknown, then exclude it. + // Unknown means that the device is not plugged into the local host. + if (a->MediaConnectState == MediaConnectStateUnknown) + { + continue; + } + NIC_ENTRY *e = ZeroMalloc(sizeof(NIC_ENTRY)); StrCpy(e->IfName, sizeof(e->IfName), a->Title);