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:
Similar Kata:
Stats:
Created | Mar 11, 2015 |
Published | Mar 12, 2015 |
Warriors Trained | 101 |
Total Skips | 45 |
Total Code Submissions | 103 |
Total Times Completed | 21 |
JavaScript Completions | 21 |
Total Stars | 3 |
% of votes with a positive feedback rating | 100% of 12 |
Total "Very Satisfied" Votes | 12 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |