Re: gethostbyname problems

470 views
Skip to first unread message

Gavin Kinsey

unread,
Sep 11, 2012, 4:11:13 AM9/11/12
to andro...@googlegroups.com
On Tuesday 11 September 2012 00:45:23 Alexander Cohen wrote:
>
> I'm working with Apple's Bonjour source code and trying to get it to work
> correctly on Android using the ndk. I got it all up and running and
> working pretty well, i'm pleased. There is one small problem when i try
> and resolve a hostname of a local computer though. I get that hostname
> from a callback directly from apple's code. If i use that hostname with
> gethostbyname, the hostent returned is NULL which is very surprising.
> I've tried using something i know should resolve such as "google.com"
> and that works fine. But anything local ( i.e.: "WIN-PC.local." ) never
> resolves. Has anyone seen anything similar to this? Any ideas how to fix
> the issue.
>
> BTW, i have tried the same code on both Mac and Windows ( latest OS's )
> and the hostname is resolved without a problem. Also, my device is a
> brand new nexus 7 in case that matters completely up to date and the
> target is android 14.

gethostbyname uses DNS and local addresses don't exist in DNS, only in MDNS.
You need to use the equivalent bonjour api call to do the lookup. I
implemented similar functionality using the avahi library so I don't know
the name of it but you need to setup a resolve callback from the browse
callback.

The reason it works on PC is Bonjour installs hooks into the operating
system to allow standard DNS api calls to use the MDNS library. It can't do
this on Android and so you need to do the calls yourself.

--
Gavin Kinsey
AD Holdings Plc


--------------------------------------------------------
This email and any files transmitted with it are CONFIDENTIAL and intended solely for the use of the individual or entity to whom they are addressed. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system; you may not copy this message or disclose its contents to anyone. The recipient should check this email and any attachments for the presence of viruses. The Company accepts no liability for any damage caused by any virus transmitted by this email. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the Company. Contact Customer Services for details customer...@dmicros.com
Reply all
Reply to author
Forward
0 new messages