按名称获取主机(带有变量) [英] Get Host By Name (with a variable)

查看:53
本文介绍了按名称获取主机(带有变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从URL获取IP地址.当我使用"www.dog.com"时,此方法工作正常,但当我要使用变量时,它不起作用.

 HOSTENT * pHostEnt;
 int  ** ppaddr;
SOCKADDR_IN sockAddr;
字符 * addr;

std :: wstring网站;
site = wsURL.c_str();
pHostEnt = gethostbyname(" );
ppaddr =( int  **)pHostEnt-> h_addr_list;
sockAddr.sin_addr.s_addr = ** ppaddr;
addr = inet_ntoa(sockAddr.sin_addr); 

解决方案

API到底是怎么知道"site"是变量名的,而不是您要查找的主机名?

pHostEnt = gethostbyname("site");



您看到引号了吗?您认为这意味着什么?

不,我不会为您提供有效的代码,除了如何粘贴之外,您将不会学到其他任何东西,并且您已经证明自己做得很好.


I''m trying to get an IP address from an URL. This works fine when I use "www.dog.com" but when I want to use a variable it doesn''t work.

HOSTENT *pHostEnt;
int  **ppaddr;
SOCKADDR_IN sockAddr;
char* addr;
		
std::wstring site;
site = wsURL.c_str();
pHostEnt = gethostbyname("site");
ppaddr = (int**)pHostEnt->h_addr_list;
sockAddr.sin_addr.s_addr = **ppaddr;
addr = inet_ntoa(sockAddr.sin_addr);

解决方案

How in the world is the API to know that "site" is the name of your variable and not the name of the host you are looking up?

pHostEnt = gethostbyname("site");



Do you see the quotation marks? What do you think that means?

No, I''m not going to give you the code that works, you''ll not learn anything other than how to paste and you''ve demonstrated that you do that well.


这篇关于按名称获取主机(带有变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆