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)