[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Sat, 21 Mar 2009 21:43:46 -0000


raeburn		Sat Mar 21 21:43:46 2009 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Attempt to retrieve IP of DNS server from %name_to_ip first before calling gethostbyname.
  - Move &host_from_dns() subroutine so %name_to_ip is in scope.  
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.991 loncom/lonnet/perl/lonnet.pm:1.992
--- loncom/lonnet/perl/lonnet.pm:1.991	Sat Mar 21 20:56:55 2009
+++ loncom/lonnet/perl/lonnet.pm	Sat Mar 21 21:43:46 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.991 2009/03/21 20:56:55 raeburn Exp $
+# $Id: lonnet.pm,v 1.992 2009/03/21 21:43:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -9046,23 +9046,31 @@
 
 	return %iphost;
     }
-}
 
-#
-#  Given a DNS returns the loncapa host name for that DNS 
-# 
-sub host_from_dns {
-    my ($dns) = @_;
-    my @hosts;
-    my $ip;
-
-    $ip = gethostbyname($dns);	# Initial translation to IP is in net order.
-    if (length($ip) == 4) { 
-	$ip   = &IO::Socket::inet_ntoa($ip);
-	@hosts = get_hosts_from_ip($ip);
-	return $hosts[0];
+    #
+    #  Given a DNS returns the loncapa host name for that DNS 
+    # 
+    sub host_from_dns {
+        my ($dns) = @_;
+        my @hosts;
+        my $ip;
+
+        if (defined($name_to_ip{$dns})) {
+            $ip = $name_to_ip{$dns};
+        }
+        if (!$ip) {
+            $ip = gethostbyname($dns); # Initial translation to IP is in net order.
+            if (length($ip) == 4) { 
+	        $ip   = &IO::Socket::inet_ntoa($ip);
+            }
+        }
+        if ($ip) {
+	    @hosts = get_hosts_from_ip($ip);
+	    return $hosts[0];
+        }
+        return undef;
     }
-    return undef;
+
 }
 
 BEGIN {