diff --git a/ddclient b/ddclient index 304d06d..9e15ff0 100755 --- a/ddclient +++ b/ddclient @@ -740,47 +740,58 @@ sub runpostscript { ## update_nics ###################################################################### sub update_nics { - my %examined = (); + my %examined = (); + my %iplist = (); - foreach my $s (sort keys %services) { - my (@hosts, %ips) = (); - my $updateable = $services{$s}{'updateable'}; - my $update = $services{$s}{'update'}; + foreach my $s (sort keys %services) { + my (@hosts, %ips) = (); + my $updateable = $services{$s}{'updateable'}; + my $update = $services{$s}{'update'}; + foreach my $h (sort keys %config) { + next if $config{$h}{'protocol'} ne lc($s); + $examined{$h} = 1; + my $use = $config{$h}{'use'} || opt('use'); + local $opt{$use} = $config{$h}{$use} if $config{$h}{$use}; + # bug #13: we should only do this once + # use isn't enough, we have to save the origin to. + # this will break the multiple ip stuff if use has + # been used twice for the same device. + my $ip = ""; + if (defined $iplist{$use}) { + $ip = $iplist{$use}; + } else { + $ip = get_ip($use, $h); + if (!defined $ip || !$ip) { + warning("unable to determine IP address") + if !$daemon || opt('verbose'); + next; + } + if ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { + warning("malformed IP address (%s)", $ip); + next; + } + $iplist{$use} = $ip; + } + $config{$h}{'wantip'} = $ip; + next if !nic_updateable($h, $updateable); + push @hosts, $h; + $ips{$ip} = $h; + } + if (@hosts) { + $0 = sprintf("%s - updating %s", $program, join(',', @hosts)); + &$update(@hosts); + runpostscript(join ' ', keys %ips); + } + } foreach my $h (sort keys %config) { - next if $config{$h}{'protocol'} ne lc($s); - $examined{$h} = 1; - my $use = $config{$h}{'use'} || opt('use'); - local $opt{$use} = $config{$h}{$use} if $config{$h}{$use}; - my $ip = get_ip($use, $h); - if (!defined $ip || !$ip) { - warning("unable to determine IP address") - if !$daemon || opt('verbose'); - next; - } - if ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { - warning("malformed IP address (%s)", $ip); - next; - } - $config{$h}{'wantip'} = $ip; - next if !nic_updateable($h, $updateable); - push @hosts, $h; - $ips{$ip} = $h; + if (!exists $examined{$h}) { + failed("%s was not updated because protocol %s is not supported.", + $h, define($config{$h}{'protocol'}, '') + ); + } } - if (@hosts) { - $0 = sprintf("%s - updating %s", $program, join(',', @hosts)); - &$update(@hosts); - runpostscript(join ' ', keys %ips); - } - } - foreach my $h (sort keys %config) { - if (!exists $examined{$h}) { - failed("%s was not updated because protocol %s is not supported.", - $h, define($config{$h}{'protocol'}, '') - ); - } - } - write_cache(opt('cache')); + write_cache(opt('cache')); } ###################################################################### ## unlink_pid()