For reference, I am also seeing this problem and have reproduced it
with the two very simple programs below (a.c, and b.c correspond to A
and B as mentioned in CodePupil's post):
/* a.c */
#include <unistd.h>
#include <stdio.h>
int main(int argc, char** argv)
{
printf("a running\n");
execve("b", argv, NULL);
}
/* b.c */
#include <stdio.h>
#include <netdb.h>
#include <errno.h>
#include <netinet/in.h>
int main()
{
struct hostent* h;
struct in_addr* address;
extern int h_errno;
printf("b running\n");
h = gethostbyname("www.google.com");
printf("_errno = %d\n", errno);
printf("h_errno = %d\n", h_errno);
if(h == NULL) {
printf("gethostbyname returned NULL\n");
}
else {
address = (struct in_addr*)h->h_addr;
printf("IP address: %s\n", inet_ntoa(* address));
}
}
The output is as follows:
# ./b
b running
_errno = 0
h_errno = 0
IP address: 209.85.229.106
# ./a
a running
b running
_errno = 111
h_errno = 2
gethostbyname returned NULL
On 25 Sep, 20:27, CodePupil <[email protected]> wrote:
> Hi All,
>
> Could anybody throw some light on the issue ?
>
> Thanks!
>
> On Sep 20, 11:05 pm, CodePupil <[email protected]> wrote:
>
> > Could someone please look into the issue and let me know if it's a
> > limitation ofAndroidplatform(It shouldn't be though) .. ?
>
> > Thanks!
>
> > On Sep 16, 6:56 pm, CodePupil <[email protected]> wrote:
>
> > > Here is the discussion between me and David but still solution is out
> > > of reach !! :(
>
> > > ###########################################################################
> > > #
>
> > > Hi,
>
> > > h_errno has the value "TRY_AGAIN" aftergethostbyname() returns NULL.
>
> > > h_errno suggets "
> > > A temporary error occurred on an authoritative name server. Try again
> > > later !!
> > > "
>
> > > Thanks!
>
> > > => On Tue, Sep 15, 2009 at 5:24 AM, David Turner <[email protected]>
> > > wrote:
>
> > > Try readinf the value of the h_errno variable aftergethostbyname()
> > > returns NULL.
> > > You might also want to try getaddrinfo() which also allows you to
> > > perform DNS resolution (though with a difference interface)
> > > and see if it changes anything.
>
> > > There is a chance that you're encoutering a subtle bug in the DNS
> > > resolver implementation. Can you provide two short
> > > source files that reproduce the problem?
>
> > > => On Mon, Sep 14, 2009 at 11:29 AM, murlivala <[email protected]>
> > > wrote:
>
> > > But A itself is launched from shell and both A and B are native code !
> > > Since A and B are both written in Native code, B alone is able to
> > > work.
> > > I'm quite curious that What difference execve() can make which is used
> > > in the app A ?
> > > I'm not getting any exception, but NULL which is returned by
> > > gethostname() in B after being executed from A using execve() .. !
>
> > > Thanks!
>
> > > =>On Mon, Sep 14, 2009 at 10:25 PM, David Turner <[email protected]>
> > > wrote:
>
> > > My understanding is that B is not a realAndroidapplication, just a
> > > native executable that happens to be installed.
>
> > > When you launch B from an adb shell, you're doing it from the "shell"
> > > user/group ID I believe.
> > > When you launch it from application A, you launch it from A's own
> > > userId/groupId which has less permission that the shell one.
>
> > > the kernel controls permissions based on the UID/GID of processes.
>
> > > =>On Mon, Sep 14, 2009 at 8:03 AM, CodePupil <[email protected]>
> > > wrote:
>
> > > Hi,
>
> > > Thanks for the reply but still there is a room for appropriate
> > > explanation(s).
> > > First let me clarify the problem:
>
> > > Suppose I have test app A which triggers the application B which needs
> > > to resolve the remote hostname.
> > > Now when I execute B directly from the shell, it works fine.
> > > When B is triggered by A using execve(), It fails.
>
> > > If this fails due to less permissions(may be), I don't be able to
> > > understand How could it be?
> > > If I execute both the apps(A and B)from shell(from # prompt), both
> > > should have same permissions.
> > > Either both should work or should simply fail.
>
> > > DoesAndroidsystem itself decide to execute the app giving it less
> > > permissions if that app is triggerred using execve() call ?
>
> > > One more thing, If I triggerred my app using system() call, it works
> > > FINE !
> > > So now, scene is like this:
>
> > > If B is executed itself
> > > # ./B
> > > Result -> Works
>
> > > If B is executed by A using system() call
> > > # ./A
> > > Result -> Works
>
> > > If B is executed by A using execve() call
> > > # ./A
> > > Result -> Doesn't work -> ??
>
> > > Looking for better explanation(s) !
>
> > > Thanks!
>
> > > ###########################################################################
> > > #
>
> > > On Sep 14, 6:10 pm, David Turner <[email protected]> wrote:
>
> > > > On Mon, Sep 14, 2009 at 6:06 AM, lbcoder <[email protected]> wrote:
>
> > > > > There are two DNS sets on anandroiddevice.
> > > > > The "linux" set and the "android" set.
> > > > > You can find the DNS servers used by linux by checking the contents
> > > > > of /etc/resolv.conf
> > > > > Theandroiddns servers can be found by "getprop".
> > > > > They do not match.
> > > > > Theandroiddns servers are set by dhcp.
> > > > > The linux dns servers are more like fallbacks and are set statically.
>
> > > > This is correct, but it's only an implementation detail that should not
> > > > affect typical application developers (even the C library DNS resolver
> > > > uses
> > > > the
> > > > system properties to know which DNS servers to talk to), so there
> > > > should be
> > > > no difference between native and VM code when it comes to DNS
> > > > resolution.
>
> > > > > On Sep 14, 2:56 am, CodePupil <[email protected]> wrote:
> > > > > > Hi All,
>
> > > > > > I'm facing strange problem in resolving remote hostname.
> > > > > > I have an application which needs to resolve some remote hostname in
> > > > > > order to connect to it, and If I start this application using
> > > > > > execve()
> > > > > > call, the application doesn't resolve hostname,gethostbyname()
> > > > > > returns NULL. If I execute the application directly, it's able to
> > > > > > resolve the host name but if it's executed using execve() call, it
> > > > > > doesn't.
> > > > > > Same approach is working fine on Linux machine but onAndroidplatform
> > > > > > it's not able to work.
>
> > > > > > On Linux:
> > > > > > execve() -----> application() ------> Works
> > > > > > app() -----> Works
>
> > > > > > OnAndroid:
> > > > > > execve() -----> application() ------> Doesn't works ------->
> > > > > > ???
> > > > > > app() -----> Works
>
> > > > > ___________________________________________________________________________
> > > > > ____
>
> > > > > > Could anybody please throw some light on the matter ?
>
> > > > > > Thanks!- Hide quoted text -
>
> > > > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Android Discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---