gethostbyaddr()怎麼用的啊?我這樣用怎麼不行啊?

xhwu3721 2003-09-12 10:08:19
gethostbyaddr()怎麼用的啊?我這樣用怎麼不行啊?
CString addr;
addr="10.132.227.131";
hostAddr=gethostbyaddr(addr,14,AF_INET );
if(hostAddr==NULL)
{
char * buf=new char[100];
strcpy(buf,"can't find the pc ip '");
strcat(buf,m_PcName);
strcat(buf,"'");
MessageBox(buf,"Error");
delete buf;
return;
}

CString sip;
sip.Format("%s",hostAddr->h_name);
m_monitor.InsertString(0,sip);
}
...全文
34 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanshenpkl 2003-09-12
  • 打赏
  • 举报
回复
Although gethostbyaddr is deprecated by the getnameinfo function, gethostbyaddr is capable of returning a NetBIOS name; getnameinfo is not. Developers requiring NetBIOS name resolution may need to use gethostbyaddr until their applications are completely independent of NetBIOS names
xhwu3721 2003-09-12
  • 打赏
  • 举报
回复
已經解決了如下:
CString addr;
addr="10.132.227.131";
sockaddr_in findhostaddr;
findhostaddr.sin_addr.S_un.S_addr=inet_addr(addr);
hostAddr=gethostbyaddr((const char *)&(findhostaddr.sin_addr.S_un.S_addr),4,AF_INET );
if(hostAddr==NULL)
{
char * buf=new char[100];
strcpy(buf,"can't find the pc ip '");
strcat(buf,m_PcName);
strcat(buf,"'");
MessageBox(buf,"Error");
delete buf;
return;
}

CString sip;
sip.Format("The IP "+addr+" PC name is:"+"%s",hostAddr->h_name);
m_monitor.InsertString(0,sip);
zhanshenpkl 2003-09-12
  • 打赏
  • 举报
回复
WSANO_DATA
(11004)
Valid name, no data record of requested type.
The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record—indicating the host itself exists, but is not directly reachable.
zhanshenpkl 2003-09-12
  • 打赏
  • 举报
回复
要么就是地址没有办法解释,DNS解释失败,没有与之相对应的名称。你用WSAGetLastError看错误代码是多少,然后在MSDN中查找这个错误代码的解释。
zhanshenpkl 2003-09-12
  • 打赏
  • 举报
回复
你有没有初始化套接字?

18,356

社区成员

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

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