分段故障主机获取信息时, [英] Segmentation fault when getting host information
本文介绍了分段故障主机获取信息时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它发生在当高并发叫,看来的gethostbyname
没有缓存的结果?
It happens when called at high concurrency,it seems the result of gethostbyname
is not cached ?
static int proxy_getaddr(char *HostName)
{
struct hostent* Host;
Host=gethostbyname(HostName);
if(!Host)
{
unsigned long int addr=inet_addr(HostName);
if(addr!=-1)
Host=gethostbyaddr((char*)addr,sizeof(addr),AF_INET);
}
...
这里的核心转储:
Here's the core dump:
0x00000034f40e98b1 in gethostbyaddr () from /lib64/libc.so.6
0x000000000040182c in proxy_getaddr (HostName=0x48d75be0 "stackoverflow.com")
我怎样才能解决这个问题?
How can I fix this issue?
推荐答案
您code不正确。你逝去的 inet_addr()
,转换为指针,但你真正想要什么的地址的这个结果:
Your code is incorrect. You are passing the result of inet_addr()
, cast to a pointer, but what you actually want is the address of this:
Host = gethostbyaddr(&addr, sizeof(addr), AF_INET);
(其它意见,那你应该使用 in_addr_t
unsigned long int类型而不是是正确的了,但是这是不可能的,这是专门造成您的问题)。
(The other comments, that you should be using in_addr_t
instead of unsigned long int
are correct too, but it is unlikely that this specifically is causing your problem).
这篇关于分段故障主机获取信息时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文