https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1a964b51398a133a4d35d6c06ba4f77c75680f71

commit 1a964b51398a133a4d35d6c06ba4f77c75680f71
Author:     Pierre Schweitzer <[email protected]>
AuthorDate: Sun Nov 25 18:03:34 2018 +0100
Commit:     Pierre Schweitzer <[email protected]>
CommitDate: Sun Nov 25 18:04:13 2018 +0100

    [IPHLPAPI] In GetAdaptersAddresses(), return friendly name if asked for
---
 dll/win32/iphlpapi/address.c | 76 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 5 deletions(-)

diff --git a/dll/win32/iphlpapi/address.c b/dll/win32/iphlpapi/address.c
index ae2ed77f32..be9e147c38 100644
--- a/dll/win32/iphlpapi/address.c
+++ b/dll/win32/iphlpapi/address.c
@@ -346,6 +346,7 @@ GetAdaptersAddresses(
     {
         PIP_ADAPTER_ADDRESSES CurrentAA = (PIP_ADAPTER_ADDRESSES)Ptr;
         ULONG CurrentAASize = 0;
+        ULONG FriendlySize = 0;
 
         if (InterfacesList[i].tei_entity == IF_ENTITY)
         {
@@ -382,8 +383,31 @@ GetAdaptersAddresses(
 
             if (!(Flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
             {
-                /* Just an empty string for now. */
-                FIXME("Should get adapter friendly name.\n");
+                /* Get the friendly name */
+                HKEY ConnectionKey;
+                CHAR KeyName[256];
+
+                snprintf(KeyName, 256,
+                    
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%*s\\Connection",
+                    Entry->if_descrlen, &Entry->if_descr[0]);
+
+                if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_READ, 
&ConnectionKey) == ERROR_SUCCESS)
+                {
+                    DWORD ValueType;
+                    DWORD ValueSize = 0;
+
+                    if (RegQueryValueExW(ConnectionKey, L"Name", NULL, 
&ValueType, NULL, &ValueSize) == ERROR_SUCCESS &&
+                        ValueType == REG_SZ)
+                    {
+                        /* We remove the null char, it will be re-added after 
*/
+                        FriendlySize = ValueSize - sizeof(WCHAR);
+                        CurrentAASize += FriendlySize;
+                    }
+
+                    RegCloseKey(ConnectionKey);
+                }
+
+                /* We always make sure to have enough room for empty string */
                 CurrentAASize += sizeof(WCHAR);
             }
 
@@ -448,9 +472,51 @@ GetAdaptersAddresses(
                 if (!(Flags & GAA_FLAG_SKIP_FRIENDLY_NAME))
                 {
                     CurrentAA->FriendlyName = (PWCHAR)Ptr;
-                    CurrentAA->FriendlyName[0] = L'\0';
-                    /* Next items */
-                    Ptr = (BYTE*)(CurrentAA->FriendlyName + 1);
+
+                    if (FriendlySize != 0)
+                    {
+                        /* Get the friendly name */
+                        HKEY ConnectionKey;
+                        CHAR KeyName[256];
+
+                        snprintf(KeyName, 256,
+                            
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%*s\\Connection",
+                            Entry->if_descrlen, &Entry->if_descr[0]);
+
+                        if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, KeyName, 0, 
KEY_READ, &ConnectionKey) == ERROR_SUCCESS)
+                        {
+                            DWORD ValueType;
+                            DWORD ValueSize = FriendlySize + sizeof(WCHAR);
+
+                            if (RegQueryValueExW(ConnectionKey, L"Name", NULL, 
&ValueType, (LPBYTE)CurrentAA->FriendlyName, &ValueSize) == ERROR_SUCCESS &&
+                                ValueType == REG_SZ && ValueSize == 
FriendlySize + sizeof(WCHAR))
+                            {
+                                /* We're done, next items */
+                                Ptr = (BYTE*)(CurrentAA->FriendlyName + 
(ValueSize / sizeof(WCHAR)));
+                            }
+                            else
+                            {
+                                /* Fail */
+                                ERR("Friendly name changed after probe!\n");
+                                FriendlySize = 0;
+                            }
+
+                            RegCloseKey(ConnectionKey);
+                        }
+                        else
+                        {
+                            /* Fail */
+                            FriendlySize = 0;
+                        }
+                    }
+
+                    /* In case of failure (or no name) */
+                    if (FriendlySize == 0)
+                    {
+                        CurrentAA->FriendlyName[0] = L'\0';
+                        /* Next items */
+                        Ptr = (BYTE*)(CurrentAA->FriendlyName + 1);
+                    }
                 }
 
                 /* The DNS Servers */

Reply via email to