ietf-mxcomp
[Top] [All Lists]

Re: suggested new RRtype experiment

2004-05-20 09:35:49

Here is one example using Bind and Net::DNS perl library. Note that I am not a perl programmer, so the encoding/decoding functions (which is most of the code) is not as effective as it can be I guess.

I choose the type code 64999. The record exist for the paf.se owner, and I choose to use the SPF text string as data.

The zone contain the following:

paf.se. 3600 IN TYPE64999 \# 15 763D73706631202B6D78202D616C6C

Encoding is like this:

junior>./encode.pl "v=spf1 +mx -all"
\# 15 763d73706631202b6d78202d616c6c

Querying is like this:

junior>./query.pl paf.se
v=spf1 +mx -all

The encode and query programs follows.

   paf

----- ENCODE -----
#!/usr/bin/perl

($data) = @ARGV;
$s = "";
foreach $i (split(//,$data)) {
    $s = $s . sprintf("%x",ord($i));
    $l++;
}
printf "\\# %d %s\n",$l,$s;

----- QUERY -----
#!/usr/bin/perl

use Net::DNS;

sub parse64999 {
    ($d) = @_;
    ($head, $len, $data) = split(/ /,$d);
    $i = 0;
    $res = "";
    while ($i < (2*$len)) {
        $ch = substr($data,$i,2);
        $res = $res . chr(hex($ch));
        $i+=2;
    }
    return $res;
}

my $res = Net::DNS::Resolver->new;

my $d = $ARGV[0];

my $query = $res->query($d,"TYPE64999");
if ($query) {
    foreach my $rr ($query->answer) {
        next unless $rr->type eq "TYPE64999";
        print parse64999($rr->rdata) . "\n";
    }
} else {
    warn "query failed: ", $res->errorstring, "\n";
}