in reply to deconstructing tinydns(djbdns) SRV records
Corion is right that if there is an appropriate module to do this for you, you should use that. <update> For example as VinsWorldcom demonstrated here. </update>
If it turns out you do need to do this yourself, here are two ideas based on unpack (templates explained in perlpacktut and pack) and regexes. The first is a little more robust in its parsing, the second a little shorter and simpler.
my $data = "\000\012\000\144\023\304\003pbx\007example\003com\000:3600 +"; my ($pri,$weight,$port,$rest) = unpack "S>3A*", $data; my $target=''; $target .= (length($target)?'.':'').$2 while $rest=~/\G([\x01-\xFF])((??{".{".ord($1)."}"}))/saagc; my ($ttl) = $rest=~/\G\x00:(.+)\z/saagc or die "failed to parse"; # - OR - my ($pri,$weight,$port,$target,$ttl) = unpack "S>3Z*A*", $data; $target = join '.', unpack "(C/A)*", $target; $ttl=~s/\A://;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: deconstructing tinydns(djbdns) SRV records
by 0xdeadbad (Novice) on Aug 25, 2017 at 10:52 UTC |