Reputation: 7891
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.
Upvotes: 13
Views: 10718
Reputation: 4220
A workaround for using gethostname
is to use the Win32 API equivalent GetComputerNameEx
with the ComputerNameDnsHostname
flag.
For gethostbyname
, perhaps you could do a similar thing with WSAAsyncGetHostByName
I presume at some point it'll be fixed in Windows, but 2 years after this question was raised, it's still there. This is the easiest workaround I could find to avoid the messages.
Upvotes: 0
Reputation: 31393
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.
Upvotes: 9