'C++ gethostbyname error No such file or directory
I use arm ld-linux-armhf.so.3 excute program on aarch system. When I call gethostbyname failed with No such file or directory
char host[100] = "www.google.com";
struct hostent *hp;
if ((hp=gethostbyname(host)) == NULL){
cout<<"gethostbyname\t"<<-2<<endl;
if(errno!=0)
{
cout<<"gethostbyname\t"<<errno<<endl;
cout<<"gethostbyname\t"<<strerror(errno)<<endl;
}
}
gethostbyname -2
gethostbyname 2
gethostbyname No such file or directory
/etc/resolve.conf
nameserver 8.8.8.8
/etc/hosts
127.0.0.1 localhost
127.0.0.1 AIBox
1.1.1.1 www.google.com
How do I know which file is not found?
Changed to h_errno.
char host[100] = "www.google.com";
struct hostent *hp;
if ((hp=gethostbyname(host)) == NULL){
cout<<"gethostbyname\t"<<-2<<endl;
if(errno!=0)
{
cout<<"gethostbyname\t"<<h_errno<<endl;
cout<<"gethostbyname\t"<<hstrerror(h_errno)<<endl;
}
}
gethostbyname -2
gethostbyname 3
gethostbyname Unknown server error
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
