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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 01 Sep 2005 06:48:09 -0000


albertel		Thu Sep  1 02:48:09 2005 EDT

  Modified files:              (Branch: version_2_0_X)
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - backport 1.652
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.651.2.1 loncom/lonnet/perl/lonnet.pm:1.651.2.2
--- loncom/lonnet/perl/lonnet.pm:1.651.2.1	Wed Aug 31 04:27:38 2005
+++ loncom/lonnet/perl/lonnet.pm	Thu Sep  1 02:48:05 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.651.2.1 2005/08/31 08:27:38 albertel Exp $
+# $Id: lonnet.pm,v 1.651.2.2 2005/09/01 06:48:05 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5887,14 +5887,21 @@
 
 sub get_iphost {
     if (%iphost) { return %iphost; }
+    my %name_to_ip;
     foreach my $id (keys(%hostname)) {
 	my $name=$hostname{$id};
-	my $ip = gethostbyname($name);
-	if (!$ip || length($ip) ne 4) {
-	    &logthis("Skipping host $id name $name no IP found\n");
-	    next;
+	my $ip;
+	if (!exists($name_to_ip{$name})) {
+	    $ip = gethostbyname($name);
+	    if (!$ip || length($ip) ne 4) {
+		&logthis("Skipping host $id name $name no IP found\n");
+		next;
+	    }
+	    $ip=inet_ntoa($ip);
+	    $name_to_ip{$name} = $ip;
+	} else {
+	    $ip = $name_to_ip{$name};
 	}
-	$ip=inet_ntoa($ip);
 	push(@{$iphost{$ip}},$id);
     }
     return %iphost;