简体   繁体   中英

gethostbyname says No such service is known. The service cannot be found in the specified name space

This simple piece of code in Windows results in an annoying debug message printed by gethostbyname .

#include <stdio.h>
#include <winsock.h>
int main()
{
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2, 2), &wsaData);
    hostent* he = gethostbyname("www.stackoverflow.com");
    char* ip = inet_ntoa(*(struct in_addr*)he->h_addr_list[0]);
    printf(ip);
}

it says:

onecore\net\netprofiles\service\src\nsp\dll\namespaceserviceprovider.cpp(550)\nlansp_c.dll!00007FFCFC1FC759: (caller: 00007FFD2856388E) LogHr(1) tid(6e14) 8007277C No such service is known. The service cannot be found in the specified name space.

I'm on Windows. using visual studio 2019. How can I omit that? Currently, I'm debugging and because my log is filled completely with this message, it's hard to find desired logs.

The behaviour you're seeing seems to be due to Layered Service Providers being deprecated as of Win11 (and potentially an upcoming Win10 update).

GetHostByName is listed as deprecated, but GetHostName is not and also displays the same behaviour. In both cases the method queries any available namespace service providers first and then falls back to querying the NetBIOS name if none are found. As of Win11 it seems the call to enumerate the namespace service providers fails internally, generating the debug output you see.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM