如何找到Unix主机?

francis 2000-05-24 09:04:00
使用Socket通信,发送UDP包,Unix端用BSDSocket,Windows端用Winsock.
从Unix-->Unix,Unix-->Windows,Windows-->Windows都没问题,但从Windows-->Unix时,无论用gethostbyname()或gethostbyaddr()都得不到类型为(struct hostent)的Unix主机描述.
为何? 如何解决? 如有程序例子更好.
Thanks
...全文
125 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
francis 2000-05-26
  • 打赏
  • 举报
回复
返回错误是WSANO_DATA: Valid name, no data record of requested type. 如何处置?
我的句法是这样的:hp = gethostbyaddr((char *)&addr,4,AF_INET);
x86 2000-05-24
  • 打赏
  • 举报
回复
我把MSDN中的帮助抄给你,不过你应该有吧.
你可以先看看返回什么错误.

Return Values
If no error occurs, gethostbyname returns a pointer to the HOSTENT structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.

Error Code Meaning
WSANOTINITIALISED A successful WSAStartup call 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 failure.
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.
WSAEFAULT The name parameter is not a valid part of the user address space.
WSAEINTR A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.


Remarks
The gethostbyname function returns a pointer to a HOSTENT structure — a structure allocated by Windows Sockets. The HOSTENT structure contains the results of a successful search for the host specified in the name parameter.

The application must never attempt to modify this structure or to free any of its components. Furthermore, only one copy of this structure is allocated per thread, so the application should copy any information it needs before issuing any other Windows Sockets function calls.

The gethostbyname function cannot resolve IP address strings passed to it. Such a request is treated exactly as if an unknown host name were passed. Use inet_addr to convert an IP address string the string to an actual IP address, then use another function, gethostbyaddr, to obtain the contents of the HOSTENT structure.

The gethostbyname function resolves the string returned by a successful call to gethostname.

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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