On Thu, Apr 30, 2009 at 5:39 PM, Carlos A. M. dos Santos
<unixma...@gmail.com> wrote:
> 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?

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?

-- 
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.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"android-framework" group.
To post to this group, send email to android-framework@googlegroups.com
To unsubscribe from this group, send email to 
android-framework+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/android-framework?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to