diff --git a/ddclient b/ddclient
index 94d04bd..0c4cae0 100755
--- a/ddclient
+++ b/ddclient
@@ -34,7 +34,7 @@ my $cachedir  = ($program =~ /test/i) ? './'   : '/var/cache/ddclient/';
 my $savedir   = ($program =~ /test/i) ? 'URL/' : '/tmp/';
 my $msgs      = '';
 my $last_msgs = '';
-
+my $use_ipv6  = 0;
 use vars qw($file $lineno);
 local $file   = '';
 local $lineno = '';
@@ -366,7 +366,7 @@ my %variables = (
 	'password'            => setv(T_PASSWD, 1, 0, 1, '',                  undef),
 	'host'                => setv(T_STRING, 1, 1, 1, '',                  undef),
 
-	'use'                 => setv(T_USE,   0, 0, 1, 'ip',                 undef),
+	'use'                 => setv(T_USE,   0, 0, 1, undef,                 undef),
 	'if'                  => setv(T_IF,    0, 0, 1, 'ppp0',               undef),
 	'usev6'               => setv(T_USE,   0, 0, 1, undef,                undef),
 	'if-skip'             => setv(T_STRING,0, 0, 1, '',                   undef),
@@ -774,54 +774,79 @@ sub update_nics {
 		my $updateable = $services{$s}{'updateable'};
 		my $update     = $services{$s}{'update'};
 		my $ipv6 = 0;
+		my $ipv4 = 0;
 
 		foreach my $h (sort keys %config) {
 			next if $config{$h}{'protocol'} ne lc($s);
 			$examined{$h} = 1;
 			my $use = '';
-		        $ipv6 = 1 if (defined $config{$h}{'usev6'});
-			if ($ipv6) {
-			    $use = $config{$h}{'usev6'} || opt('usev6');
-			}
-			else {
-			    $use = $config{$h}{'use'} || opt('use');
-			}
+			$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 !$ipv6;
-				$ip = get_ipv6($use, $h) if $ipv6;
-				if (!defined $ip || !$ip) {
-					warning("unable to determine IP address")
-						if !$daemon || opt('verbose');
-					next;
-				}
-				if (!$ipv6 and $ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
-					warning("malformed IP address (%s)", $ip);
-					next;
-				}
-				if ($ipv6 and $ip !~ /^[0-9a-f:]+$/) {
-					warning("malformed IPv6 address (%s)", $ip);
-					next;
-				}
-				$iplist{$use} = $ip;
-			}
-			$config{$h}{'wantip'} = $ip;
-			next if !nic_updateable($h, $updateable);
-			push @hosts, $h;
-			$ips{$ip} = $h;
-		}
+		    $ipv4 = 1 if (defined $config{$h}{'use'});
+            if($ipv4)
+            {
+                print "use ipv4 ";
+                if (defined $iplist{$use}) {
+                    $ip = $iplist{$use};
+                } else {
+                    $ip = get_ip($use, $h) if !$ipv6;
+                    if (!defined $ip || !$ip) {
+                        warning("unable to determine IP address")
+                            if !$daemon || opt('verbose');
+                    }
+                    elsif ( $ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+                        warning("malformed IP address (%s)", $ip);
+                        next;
+                    }
+                }
+                if($ip)
+                {
+                    $iplist{$use} = $ip;
+                    $config{$h}{'wantip'} = $ip;
+                    next if !nic_updateable($h, $updateable);
+                }
+            }
+            $ipv6 = 1 if (defined $config{$h}{'usev6'});
+            if ($ipv6)
+            {
+                $use = $config{$h}{'usev6'} || opt('usev6');
+                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.
+                $ip = "";
+                $ip = get_ipv6($use, $h) if $ipv6;
+
+                if (!defined $ip || !$ip) {
+                    warning("unable to determine IP address")
+                        if !$daemon || opt('verbose');
+                }
+                elsif ($ipv6 and $ip !~ /^[0-9a-f:]+$/) {
+                    warning("malformed IPv6 address (%s)", $ip);
+                    next;
+                }
+                if($ip)
+                {
+                    $iplist{$use} = $ip;
+                    $config{$h}{'wantipv6'} = $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) {
 		if (!exists $examined{$h}) {
@@ -1889,14 +1914,30 @@ sub geturl {
             Timeout => opt('timeout'),
         );
 	    defined $sd or warning("cannot connect to $peer:$port socket: $@ " . IO::Socket::SSL::errstr());
-    } else {
-	    $sd = IO::Socket::INET->new(
-            PeerAddr => $peer,
-            PeerPort => $port,
-            Proto => 'tcp',
-            MultiHomed => 1,
-            Timeout => opt('timeout'),
-        );
+    }
+    else 
+    {
+       if( $use_ipv6 == 0)
+        {
+          $sd = IO::Socket::INET->new(
+                PeerAddr => $peer,
+                PeerPort => $port,
+                Proto => 'tcp',
+                MultiHomed => 1,
+                Timeout => opt('timeout'),
+                );
+        }
+       else
+       {
+         $sd = IO::Socket::INET->new(
+               Domain    => AF_INET6,
+               PeerAddr => $peer,
+               PeerPort => $port,
+               Proto => 'tcp',
+               MultiHomed => 1,
+               Timeout => opt('timeout'),
+               );
+       }
 	    defined $sd or warning("cannot connect to $peer:$port socket: $@");
     }
 
@@ -2206,7 +2247,7 @@ sub nic_updateable {
 	);
 	$update = 1;
 
-    } elsif ((!exists($cache{$host}{'ip'})) ||
+    }elsif ((!exists($cache{$host}{'ip'})) ||
 		    ("$cache{$host}{'ip'}" ne "$ip")) {
 	    if (($cache{$host}{'status'} eq 'good') && 
 			    !interval_expired($host, 'mtime', 'min-interval')) {
@@ -2221,7 +2262,7 @@ sub nic_updateable {
 		if opt('verbose') || !define($cache{$host}{'warned-min-interval'}, 0);
 
 	    $cache{$host}{'warned-min-interval'} = $now;
-	    
+         
 	} elsif (($cache{$host}{'status'} ne 'good') && !interval_expired($host, 'atime', 'min-error-interval')) {
 
 	    warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.", 
@@ -2269,7 +2310,6 @@ sub nic_updateable {
 	delete $cache{$host}{'warned-min-interval'};
 	delete $cache{$host}{'warned-min-error-interval'};
     }
-	    
     return $update;
 }
 ######################################################################
@@ -2486,8 +2526,13 @@ sub nic_dyndns2_update {
 	my @hosts = @{$groups{$sig}};
 	my $hosts = join(',', @hosts);
 	my $h     = $hosts[0];
-	my $ip    = $config{$h}{'wantip'};
+	my $ip    = "";
+	my $ip6   = "";
+   
+	$ip    = $config{$h}{'wantip'};
+	$ip6   = $config{$h}{'wantipv6'};
 	delete $config{$_}{'wantip'} foreach @hosts;
+	delete $config{$_}{'wantipv6'} foreach @hosts;
 
 	info("setting IP address to %s for %s", $ip, $hosts);
 	verbose("UPDATE:","updating %s", $hosts);
@@ -2510,10 +2555,23 @@ sub nic_dyndns2_update {
 	    $url .= 'dyndns';
 	}
 
-	$url  .= "&hostname=$hosts";
-	$url  .= "&myip=";
-	$url  .= $ip            if $ip;
-
+    $url  .= "&hostname=$hosts";
+    if($ip ne "")
+    {
+        $url  .= "&myip=";
+        $url  .= $ip;
+    }
+    if($ip6 ne "")
+    {
+        $url  .= "&myip=";
+        $url  .= $ip6;
+        if($ip eq "")
+        {
+            $ip = $ip6;
+            $use_ipv6 = 1;
+        }
+    }
+	info("setting IP address to %s for %s", $ip, $hosts);
 	## some args are not valid for a custom domain.
 	$url  .= "&wildcard=ON" if ynu($config{$h}{'wildcard'}, 1, 0, 0);
 	if ($config{$h}{'mx'}) {
