Why gethostbyaddr return group name instead of machine name?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Dears,
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Can I get your help about Windows API gethostbyaddr?
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri It seems that there is some issue on API gethostbyaddr.
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Below is the detail.
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri The code in program is below:
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri ---------------------------
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri â
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri struct hostent *hp = gethostbyaddr((const char *)&(dest.sin_addr.s_addr), sizeof(DWORD), AF_INET );
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri printf( âThe official name is:%sâ, hp->h_name );
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri â
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri ---------------------------
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri There are two different output when the response of NBNS is different.
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri First, when the response of NBNS is below, the function gethostbyaddr is OK.
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri â
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri NetBIOS Name Service
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Transaction ID: 0x803c
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Flags: 0x8400 (Name query response, No error)
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Questions: 0
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Answer RRs: 1
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Authority RRs: 0
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Additional RRs: 0
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Answers
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" *<00><00><00><00><00><00><00><00><00><00><00><00><00><00><00>: type NBSTAT, class IN
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: *<00><00><00><00><00><00><00><00><00><00><00><00><00><00><00>
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Type: NBSTAT
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Class: IN
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Time to live: 0 time
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Data length: 72
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Number of names: 4
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: MACHINENAME<00> (Workstation/Redirector)
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x4400 (M-node, unique, active)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: MACHINENAME<03> (Messenger service/Main name)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x400 (B-node, unique, active)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: MACHINENAME<20> (Server service)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x400 (B-node, unique, active)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: GROUPNAME<00> (Workstation/Redirector)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x8400 (B-node, group, active)

<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri â
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Second, when the response of NBNS is below, the function gethostbyaddr is wrong.
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri â
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri NetBIOS Name Service
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Transaction ID: 0x803c
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Flags: 0x8400 (Name query response, No error)
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Questions: 0
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Answer RRs: 1
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Authority RRs: 0
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Additional RRs: 0
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Answers
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" *<00><00><00><00><00><00><00><00><00><00><00><00><00><00><00>: type NBSTAT, class IN
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: *<00><00><00><00><00><00><00><00><00><00><00><00><00><00><00>
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Type: NBSTAT
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Class: IN
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Time to live: 0 time
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Data length: 72
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Number of names: 4
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: GROUPNAME<00> (Workstation/Redirector)
<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x8400 (B-node, group, active)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: MACHINENAME<00> (Workstation/Redirector)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x400 (B-node, unique, active)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: MACHINENAME<03> (Messenger service/Main name)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x400 (B-node, unique, active)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name: MACHINENAME<20> (Server service)

<p style="text-indent:9pt; margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <span style="
Name flags: 0x400 (B-node, unique, active)

<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri â
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri I have two questions:
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small 1. As Q154608( http://support.microsoft.com/default.aspx?scid=kb;en-us;Q154608 <span style="font-family:Calibri; color:#0000ff; font-size:small http://support.microsoft.com/default.aspx?scid=kb;en-us;Q154608 <span style="font-size:small <span style="font-family:Calibri )
said,
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small â<span style="font-family:"Verdana","sans-serif"; color:black; font-size:9pt When a gethostbyaddr() uses a NETBIOS Node Status Query to return the Machine Name of
a device, it will return the first instance of the machine name that is registered as Unique [00h].â
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:9pt
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:9pt But under the second situation,
<span style=" following âthe first instance of the machine name that is registered as Unique [00h].â , gethostbyaddr() should return the first
<span style="font-size:small <span style="font-family:Calibri MACHINENAME, but in fact it will return GROUPNAME as the result. I want to know why?
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small 2.
<span style=" Why <span style="font-family:"Verdana","sans-serif"; color:black; font-size:9pt gethostbyaddr() with parameter â<span style="font-family:Calibri; font-size:small AF_INETâ will handle the response of NBNS?
I think that it will handle the response of NBNS only when <span style="font-family:"Verdana","sans-serif"; color:black; font-size:9pt with parameter â<span style="font-size:small <span style="font-family:Calibri AF_NETBIOSâ.
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Can you help me about my question?
<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Thanks and Best wishes,
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Bob
<p style="margin:0in 0in 0pt <span style="font-family:"Verdana","sans-serif"; color:black; font-size:9pt

View the full article
 
Back
Top