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

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


albertel		Thu Sep  1 02:45:33 2005 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - don't looks up educog.com lots and lots of times, once is enough
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.652 loncom/lonnet/perl/lonnet.pm:1.653
--- loncom/lonnet/perl/lonnet.pm:1.652	Thu Sep  1 01:07:35 2005
+++ loncom/lonnet/perl/lonnet.pm	Thu Sep  1 02:45:30 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.652 2005/09/01 05:07:35 albertel Exp $
+# $Id: lonnet.pm,v 1.653 2005/09/01 06:45:30 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5891,19 +5891,26 @@
     }
     close($config);
     # FIXME: dev server don't want this, production servers _do_ want this
-    #&get_iphost();
+    &get_iphost();
 }
 
 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;