bdbai 2 лет назад
Родитель
Сommit
c09075a048

+ 21 - 3
Maple.App/MainPage.xaml

@@ -63,7 +63,8 @@
             Grid.ColumnSpan="3"
             DisplayMode="Overlay"
             PaneClosing="MainSplitView_PaneClosing"
-            Background="White">
+            Background="White"
+            OpenPaneLength="330">
             <SplitView.Pane>
                 <Pivot x:Name="MainPivot" PivotItemLoaded="MainPivot_PivotItemLoaded">
                     <PivotItem Header="Config" Margin="0">
@@ -188,9 +189,26 @@
                                     x:Name="NetifCombobox"
                                     HorizontalAlignment="Stretch"
                                     Margin="0, 8"
-                                    DisplayMemberPath="Desc"
                                     SelectedValuePath="Addr"
-                                    SelectionChanged="NetifCombobox_SelectionChanged"/>
+                                    SelectionChanged="NetifCombobox_SelectionChanged">
+                                    <ComboBox.ItemTemplate>
+                                        <DataTemplate x:DataType="maple_app:Netif">
+                                            <StackPanel x:Name="NetifComboboxTemplateRoot">
+                                                <TextBlock Text="{x:Bind Desc}" FontWeight="Bold" />
+                                                <TextBlock
+                                                    Text="{x:Bind IpLines}"
+                                                    Visibility="{Binding IsDropDownOpen, ElementName=NetifCombobox}" />
+                                                <TextBlock
+                                                    Text="{x:Bind IpSummary}"
+                                                    Visibility="{Binding
+                                                        IsDropDownOpen,
+                                                        ElementName=NetifCombobox,
+                                                        Converter={StaticResource BoolToVisibilityConverter},
+                                                        ConverterParameter=true}" />
+                                            </StackPanel>
+                                        </DataTemplate>
+                                    </ComboBox.ItemTemplate>
+                                </ComboBox>
 
                                 <TextBlock Margin="0, 18" Text="VPN Connection" Style="{ThemeResource TitleTextBlockStyle}"/>
                                 <TextBlock Margin="0, 0, 0, 18" TextWrapping="WrapWholeWords">

+ 1 - 1
Maple.App/Maple.App.vcxproj

@@ -15,7 +15,7 @@
     <AppContainerApplication>true</AppContainerApplication>
     <ApplicationType>Windows Store</ApplicationType>
     <ApplicationTypeRevision>10.0</ApplicationTypeRevision>
-    <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.22000.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.22621.0</WindowsTargetPlatformVersion>
     <WindowsTargetPlatformMinVersion>10.0.17763.0</WindowsTargetPlatformMinVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

+ 3 - 1
Maple.App/Maple.App.vcxproj.filters

@@ -196,7 +196,6 @@
     </CopyFileToFolders>
   </ItemGroup>
   <ItemGroup>
-    <Midl Include="Model\Netif.idl" />
     <Midl Include="Model\ConfigViewModel.idl">
       <Filter>Model</Filter>
     </Midl>
@@ -206,6 +205,9 @@
     <Midl Include="Converter\BoolToVisibilityConverter.idl">
       <Filter>Converter</Filter>
     </Midl>
+    <Midl Include="Model\Netif.idl">
+      <Filter>Model</Filter>
+    </Midl>
   </ItemGroup>
   <ItemGroup>
     <None Include="PropertySheet.props" />

+ 80 - 14
Maple.App/Model/Netif.cpp

@@ -15,9 +15,33 @@ constexpr auto MAX_TRIES = 3;
 
 namespace winrt::Maple_App::implementation
 {
-    Netif::Netif(const hstring& desc, const hstring& Addr)
-        : m_desc(desc), m_addr(Addr)
+    Netif::Netif(const hstring& desc, addresses_t addresses)
+        : m_desc(desc), m_addresses(std::move(addresses))
     {
+        for (auto const& [af, a] : m_addresses)
+        {
+            if (af != AF_INET)
+            {
+                continue;
+            }
+            if (!m_addr.empty())
+            {
+                m_addr = m_addr + L",";
+            }
+            m_addr = m_addr + a;
+        }
+        for (auto const& [af, a] : m_addresses)
+        {
+            if (af != AF_INET6)
+            {
+                continue;
+            }
+            if (!m_addr.empty())
+            {
+                m_addr = m_addr + L",";
+            }
+            m_addr = m_addr + a;
+        }
     }
     hstring Netif::Desc()
     {
@@ -29,6 +53,39 @@ namespace winrt::Maple_App::implementation
         return m_addr;
     }
 
+    hstring Netif::IpSummary()
+    {
+        // auto const parent = VisualTreeHelper::GetParent(templateRoot);
+        int cnt4 = 0, cnt6 = 0;
+        for (auto const& [af, _] : m_addresses)
+        {
+            switch (af)
+            {
+            case AF_INET: cnt4++; break;
+            case AF_INET6: cnt6++; break;
+            default: break;
+            }
+        }
+        return to_hstring(cnt4) + L" IPv4 address" + (cnt4 > 1 ? L"es" : L"") + L"; "
+            + to_hstring(cnt6) + L" IPv6 address" + (cnt6 > 1 ? L"es" : L"");
+    }
+    hstring Netif::IpLines()
+    {
+        hstring ret;
+        for (auto const& [_, addr] : m_addresses)
+        {
+            if (ret.empty())
+            {
+                ret = ret + addr;
+            }
+            else
+            {
+                ret = ret + L"\r\n" + addr;
+            }
+        }
+        return ret;
+    }
+
     std::vector<Maple_App::Netif> Netif::EnumerateInterfaces() {
 
         /* Declare and initialize variables */
@@ -45,7 +102,7 @@ namespace winrt::Maple_App::implementation
             | GAA_FLAG_SKIP_FRIENDLY_NAME;
 
         // default to unspecified address family (both)
-        ULONG family = AF_INET;
+        ULONG family = AF_UNSPEC;
 
 
         PIP_ADAPTER_ADDRESSES pAddresses = NULL;
@@ -94,34 +151,43 @@ namespace winrt::Maple_App::implementation
         std::vector<Maple_App::Netif> ret;
         pCurrAddresses = pAddresses;
         while (pCurrAddresses) {
-            if (!(pCurrAddresses->Flags & IP_ADAPTER_IPV4_ENABLED)) {
+            if (!(pCurrAddresses->Flags & (IP_ADAPTER_IPV4_ENABLED | IP_ADAPTER_IPV6_ENABLED))) {
                 pCurrAddresses = pCurrAddresses->Next;
                 continue;
             }
-            const auto& friendlyName = to_hstring(pCurrAddresses->FriendlyName);
+            const auto friendlyName = to_hstring(pCurrAddresses->FriendlyName);
+            std::vector<std::pair<ADDRESS_FAMILY, hstring>> addrs;
+            hstring desc = friendlyName;
+            if (friendlyName != L"Maple" && std::make_optional(pCurrAddresses->IfIndex) == sniffed) {
+                desc = L"★" + desc;
+            }
 
             pUnicast = pCurrAddresses->FirstUnicastAddress;
             if (pUnicast != NULL) {
                 for (i = 0; pUnicast != NULL; i++) {
-                    // pUnicast->Address.lpSockaddr->sa_family;
                     auto bufSize = static_cast<DWORD>(addrBuf.size());
-                    if (FAILED(WSAAddressToStringW(pUnicast->Address.lpSockaddr, pUnicast->Address.iSockaddrLength, nullptr, addrBuf.data(), &bufSize))) {
+                    auto af = pUnicast->Address.lpSockaddr->sa_family;
+                    if (af == AF_INET || af == AF_INET6) {
+                        if (FAILED(WSAAddressToStringW(pUnicast->Address.lpSockaddr, pUnicast->Address.iSockaddrLength, nullptr, addrBuf.data(), &bufSize))) {
+                            pUnicast = pUnicast->Next;
+                            continue;
+                        }
+                    }
+                    else
+                    {
                         pUnicast = pUnicast->Next;
                         continue;
                     }
                     if (bufSize > 0) {
                         bufSize--;
                     }
-                    hstring addr(addrBuf.data(), bufSize);
-                    hstring desc{ L"" };
-                    if (friendlyName != L"Maple" && std::make_optional(pCurrAddresses->IfIndex) == sniffed) {
-                        desc = L"★";
-                    }
-                    desc = desc + friendlyName + L" (" + addr + L")";
-                    ret.emplace_back(winrt::make<Netif>(desc, addr));
+                    addrs.emplace_back(std::make_pair(af, hstring(addrBuf.data(), bufSize)));
                     pUnicast = pUnicast->Next;
                 }
             }
+            if (!addrs.empty()) {
+                ret.emplace_back(winrt::make<Netif>(desc, addrs));
+            }
 
             pCurrAddresses = pCurrAddresses->Next;
         }

+ 7 - 1
Maple.App/Model/Netif.h

@@ -6,11 +6,16 @@ namespace winrt::Maple_App::implementation
 {
     struct Netif : NetifT<Netif>
     {
+        using addresses_t = std::vector<std::pair<unsigned short, hstring>>;
+
         Netif() = default;
-        Netif(const hstring& desc, const hstring& Addr);
+        Netif(const hstring& desc, addresses_t addresses);
 
         hstring Desc();
         hstring Addr();
+        addresses_t& Addresses();
+        hstring IpSummary();
+        hstring IpLines();
 
         static std::vector<Maple_App::Netif> EnumerateInterfaces();
         static std::optional<DWORD> SniffBestInterface();
@@ -18,6 +23,7 @@ namespace winrt::Maple_App::implementation
     private:
         hstring m_desc;
         hstring m_addr;
+        addresses_t m_addresses;
     };
 }
 

+ 2 - 0
Maple.App/Model/Netif.idl

@@ -7,5 +7,7 @@ namespace Maple_App
         Netif();
         String Desc{ get; };
         String Addr{ get; };
+        String IpSummary{ get; };
+        String IpLines{ get; };
     }
 }

+ 1 - 1
Maple.Task/Maple.Task.vcxproj

@@ -14,7 +14,7 @@
     <AppContainerApplication>true</AppContainerApplication>
     <ApplicationType>Windows Store</ApplicationType>
     <ApplicationTypeRevision>10.0</ApplicationTypeRevision>
-    <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.22000.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.22621.0</WindowsTargetPlatformVersion>
     <WindowsTargetPlatformMinVersion>10.0.10240.0</WindowsTargetPlatformMinVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

+ 1 - 0
Maple.Task/VpnPlugin.cpp

@@ -107,6 +107,7 @@ namespace winrt::Maple_Task::implementation
             || !SetEnvironmentVariable(L"LOG_NO_COLOR", L"true")
             || !SetEnvironmentVariable(L"OUTBOUND_INTERFACE", outNetif.data())
             || !SetEnvironmentVariable(L"CACHE_LOCATION", cacheDir.data())
+            || !SetEnvironmentVariable(L"ENABLE_IPV6", L"true")
             ) {
             channel.TerminateConnection(L"Failed to set environment variables: " + winrt::to_hstring((uint32_t)GetLastError()));
             return;