8

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.

J...
  • 30,968
  • 6
  • 66
  • 143
s4eed
  • 7,173
  • 9
  • 67
  • 104
  • I know I can filter logs :) – s4eed Jan 13 '22 at 09:48
  • @user438383 c++ – s4eed Jan 13 '22 at 09:48
  • From the [manual](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-gethostbyname): *Otherwise, it returns a null pointer and a specific error number can be retrieved by calling WSAGetLastError.* You should check for errors instead of just accessing the pointer. – Gerhardh Jan 13 '22 at 09:51
  • @Gerhardh It doesn't have any error. gethostbyname prints that log. not using the result. – s4eed Jan 13 '22 at 09:52
  • gethostbyname is deprecated. Try using getaddrinfo instead. – n. m. could be an AI Jan 13 '22 at 10:02
  • Anything `gethostbyname()` does internally is outside of your control. You can't stop it from logging internal messages, if that is what it wants to do. Lots of system functions have various levels of internal logging. – Remy Lebeau Jan 13 '22 at 10:08
  • @RemyLebeau I thought I set something wrong. – s4eed Jan 13 '22 at 10:40
  • Are you using Windows 11, by chance? – J... Jan 24 '22 at 17:12
  • @J... yep i am ! – s4eed Jan 25 '22 at 15:35
  • @s4eed Thanks. I don't have a solution for you, but I've also noticed similar pollution in the debug output in a large project recently test built in Win11 - a suite of COM errors like this one, mostly related to WinAPI calls into AD/LDAP as welll as to the namespace service provider (as you've shown here). The project is built in Delphi, but has about two decades worth of dependencies and something down there is generating hundreds of these debug output errors on launch. Oddly, we see nothing broken in the app itself but I haven't tracked down the cause. Something changed in Win11... – J... Jan 25 '22 at 17:43
  • @J... Exactly like me. I didn't have this log in Windows 10 but I do in Windows 11. In comments, someone said it's deprecated. – s4eed Jan 25 '22 at 19:57
  • I get similar debug output when calling [`ADsGetObject`](https://learn.microsoft.com/en-us/windows/win32/api/adshlp/nf-adshlp-adsgetobject) and that is not deprecated... – J... Feb 03 '22 at 18:01

1 Answers1

7

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.

J...
  • 30,968
  • 6
  • 66
  • 143