greg7gkb
greg7gkb

Reputation: 5040

getaddrinfo() failing in Android?

I'm building a C library we have using the Android NDK build chain. Things are working in general, but the following section is causing problems:

#include <netdb.h>
...
    struct addrinfo* addr_result;

    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;

    LOGD("host name: %s", name);
    result = getaddrinfo(name, GCSL_NULL, &hints, &addr_result);
    LOGD("result: %d", result);

getaddrinfo is returning an error code of 7, which translates to "EAI_NODATA".

I tried forcing "name" to easy urls like "www.google.com" and "http://www.google.com" but nothing works.

I'm debugging using the emulator, which in general is able to connect to the Internet from other applications.

Upvotes: 2

Views: 5406

Answers (2)

FeelGood
FeelGood

Reputation: 5614

Insure that you have INTERNET permission in AndroidManifest.xml.

Upvotes: 4

greg7gkb
greg7gkb

Reputation: 5040

It looks like this could be caused by an emulator DNS bug:

http://groups.google.com/group/android-developers/browse_thread/thread/b04537d827c4f9e1

Upvotes: 0

Related Questions