Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 98149
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: Nobody in particular
Requestors: fraserbn [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Android support
Howdy! The attached patch adds support for Android to the module. The main component is to grab the net.dsn{1..4} setting from getprop; slightly less importantly, it overrides some of the UNIX resolver to have it check /system/etc instead of /etc -- /etc generally exists, but even if it does, it's just a symlink to /system/etc.
Subject: 0001-Android-support.patch
From c49d72f592c78b926ce760f9e2a20e7b746fc3b1 Mon Sep 17 00:00:00 2001 From: Brian Fraser <fraserbn@gmail.com> Date: Sun, 17 Aug 2014 18:58:39 +0200 Subject: [PATCH] Android support --- MANIFEST | 1 + lib/Net/DNS/Resolver/UNIX.pm | 2 +- lib/Net/DNS/Resolver/android.pm | 71 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 lib/Net/DNS/Resolver/android.pm diff --git a/MANIFEST b/MANIFEST index 56ce021..06e5988 100644 --- a/MANIFEST +++ b/MANIFEST @@ -26,6 +26,7 @@ lib/Net/DNS/Packet.pm lib/Net/DNS/Parameters.pm lib/Net/DNS/Question.pm lib/Net/DNS/Resolver.pm +lib/Net/DNS/Resolver/android.pm lib/Net/DNS/Resolver/Base.pm lib/Net/DNS/Resolver/cygwin.pm lib/Net/DNS/Resolver/MSWin32.pm diff --git a/lib/Net/DNS/Resolver/UNIX.pm b/lib/Net/DNS/Resolver/UNIX.pm index 138710d..16784fc 100644 --- a/lib/Net/DNS/Resolver/UNIX.pm +++ b/lib/Net/DNS/Resolver/UNIX.pm @@ -18,7 +18,7 @@ use strict; use base qw(Net::DNS::Resolver::Base); -my $resolv_conf = "/etc/resolv.conf"; +our $resolv_conf = "/etc/resolv.conf"; my $dotfile = '.resolv.conf'; my @config_path; diff --git a/lib/Net/DNS/Resolver/android.pm b/lib/Net/DNS/Resolver/android.pm new file mode 100644 index 0000000..536e919 --- /dev/null +++ b/lib/Net/DNS/Resolver/android.pm @@ -0,0 +1,71 @@ +package Net::DNS::Resolver::android; + +# +# $Id: UNIX.pm 1224 2014-07-01 07:57:42Z willem $ +# +use vars qw($VERSION); +$VERSION = (qw$LastChangedRevision: 1224 $)[1]; + + +=head1 NAME + +Net::DNS::Resolver::UNIX - UNIX Resolver Class + +=cut + + +use strict; +use base qw(Net::DNS::Resolver::UNIX); + + +my $android_root = $ENV{ANDROID_ROOT} || '/system'; +# /system/etc/resolv.conf MAY exists. It probably doesn't, +# and it gets ignored by some of Bionic. Still worth a shot. +my $resolv_conf = File::Spec->catfile($android_root, "etc", "resolv.conf"); + +sub init { + my $class = shift; + my $self = $class->defaults; + + my @nameservers; + + for my $i (1..4) { + my $ret = `getprop net.dns$i`; + chomp $ret; + push @nameservers, $ret if $ret; + } + + $self->nameservers(@nameservers) if @nameservers; + + local $Net::DNS::Resolver::UNIX::resolv_conf = $resolv_conf; + $class->SUPER::init(@_); +} + + +1; +__END__ + + +=head1 SYNOPSIS + + use Net::DNS::Resolver; + +=head1 DESCRIPTION + +This class implements the OS specific portions of C<Net::DNS::Resolver>. + +No user serviceable parts inside, see L<Net::DNS::Resolver|Net::DNS::Resolver> +for all your resolving needs. + +=head1 COPYRIGHT + +Copyright (c) 1997-2002 Michael Fuhr. + +All rights reserved. This program is free software; you may redistribute +it and/or modify it under the same terms as Perl itself. + +=head1 SEE ALSO + +L<perl>, L<Net::DNS>, L<Net::DNS::Resolver> + +=cut -- 1.7.12.4 (Apple Git-37)
From: rwfranks [...] acm.org
Thanks for your help in bringing Net::DNS to another platform. The active ingredients of your suggested solution have now been reworked to disentangle it from the UNIX.pm package. Android is not a sub-class of Unix, so the inheritance relationship that you used is semantically wrong. It does not yield much in the way of code-saving either. Confining the OS-specific bits to an independent package avoids any risk that it might get broken by future changes which might be needed in UNIX.pm. Please can you install version 0.78_5 and check that this actually works. This will need to be done quickly, to avoid slipping the release date for 0.79.
From: fraserbn [...] gmail.com
On Tue Aug 19 10:19:25 2014, rwfranks@acm.org wrote: Show quoted text
> Thanks for your help in bringing Net::DNS to another platform. > > The active ingredients of your suggested solution have now been > reworked to disentangle it from the UNIX.pm package. > > Android is not a sub-class of Unix, so the inheritance relationship > that you used is semantically wrong.
Oh, why not? Android is really a barebones Linux distro with some quirks, plus Java bells and whistles on top. Case point: shell@android:home # uname -a Linux hugmeir-ouya_1_1 3.1.10-g780994a #1 SMP PREEMPT Tue Aug 5 11:18:22 PDT 2014 armv7l GNU/Linux Show quoted text
> It does not yield much in the > way of code-saving either.
Fair enough, though :) The code in the svn repo looks significantly clearer. Show quoted text
> > Confining the OS-specific bits to an independent package avoids any > risk that it might get broken by future changes which might be needed > in UNIX.pm. > > Please can you install version 0.78_5 and check that this actually > works. This will need to be done quickly, to avoid slipping the > release date for 0.79.
I got 0.78_5 off svn, and it all looks good: shell@android:Net-DNS-0.78_5 # perl -Mblib -MNet::DNS -E 'say "$Net::DNS::VERSION"' 0.78_5 shell@android:Net-DNS-0.78_5 # perl -Mblib -MNet::DNS -E 'say join ", ", Net::DNS::Resolver->new->nameservers' 8.8.8.8, 127.0.0.1, ::1 Thanks for the quick feedback!
From: rwfranks [...] acm.org
On Tue Aug 19 17:30:31 2014, Hugmeir wrote: [snip] Show quoted text
> > Android is not a sub-class of Unix, so the inheritance relationship > > that you used is semantically wrong.
> > Oh, why not? Android is really a barebones Linux distro with some > quirks, plus Java bells and whistles on top. Case point:
Unconvincing. If they really were indistinguishable, the nameserver addresses would be in /etc/resolv.conf like every other Linux and Unix platform, and we would not be having this conversation! Show quoted text
> shell@android:Net-DNS-0.78_5 # perl -Mblib -MNet::DNS -E 'say join ", > ", Net::DNS::Resolver->new->nameservers' > 8.8.8.8, 127.0.0.1, ::1 >
I am not happy with that, unless you really have a nameserver daemon running on your machine. This will still work, but suffer serious delays when a DNS reply gets dropped in the network.
From: rwfranks [...] acm.org
On Tue Aug 19 17:30:31 2014, Hugmeir wrote: Show quoted text
> shell@android:Net-DNS-0.78_5 # perl -Mblib -MNet::DNS -E 'say join ", > ", Net::DNS::Resolver->new->nameservers' > 8.8.8.8, 127.0.0.1, ::1 >
Fixed on SVN trunk
From: fraserbn [...] gmail.com
On Wed Aug 20 12:43:10 2014, rwfranks@acm.org wrote: Show quoted text
> On Tue Aug 19 17:30:31 2014, Hugmeir wrote: >
> > shell@android:Net-DNS-0.78_5 # perl -Mblib -MNet::DNS -E 'say join ", > > ", Net::DNS::Resolver->new->nameservers' > > 8.8.8.8, 127.0.0.1, ::1 > >
> Fixed on SVN trunk >
The one-liner from before now returns just '8.8.8.8' -- thank you!
From: rwfranks [...] acm.org
On Wed Aug 20 13:05:26 2014, Hugmeir wrote: Show quoted text
> > The one-liner from before now returns just '8.8.8.8' -- thank you! >
As I thought it should. Thanks for turning the tests round so promptly.
Android support included in 0.79. Thanks for the contribution.