curl: (6) Could not resolve host: in Android J

305 views Asked by At

In Android Jellybean, when I try to use curl to access a URL it gives me the following error:

curl: (6) Could not resolve host:

Here is the command I am trying from the Android shell:

$ curl http://www.pu.edu.pk/

I am using latest curl version:

curl 8.0.1 (armv7l-unknown-linux-musleabihf) libcurl/8.0.1 OpenSSL/1.1.1t zlib/1.2.12 libssh2/1.9.0 nghttp2/1.43.0
Release-Date: 2023-03-20
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL threadsafe TLS-SRP UnixSockets

It seems my hostname not resolving to the IP address. However, when I tried it using wget it works fine.

Check the following command:

$ wget http://www.pu.edu.pk/

--2023-05-10 11:59:41--  http://www.pu.edu.pk/
Resolving www.pu.edu.pk... 111.68.103.27
Connecting to www.pu.edu.pk|111.68.103.27|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

So, it seems there is some issue with curl. Does anyone know how to resolve this issue?

1

There are 1 answers

0
 wizehack On

Update c-ares library to the newest version. libcurl calls libcares to get dns resulution info.

c-ares requests an IP address from DNS twice, one for A record (IPv4) and one for AAAA record (IPv6).

Even if you get a normal response on either record, c-ares calls the callback function of libcurl with an error code when a parsing error occurs.

I found that there is an improved patch in the latest version of c-ares code as below.

   if (addinfostatus != ARES_SUCCESS && addinfostatus != ARES_ENODATA)
    {          /* error in parsing result e.g. no memory */
      if (addinfostatus == ARES_EBADRESP && hquery->ai->nodes) //<--------------- condition is added to resolve the error.
        {
          /* We got a bad response from server, but at least one query
           * ended with ARES_SUCCESS */
          end_hquery(hquery, ARES_SUCCESS);
        }
      else
        {
          end_hquery(hquery, addinfostatus);
        }
    }