<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># $Id: hesiod.pl,v 1.1 2008/01/04 00:52:04 root Exp root $

package hes;

sub make_domain {
    $d = $_[0].$_[1];
    $d .= "." if $d !~ /\.$/;
}

sub get_domain {
    return($domain) if $domain;

    if (open(CONF,"/etc/hesiod.conf")) {
	while(&lt;CONF&gt;) {
	    chop;
	    $lhs = $' if /^lhs=/;
	    $rhs = $' if /^rhs=/;
	}
	close(CONF);
    } else {
	($lhs,$rhs) = (".ns",".athena.mit.edu");
    }

    $domain = &amp;make_domain($lhs,$rhs);
}

sub get_lhs {
    return($lhs) if $lhs;

    &amp;get_domain();

    die "\$lhs is false\n" if !$lhs;

    return($lhs);
}

sub hes_resolve {
  my($name,$type,$dom) = @_;
    local(@ans,@fields);

    if (! $fh) { $fh = &amp;main'res_open(); }
    ($name,$dom) = ($`,$') if $name =~ /@/;
    $dom = $dom?&amp;make_domain(&amp;get_lhs(),".".$dom):&amp;get_domain();

    $query = &amp;main'res_mkquery($name.".".$type.$dom,"TXT","HS");
    @repl = &amp;main'res_send($fh, $query);
    for (0..$repl[7]-1) {
	@fields = split(/ /,$repl[$repl[6]+$_],5);
	push(@ans,$fields[4]) if ($fields[1] eq "TXT" &amp;&amp; $fields[2] eq "HS");
    }
    return(@ans);
}
</pre></body></html>