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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 10 Feb 2005 22:26:38 -0000


albertel		Thu Feb 10 17:26:38 2005 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - be lazy about when we do hostname lookups
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.597 loncom/lonnet/perl/lonnet.pm:1.598
--- loncom/lonnet/perl/lonnet.pm:1.597	Wed Feb  9 17:39:49 2005
+++ loncom/lonnet/perl/lonnet.pm	Thu Feb 10 17:26:38 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.597 2005/02/09 22:39:49 albertel Exp $
+# $Id: lonnet.pm,v 1.598 2005/02/10 22:26:38 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5685,13 +5685,6 @@
        my ($id,$domain,$role,$name)=split(/:/,$configline);
        $name=~s/\s//g;
        if ($id && $domain && $role && $name) {
-	 my $ip = gethostbyname($name);
-	 if (length($ip) ne 4) {
-	     &logthis("Skipping host $id name $name no IP $ip found\n");
-	     next;
-	 }
-	 $ip=inet_ntoa($ip);
-	 push(@{$iphost{$ip}},$id);
 	 $hostname{$id}=$name;
 	 $hostdom{$id}=$domain;
 	 if ($role eq 'library') { $libserv{$id}=$name; }
@@ -5700,6 +5693,21 @@
     close($config);
 }
 
+sub get_iphost {
+    if (%iphost) { return %iphost; }
+    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;
+	}
+	$ip=inet_ntoa($ip);
+	push(@{$iphost{$ip}},$id);
+    }
+    return %iphost;
+}
+
 # ------------------------------------------------------ Read spare server file
 {
     open(my $config,"<$perlvar{'lonTabDir'}/spare.tab");