c++ gethostbyaddr 与用户输入
我正在为 telnet 客户端编写 C++ 代码。我在从用户输入获取主机地址时遇到问题。
struct in_addr peers;
cin>>peers;
peerserver = gethostbyaddr((const char*)peers,4,AF_INET);
if (peerserver == NULL)
exit(0);
我是 C++ 新手,谁能建议一种更好的方法来通过用户输入获取主机地址。提前致谢。
I am writing c++ code for a telnet client. I am having problems getting the host address from the user input.
struct in_addr peers;
cin>>peers;
peerserver = gethostbyaddr((const char*)peers,4,AF_INET);
if (peerserver == NULL)
exit(0);
I am new to c++, can anyone suggest a better way of getting the host addr with user input. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要查找的是
gethostbyname
,而不是gethostbyaddr
。gethostbyaddr
假定您已经获得了 IP 地址。What you're looking for is
gethostbyname
, notgethostbyaddr
.gethostbyaddr
assumes that you've already got the IP address.