Why doesn't GetNameInfo win32 api resolve Chinese computer names on Windows 11?

Arif Waqas 0 Reputation points
2024-10-01T07:31:51.6766667+00:00

0

I have a small lab based Active Directory environment with 3 devices. They have the following OS installed.

DC running Windows Server 2022 hosting my AD server. 1.Endpoint running Windows 10 Pro (22H2 Build 19045.4780) [English US installation and default computer name is "Endpoint1"] 2.Endpoint running Windows 11 Pro (23H2 Build 22631.2861) [English US installation and default computer name is "Endpoint2"] 3.Endpoint running Windows 10 (22H2 Build 19045.4780) [Chinese-Traditional installed and dfault and computer name is "通用的用户"]

Both the devices are connected to the Active Directory server hosted on the DC.

I have confirmed that the reverse lookup zones are properly set in the DNS Manager on the DC and they have proper entries .

I have a following test code that uses the GetNameInfoW windows API from winsock. I am trying to perform a reverse DNS lookup for XYZ reasons from each of the endpoints to see if the other endpoint is accessible and resolves to the correct name.

I am running the below code on both the endpoints, as well as a 3rd endpoint (completely for testing) and i am able to see the resolution result correctly for 1 but not for 2.

Outputs [Endpoint1.ITDR.local]: C:\Users\Administrator\Desktop>reverse_dns

hostname: 通用的用户.ITDR.local

Outputs [Endpoint2.ITDR.local]: C:\Users\Administrator\Desktop>reverse_dns

hostname: Error in getnameinfo: 11001

In both the endpoints above I Expect the SAME output. because the DNS Server is the same entity for both the endpoints.

I tried adding multiple fake reverse lookups with different values for english and chinese characters, weirdly for windows 10 all of them returned the expected responses while for windows 11, the non-english reverselookups all failed, while the english ones passed.

This is not a language pack issue, because nslookup is able to get the expected outputs and i have the chinese-t language packs installed on all the 3 endpoints.

Is this a microsoft bug?? Or am I doing something wrong ??

TLDR : GetNameInfo expected output is 通用的用户.ITDR.local which works fine in windows 10 machines but returns error 11001 on Windows 11 machines. Both machines are fully updated.

void func() {
    struct sockaddr_in sa;
    char str[INET_ADDRSTRLEN];
    wchar_t host[NI_MAXHOST];

    memset(&sa, 0, sizeof(sa));
    sa.sin_family = AF_INET;
    sa.sin_port = htons(80);

    if (inet_pton(AF_INET, "CORRECT_IP_HERE", &sa.sin_addr) <= 0) {
        std::cerr << "Error in inet_pton" << std::endl;
        exit(EXIT_FAILURE);
    }

    if (GetNameInfoW((struct sockaddr*)&sa, sizeof(sa), host, NI_MAXHOST, NULL, 0, NI_NAMEREQD) == 0) {
        std::wcout << "hostname: " << host << std::endl;
    }
    else {
        std::cerr << "Error in getnameinfo: " << WSAGetLastError() << std::endl;
    }

    std::wstring wstr{ host };
    int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
    std::string strTo(size_needed, 0);
    WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
    cout << strTo << endl;
}

int main()
{

    WSADATA wsaData;
    auto ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
    func();
    WSACleanup();
    return 0;
}
																								

Output of the code running on different configs are as follows:

Windows 11 Ver: 23H2 Build 22631.2861 ->

C:\Users\winauto\Desktop>reverse_dns.exe

Error in getnameinfo: 11001


Windows 10 Endpoint Ver: 22H2 Build 19045.4780 ->

C:\Users\Administrator\Desktop>reverse_dns

hostname: 通用的用户.ITDR.local Same result is expected as all settings across the board are same.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,617 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,729 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
9,634 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.