急问 微软专家(关于 gethostbyaddr)

chen_jun_fen 2002-11-11 10:05:17
我发现这个函数对机器的配置也有关系,但是具体和那些东西有关系不是很清楚.
比如 61.171.20.23这个是internet上的IP地址,我要根据这个IP地址取得
这机器的host name
unsigned long ip2 ;
ip2 = inet_addr( inet_ntoa( "61.171.20.23" ) ) ;
HOSTENT m_tmpHostent = gethostbyaddr( (char*)&ip2 ) ;
结果 m_tmpHosten == NULL ;
但是有的电脑用这样的方法是可以取得到 主机名.
所以我想请问 gethostbyaddr 执行过程是怎样的 ?
和机器的那些配置有关系?
谢谢!!!!!
...全文
198 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gargamel 2002-11-21
  • 打赏
  • 举报
回复
我的第一个回复里就说过,网络上的机器名并不是tcp/ip协议簇中的东西,而是netbios协议中的。支持tcp/ip的机器,并不一定支持netbios。
不同的操作系统,不同的系统配置,你用gethostbyaddr()拿到的结果自然不同!

回到你现在的问题,现象出现的原因很简单,csdn的系统是不支持netbios的,而microsoft.com的系统打开了netbios服务
chen_jun_fen 2002-11-20
  • 打赏
  • 举报
回复
没人碰到过这样的情况吗 ?
都这么多天了,
还是没有人来,
不了了之
chen_jun_fen 2002-11-18
  • 打赏
  • 举报
回复
这样好了,我去取 www.csdn.net的主机名的时候,取不到,
而我去取 www.microsoft.com的主机名的时候,是取的到的.
怎么回事 ?
alaclp 2002-11-17
  • 打赏
  • 举报
回复
我觉得应该是netbios的问题,网络中标准通信协议是tcp/ip, netbios可以设置成附属协议,如果设置了,则可以取得hostname
chen_jun_fen 2002-11-16
  • 打赏
  • 举报
回复
那为什么我取其他IP地址的主机名是可以的那
kevin512 2002-11-16
  • 打赏
  • 举报
回复
我觉着是不是你在192.168.0.168开始试验你的程序的时候,没有设定默认的DNS或者wins呢?
asdmonster 2002-11-14
  • 打赏
  • 举报
回复
mark
chen_jun_fen 2002-11-13
  • 打赏
  • 举报
回复
不对,
今天我把服务器重装了一下,
就可以了.不知道怎么回事
zhaolaoxin 2002-11-13
  • 打赏
  • 举报
回复
gethostbyaddr是netbios的函数,不能跨网段。
61的地址并没有连接到局域网的设备上,而是通过那台机器的操作系统完成数据转发的。
chen_jun_fen 2002-11-13
  • 打赏
  • 举报
回复
不能
zhaolaoxin 2002-11-13
  • 打赏
  • 举报
回复
1,你试试在局域网其他的机器用61.171.20.23这个地址能否得到主机名。
2,将你的机器地址改为61网段,看看能否得到主机名。
Gargamel 2002-11-11
  • 打赏
  • 举报
回复
描述得还不够清楚。比如,你怎么用192.168.0.1去执行gesthostbyaddr()?是把61.171.20.23那块网卡禁止了?还是?

还有,你gesthostbyaddr()的时候,是去取谁的地址?局域网内的还是外网的??
chen_jun_fen 2002-11-11
  • 打赏
  • 举报
回复
说明白点好了.
我们局域网内有一台服务器,
操作系统win2000 Server
有两块网卡,一块:192.168.0.1
一块是连ADSL的,上网之后获得的IP地址是 61.171.20.23(动态的,下次上网时会改变,跟这个应该没有关系的.),我用192.168.0.1去执行gethostbyaddr
的时候,可以得到对方的主机名,但是用61.171.20.23时去执行gethostbyaddr
的时候,会出现WSANO_DATA.但是也不是所有的机器都不行.
我试了其他上网的机器,也用internet的IP地址,gethostbyaddr可以执行.
所以我想弄清楚,我们这台服务器那些配置出了问题.
Gargamel 2002-11-11
  • 打赏
  • 举报
回复
我的解释(不一定正确)

gethostbyaddr()函数用来获取机器名的手段,并非标准tcp/ip协议中的东西。(应该是netbios协议簇中的东西)。所以,对支持这种方法的操作系统,函数可以取得远程ip的机器名。但对linux等系统,在默认情况下,似乎不支持。

同时,网络状况也可能会影响到函数执行的结果,比哪,超时等。

你可以在自己身边的机器上谢谢看,是不是操作系统、网络延时等造成的。
qing_li73 2002-11-11
  • 打赏
  • 举报
回复
try debug and see its asm code
chen_jun_fen 2002-11-11
  • 打赏
  • 举报
回复
微软专家去哪里了 ?
chen_jun_fen 2002-11-11
  • 打赏
  • 举报
回复
我用 WSAGetLastError().
得到 WSANO_DATA 这个东西,
但是为什么有的机器正常有的机器不正常.
我想知道 这个gethostbyaddr()的执行过程,
以及她是从那里得到远程的机器名.
IP地址和机器名保存在哪里
qing_li73 2002-11-11
  • 打赏
  • 举报
回复
u can judge the different status via the error code
qing_li73 2002-11-11
  • 打赏
  • 举报
回复
Return Values
If no error occurs, gethostbyaddr returns a pointer to the HOSTENT structure. Otherwise, it returns a NULL pointer, and a specific error code can be retrieved by calling WSAGetLastError.

Error Codes
WSANOTINITIALISED A successful WSAStartup must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAHOST_NOT_FOUND Authoritative Answer Host not found.
WSATRY_AGAIN Non-Authoritative Host not found, or server failed.
WSANO_RECOVERY Nonrecoverable error occurred.
WSANO_DATA Valid name, no data record of requested type.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEAFNOSUPPORT The type specified is not supported by the Windows Sockets implementation.
WSAEFAULT The addr parameter is not a valid part of the user address space, or the len parameter is too small.
WSAEINTR A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.
chen_jun_fen 2002-11-11
  • 打赏
  • 举报
回复
不要给我这个答案
Some applications use the gethostbyaddr( ) function to resolve an IP address to a host name. The gethostbyaddr( ) call uses the following (default) sequence:

Check the hosts file for a matching address entry.
If a DNS server is configured, query it.
Send a NetBIOS Adapter Status Request to the IP address being queried, and if it responds with a list of NetBIOS names registered for the adapter, parse it for the computer name.
加载更多回复(4)

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧