RE: emulation of gethostbyaddr to resolve to NetBIOS name
Hi Paul,
I understand that you would like to know how to get a NetBIOS name from an
IP address by using NetBIOS API.
If I have misunderstood, please let me know.
From my research, you can use NetBIOS API to retrieve host names and MAC
addresses of the network adapters, however to retrieve NetBIOS name from an
IP address, you need to use the WinSock API gethostbyaddr instead of
NetBIOS API. From this article,
http://msdn.microsoft.com/en-us/library/ms738521(VS.85).aspx, we can also
find the following descriptions:
"Developers requiring NetBIOS name resolution may need to use gethostbyaddr
until their applications are completely independent of NetBIOS names."
You can retrieve the Netbios name from an IP address with the following
code:
==============================
unsigned long res;
WSADATA wsaData;
HOSTENT* pHost;
res = inet_addr(ip);
if ((res == INADDR_NONE) || (res == 0)) {
strcpy(host, "unable to resolve");
return false;
}
if (WSAStartup(MAKEWORD(1, 1), &wsaData)) {
strcpy(host, "unable to resolve");
return false;
}
pHost = gethostbyaddr((char*)&res, sizeof(res), AF_NETBIOS);
if (pHost == NULL) {
MessageBox("unable to resolve");
return false;
}
MessageBox(pHost->h_name);
WSACleanup();
=================================
Also I do not recommend that you use NetBios API since Netbios is not
available for use on Windows Vista, Windows Server 2008, and subsequent
versions of the operating system. You can find the clarification in this
article:
Netbios Function
http://msdn.microsoft.com/en-us/library/bb870903(VS.85).aspx
If you want to get Network parameters information, I would recommend that
you use IP Helper functions and Winsock functions such as GetAdaptersInfo
and gethostbyaddr. You may also refer to this article for more information:
Review of the network adapter parameters
http://www.codeproject.com/KB/IP/bsipconfig.aspx
Hope this helps. If you have any other questions or concerns, please feel
free to let me know.
Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@microsoft.com.
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================