---------- Forwarded message ----------
From: Carlos A. M. dos Santos <unix...@gmail.com>
Date: Thu, Apr 30, 2009 at 5:39 PM
Subject: getaddrinfo not working on Android?
To: android-...@googlegroups.com
Hello,
I have a C++ code containing this:
char* hostname;
...
struct addrinfo hints;
struct addrinfo *addi;
::memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
int status = ::getaddrinfo(hostname, "9999", NULL, &addi);
if (status != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(status));
return 1;
}
If I run it on the emulator I ever get the following message:
"getaddrinfo failed: servname not supported for ai_socktype"
If I run a similar code on Linux it succeeds. I noticed that Dalvik
uses gethostbyname (in
dalvik/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp)
instead of getaddrinfo.
Is getaddrinfo purposefully not working on Android?
Thanks in advance for your help.
--
My preferred quotation of Robert Louis Stevenson is "You cannot
make an omelette without breaking eggs". Not because I like the
omelettes, but because I like the sound of eggs being broken.
I just realized that I pasted too many lines. The presence of the
"hints" variable in the code above became misleading. It is important
to point out that the error does not happen if I pass the hints to
getaddrinfo, like this:
struct addrinfo hints;
struct addrinfo *addi;
::memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
int status = ::getaddrinfo(hostname, "9999", &hints, &addi);
I'm intrigued about the different behaviors of Linux and Android when
the hint parameter is NULL. Which one is correct?
Ok, thanks for your help!
> On Sat, May 2, 2009 at 7:41 PM, David Turner <di...@android.com> wrote:
>>
>> Hello,
>>
>> this certainly looks like a bug, I will take a look at it. In the
>> meantime, please use a hint to work-around it.
>> Regards
>>
>> On Sat, May 2, 2009 at 7:19 PM, Carlos A. M. dos Santos
---8<--