Reverse domain name notation

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Reverse domain name notation (or reverse-DNS) is a naming convention for the components, packages, and types used by a programming language, system or framework. A characteristic of reverse-DNS strings is that they are based on registered domain names, and are only reversed for sorting purposes. For example, if a company making a product called "MyProduct" has the registered domain name "example.com", they could use the reverse-DNS string "com.example.MyProduct" to describe it. Reverse-DNS names are a simple way of reducing name-space collisions, since any domain name is registered by only one party at a time.

History[edit]

Most of the world follows the Internet standard and writes email addresses starting with the name of the computer and ending up with the name of the country. In the U.K.: the Joint Academic Networking Team had decided to do it the other way round before the Internet domain standard was established. Most gateway sites have ad-hockery in their mailers to handle this, but can still be confused. In particular, the address me@uk.ac.bris.pys.as could be interpreted in JANET's big-endian way as one in the U.K. (domain uk) or in the standard little-endian way as one in the domain as (American Samoa) on the opposite side of the world.[1]


Reverse-DNS first became widely used with the Java platform, and has since been used for other systems, for example, ActionScript 3 packages and Android applications.[citation needed]

Examples[edit]

Examples of systems that use reverse-DNS are Sun Microsystems' Java platform and Apple's Uniform Type Identifier or UTI. The Android operating system also makes use of the notation for classifying applications, as the Dalvik virtual machine made use of Java.

dconf which is the configuration back end used by GNOME.

Example of reverse-DNS strings are:

Regular expression[edit]

^[A-Za-z]{2,6}((?!-)\.[A-Za-z0-9-]{1,63}(?<!-))+$

Code[edit]

C#[edit]

static string ReverseDomainName(string domain)
{
    return string.Join(".", domain.Split('.').Reverse());
}

Java 8 and later[edit]

static String reverseDomain(final String domain) {
	final List<String> components = Arrays.asList(domain.split("\\."));
	Collections.reverse(components);
    return String.join(".",  components);
}

JavaScript[edit]

function reverseDomain(domain) {
    return domain.split('.').reverse().join('.');
}

Julia[edit]

reversedomain(d) = join(split(d, ".") |> reverse, ".")

Go[edit]

func reverseDomain(domain string) string {
	s := strings.Split(domain, ".")
	sort.Sort(sort.Reverse(sort.StringSlice(s)))
	return strings.Join(s, ".")
}

PHP[edit]

function reverseDomain($domain) {
    return implode('.', array_reverse(explode('.', $domain)));
}

Python[edit]

def reverse_domain(domain):
    return '.'.join(reversed(domain.split('.')))

Ruby[edit]

def reverse_domain(domain)
  domain.split('.').reverse.join('.')
end

Swift[edit]

func reversed(domain: String) -> String {
    return domain
        .split(separator: ".")
        .reversed()
        .joined(separator: ".")
}

Zsh[edit]

function reverse_domain() {
    echo ${(j:.:)${(Oa)${(s:.:)1}}}
}

Kotlin[edit]

fun reverseDomain(domain: String) = domain.split(".").reversed().joinToString(".")

References[edit]

  1. ^ Jargon File: Big-endian

External links[edit]