--- loncom/lonnet/perl/lonnet.pm 2009/02/08 20:28:52 1.985 +++ loncom/lonnet/perl/lonnet.pm 2009/02/10 11:15:16 1.986 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.985 2009/02/08 20:28:52 raeburn Exp $ +# $Id: lonnet.pm,v 1.986 2009/02/10 11:15:16 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -74,6 +74,7 @@ use strict; use LWP::UserAgent(); use HTTP::Date; use Image::Magick; +use IO::Socket; # use Date::Parse; use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir @@ -150,7 +151,8 @@ sub logthis { my $now=time; my $local=localtime($now); if (open(my $fh,">>$execdir/logs/lonnet.log")) { - print $fh "$local ($$): $message\n"; + my $logstring = $local. " ($$): ".$message."\n"; # Keep any \'s in string. + print $fh $logstring; close($fh); } return 1; @@ -9010,6 +9012,23 @@ sub get_dns { } } +# +# 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]; + } + return undef; +} + BEGIN { # ----------------------------------- Read loncapa.conf and loncapa_apache.conf @@ -9899,8 +9918,15 @@ dirlist($uri) : return directory list ba spareserver() : find server with least workload from spare.tab + +=item * + +host_from_dns($dns) : Returns the loncapa hostname corresponding to a DNS name or undef +if there is no corresponding loncapa host. + =back + =head2 Apache Request =over 4