我通过ppp打开GSM连接并尝试从带有curl的URL下载文件。
设备很少,我从curl
得到 CURLE_COULDNT_RESOLVE_HOST 错误而getaddrinfo
导致 EAI_AGAIN 。
在route
我的 ppp0 界面注册正确。 resolv.conf 包含Google DNS,并在终端中手动执行nslookup
。
我不知道它为什么不起作用。我唯一知道的是: IPv6 是不可能的。
这是我getaddrinfo
int checkINet(std::string address)
{
struct addrinfo hints, *servinfo, *p;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
char ip_addr[INET6_ADDRSTRLEN];
int s = getaddrinfo(address.c_str(), NULL, &hints, &servinfo);
if (s != 0)
{
std::cout << "No connection possible: " << address << "\n";
std::cout << "getaddrinfo: " << s << " " << gai_strerror(s) << "\n";
return -1;
}
else
{
std::cout << "Conection successful: " << address << "\n";
for (p = servinfo; p != NULL; p = p->ai_next)
{
void *addr;
if (p->ai_family == AF_INET)
{
struct sockaddr_in *ipv4 =(struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);
}
else
{
struct sockaddr_in6 *ipv6 =(struct sockaddr_in6 *)p->ai_addr;
addr = &(ipv6->sin6_addr);
}
inet_ntop(p->ai_family, addr, ip_addr, sizeof ip_addr);
std::cout << addr << "\n";
}
}
freeaddrinfo(servinfo);
return 0;
}
对于卷曲:
CURL *curl;
FILE *fp;
CURLcode res;
// initialise a connection to the server
curl = curl_easy_init();
if (curl)
{
fp = fopen(UPDATE_ZIP, "wb");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
if (CURLE_OK != res)
{
std::out << "curl failed with: " << res << "\n";
return res;
}
return 0;
}
return -1;
答案 0 :(得分:0)
/etc/nsswitch.con
内的订单
hosts:files dns
至
hosts:dns文件