Convert gethostby* functions to IPv6-friendly equivalents
authorJamie Cameron <jcameron@webmin.com>
Sun, 31 Oct 2010 00:36:36 +0000 (17:36 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sun, 31 Oct 2010 00:36:36 +0000 (17:36 -0700)
apache/core.pl
backup-config/backup-config-lib.pl
fsdump/freebsd-lib.pl
fsdump/irix-lib.pl
fsdump/linux-lib.pl
fsdump/solaris-lib.pl
ipfilter/ipfilter-lib.pl
ldap-server/ldap-server-lib.pl
mount/linux-lib.pl
zones/forms-lib.pl

index 33eb9f6..04c8879 100755 (executable)
@@ -317,8 +317,7 @@ for($i=0; defined($in{"Port_$i"}); $i++) {
 
        if ($bdef) { push(@blist, "*"); }
        elsif ($b =~ /^\S+$/ &&
-              (gethostbyname($b) || &check_ipaddress($b) ||
-               &check_ip6address($b))) { push(@blist, $b); }
+              (&to_ipaddress($b) || &to_ip6address($b))) { push(@blist, $b); }
        else { &error(&text('core_eaddress', $b)); }
 
        if ($pdef) { push(@plist, undef); }
@@ -576,8 +575,8 @@ local(@nv, $nv, $addr);
 foreach $nv (@nv) {
        if ($nv =~ /^(\S+):(\d+|\*)$/) { $addr = $1; }
        else { $addr = $nv; }
-       if (!gethostbyname($addr) && !&check_ipaddress($addr) &&
-           !&check_ip6address($addr) && $addr ne '*') {
+       if (!&to_ipaddress($addr) &&
+           !&to_ip6address($addr) && $addr ne '*') {
                &error(&text('core_evirtaddr', $addr));
                }
        if ($nv =~ /^(\S+):(\d+|\*)$/ && &check_ip6address($1)) {
index 648a131..923fb2e 100755 (executable)
@@ -231,7 +231,9 @@ if ($mode == 0) {
        }
 elsif ($mode == 1) {
        # FTP server
-       gethostbyname($in{"$_[0]_server"}) || &error($text{'backup_eserver1'});
+       &to_ipaddress($in{"$_[0]_server"}) ||
+         &to_ip6address($in{"$_[0]_server"}) ||
+           &error($text{'backup_eserver1'});
        $in{"$_[0]_path"} =~ /^\/\S/ || &error($text{'backup_epath'});
        $in{"$_[0]_user"} =~ /^[^:]*$/ || &error($text{'backup_euser'});
        $in{"$_[0]_pass"} =~ /^[^\@]*$/ || &error($text{'backup_epass'});
@@ -244,7 +246,9 @@ elsif ($mode == 1) {
        }
 elsif ($mode == 2) {
        # SSH server
-       gethostbyname($in{"$_[0]_sserver"}) || &error($text{'backup_eserver2'});
+       &to_ipaddress($in{"$_[0]_sserver"}) ||
+         &to_ip6address($in{"$_[0]_sserver"}) ||
+           &error($text{'backup_eserver2'});
        $in{"$_[0]_spath"} =~ /^\/\S/ || &error($text{'backup_epath2'});
        $in{"$_[0]_suser"} =~ /^[^:]*$/ || &error($text{'backup_euser'});
        $in{"$_[0]_spass"} =~ /^[^\@]*$/ || &error($text{'backup_epass'});
index 9984fd1..36a2061 100755 (executable)
@@ -109,7 +109,8 @@ if ($in{'mode'} == 0) {
        delete($_[0]->{'hfile'});
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+           &to_ip6address($in{'host'}) ||
                &error($text{'dump_ehost'});
        $_[0]->{'host'} = $in{'host'};
        $in{'huser'} =~ /^\S+$/ || &error($text{'dump_ehuser'});
@@ -346,7 +347,8 @@ if ($in{'mode'} == 0) {
        $cmd .= " -f '$in{'file'}'";
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+           &to_ip6address($in{'host'}) ||
                &error($text{'restore_ehost'});
        $in{'huser'} =~ /^\S*$/ || &error($text{'restore_ehuser'});
        $in{'hfile'} || &error($text{'restore_ehfile'});
index a86bf2b..d511622 100755 (executable)
@@ -81,7 +81,8 @@ if ($in{'mode'} == 0) {
        delete($_[0]->{'hfile'});
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+           &to_ip6address($in{'host'}) ||
                &error($text{'dump_ehost'});
        $_[0]->{'host'} = $in{'host'};
        $in{'huser'} =~ /^\S+$/ || &error($text{'dump_ehuser'});
@@ -229,7 +230,8 @@ if ($in{'mode'} == 0) {
        $cmd .= " -f '$in{'file'}'";
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+           &to_ip6address($in{'host'}) ||
                &error($text{'restore_ehost'});
        $in{'huser'} =~ /^\S*$/ || &error($text{'restore_ehuser'});
        $in{'hfile'} || &error($text{'restore_ehfile'});
index 7836a53..fbec98c 100755 (executable)
@@ -204,7 +204,8 @@ if ($in{'mode'} == 0) {
        delete($_[0]->{'hfile'});
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+           &to_ip6address($in{'host'}) ||
                &error($text{'dump_ehost'});
        $_[0]->{'host'} = $in{'host'};
        $in{'huser'} =~ /^\S*$/ || &error($text{'dump_ehuser'});
@@ -656,7 +657,8 @@ if ($in{'mode'} == 0) {
        $cmd .= " -f '$in{'file'}'";
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+           &to_ip6address($in{'host'}) ||
                &error($text{'restore_ehost'});
        $in{'huser'} =~ /^\S*$/ || &error($text{'restore_ehuser'});
        $in{'hfile'} || &error($text{'restore_ehfile'});
index add45e7..925b6e8 100755 (executable)
@@ -65,7 +65,8 @@ if ($in{'mode'} == 0) {
        delete($_[0]->{'hfile'});
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+         &to_ip6address($in{'host'}) ||
                &error($text{'dump_ehost'});
        $_[0]->{'host'} = $in{'host'};
        $in{'huser'} =~ /^\S+$/ || &error($text{'dump_ehuser'});
@@ -183,7 +184,8 @@ if ($in{'mode'} == 0) {
        $cmd .= "f '$in{'file'}'";
        }
 else {
-       gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
+       &to_ipaddress($in{'host'}) ||
+           &to_ip6address($in{'host'}) ||
                &error($text{'restore_ehost'});
        $in{'huser'} =~ /^\S*$/ || &error($text{'restore_ehuser'});
        $in{'hfile'} || &error($text{'restore_ehfile'});
index fb36a82..510414f 100755 (executable)
@@ -1430,7 +1430,7 @@ elsif ($in{$f} eq "thishost") {
        $rule->{$f."-thishost"} = 1;
        }
 elsif ($in{$f} eq "host") {
-       gethostbyname($in{$f."_host"}) ||
+       &to_ipaddress($in{$f."_host"}) ||
                &error($text{'save_ehost'.$f});
        $rule->{$f."-host"} = $in{$f."_host"};
        &check_ipaddress($in{$f."_mask"}) ||
@@ -1438,7 +1438,7 @@ elsif ($in{$f} eq "host") {
        $rule->{$f."-mask"} = $in{$f."_mask"};
        }
 elsif ($in{$f} eq "numhost") {
-       gethostbyname($in{$f."_numhost"}) ||
+       &to_ipaddress($in{$f."_numhost"}) ||
                &error($text{'save_ehost'.$f});
        $rule->{$f."-numhost"} = $in{$f."_numhost"};
        $in{$f."_nummask"} = "32" if ($in{$f."_nummask"} eq "");
@@ -1470,7 +1470,7 @@ elsif ($in{$f} eq "thishost") {
        $rule->{$f."-thishost"} = 1;
        }
 elsif ($in{$f} eq "host") {
-       gethostbyname($in{$f."_host"}) ||
+       &to_ipaddress($in{$f."_host"}) ||
                &error($text{'save_ehost'.$f});
        $rule->{$f."-host"} = $in{$f."_host"};
        &check_ipaddress($in{$f."_mask"}) ||
@@ -1478,7 +1478,7 @@ elsif ($in{$f} eq "host") {
        $rule->{$f."-mask"} = $in{$f."_mask"};
        }
 elsif ($in{$f} eq "numhost") {
-       gethostbyname($in{$f."_numhost"}) ||
+       &to_ipaddress($in{$f."_numhost"}) ||
                &error($text{'save_ehost'.$f});
        $rule->{$f."-numhost"} = $in{$f."_numhost"};
        $in{$f."_nummask"} = "32" if ($in{$f."_nummask"} eq "");
index c2b7a28..ec3eb48 100755 (executable)
@@ -39,7 +39,7 @@ local ($server, $port, $user, $pass, $ssl);
 if ($config{'server'}) {
        # Remote box .. everything must be set
        $server = $config{'server'};
-       gethostbyname($server) || return &text('connect_eserver',
+       &to_ipaddress($server) || return &text('connect_eserver',
                                               "<tt>$server</tt>");
        $port = $config{'port'};
        $user = $config{'user'};
index 4fd7d23..e646061 100755 (executable)
@@ -2148,7 +2148,7 @@ elsif ($_[0] eq $smbfs_fs || $_[0] eq "cifs") {
                        delete($options{machinename});
                        if (!$in{smbfs_mname_def})
                                { $options{machinename} = $in{smbfs_mname}; }
-                       elsif (!gethostbyname($in{'smbfs_server'})) {
+                       elsif (!&to_ipaddress($in{'smbfs_server'})) {
                                # No hostname found for the server.. try to guess
                                local($out, $sname);
                                $sname = $in{'smbfs_server'};
@@ -2167,8 +2167,7 @@ elsif ($_[0] eq $smbfs_fs || $_[0] eq "cifs") {
                                }
                        delete($options{"ip"});
                        if (!$in{"smbfs_mname_def"}) {
-                               gethostbyname($in{"smbfs_mname"}) ||
-                                   &check_ipaddress($in{"smbfs_mname"}) ||
+                               &to_ipaddress($in{"smbfs_mname"}) ||
                                        &error($text{'linux_emname'});
                                $options{"ip"} = $in{"smbfs_mname"};
                                }
index 854d861..0bb3c70 100755 (executable)
@@ -546,7 +546,7 @@ $section->add_input($text{'create_domain'}, $dinput);
 
 local (@servers, $server);
 if ($resolv eq "dns") {
-       @servers = map { gethostbyaddr(inet_aton($_), AF_INET) || $_ }
+       @servers = map { &to_ipaddress($_) || &to_ip6address($_) || $_ }
                         @{$dns->{'nameserver'}};
        $server = join(" ", @servers);
        }