Beta

Reverse DNS delegation (RFC4183)

Description:

Given a correctly-formatted IPv4 CIDR prefix, return a valid RFC4183 formatted domain name for reverse DNS.

A block of IPv4 addresses (or "prefix") in CIDR notation takes the form:

a.b.c.d/e

where a, b, c, and d are numbers between 0 and 255 inclusive, and e is a number between 0 and 32 inclusive. a, b, c, and d each represent an octet (8 bits) of a 32-bit value in "dotted quad" notation, and e represents the number of fixed bits in the address range. For instance, 192.168.0.0/24 represents the range of addresses from 192.168.0.0 through 192.168.0.255.

Reverse DNS (rDNS) is used to look up what domain name corresponds to a particular IP address. Because DNS was originally designed to do the opposite (look up an IP address given a domain name), rDNS is a bit of a hack. The address has the octets reversed, with the domain name "in-addr.arpa" affixed to it. For instance, the rDNS domain name of 192.168.0.0 would be 0.0.168.192.in-addr.arpa.

For ranges of addresses, this works very neatly if you're dealing with ranges on the octet boundaries, i.e. blocks that end in /0, /8, /16, /24, or /32, because the dots are already in useful places. But if you want to create an rDNS zone that covers any other size of prefix, a bit of hackery is required. There are a few methods for doing this, but one popular method used today is RFC4183, which prepends the block size to the octet on the range boundary with a hyphen.

Examples:

192.168.128.0/25 becomes 0-25.128.168.192.in-addr.arpa. 192.168.128.0/23 becomes 128-23.168.192.in-addr.arpa.

It's also valid to use this technique for ranges on the octet boundary, e.g. 192.168.128.0/24 becomes 0-24.128.168.192.in-addr.arpa.

Note that the final dot is required.

For this exercise, don't bother validating the input. Assume it's a valid prefix that correctly identifies the first address in that block.

For further reading, see:

http://www.ietf.org/rfc/rfc4183.txt

http://en.wikipedia.org/wiki/Reverse_DNS_lookup

Algorithms
Strings

More By Author:

Check out these other kata created by MindWanderer

Stats:

CreatedMar 11, 2015
PublishedMar 12, 2015
Warriors Trained101
Total Skips45
Total Code Submissions103
Total Times Completed21
JavaScript Completions21
Total Stars3
% of votes with a positive feedback rating100% of 12
Total "Very Satisfied" Votes12
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • MindWanderer Avatar
Ad