| 1 | package Net::DNS::Resolver::android; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | our $VERSION = (qw$Id: android.pm 2007 2025-02-08 16:45:23Z willem $)[2]; | ||
| 6 | |||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Net::DNS::Resolver::android - Android resolver class | ||
| 11 | |||
| 12 | =cut | ||
| 13 | |||
| 14 | |||
| 15 | my $config_file = 'resolv.conf'; | ||
| 16 | my @config_path = ( $ENV{ANDROID_ROOT} || '/system' ); | ||
| 17 | my @config_file = grep { -f $_ && -r $_ } map {"$_/etc/$config_file"} @config_path; | ||
| 18 | |||
| 19 | my $homedir = $ENV{HOME}; | ||
| 20 | my $dotfile = '.resolv.conf'; | ||
| 21 | my @dotfile = grep { -f $_ && -o $_ } map {"$_/$dotfile"} grep {$_} $homedir, '.'; | ||
| 22 | |||
| 23 | |||
| 24 | sub _init { | ||
| 25 | my $defaults = shift->_defaults; | ||
| 26 | |||
| 27 | my @nameserver; | ||
| 28 | for ( 1 .. 4 ) { | ||
| 29 | my $ret = `getprop net.dns$_` || next; | ||
| 30 | chomp $ret; | ||
| 31 | push @nameserver, $ret || next; | ||
| 32 | } | ||
| 33 | |||
| 34 | $defaults->nameserver(@nameserver) if @nameserver; | ||
| 35 | |||
| 36 | |||
| 37 | $defaults->_read_config_file($_) foreach @config_file; | ||
| 38 | |||
| 39 | %$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults); | ||
| 40 | |||
| 41 | $defaults->_read_config_file($_) foreach @dotfile; | ||
| 42 | |||
| 43 | $defaults->_read_env; | ||
| 44 | return; | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | 1; | ||
| 49 | __END__ |