public static void parseReverseLookupDomain(PtrDnsAnswer.Builder dnsAnswerBuilder, String hostname) {

        dnsAnswerBuilder.fullDomain(hostname);

        final InternetDomainName internetDomainName = InternetDomainName.from(hostname);
        if (internetDomainName.hasPublicSuffix()) {

            // Use Guava to extract domain name.
            final InternetDomainName topDomainName = internetDomainName.topDomainUnderRegistrySuffix();
            dnsAnswerBuilder.domain(topDomainName.toString());
        } else {

            /* Manually extract domain name.
             * Eg. for hostname test.some-domain.com, only some-domain.com will be extracted. */
            String[] split = hostname.split("\\.");
            if (split.length > 1) {
                dnsAnswerBuilder.domain(split[split.length - 2] + "." + split[split.length - 1]);
            } else if (split.length == 1) {
                dnsAnswerBuilder.domain(hostname); // Domain is a single word with no dots.
            } else {
                dnsAnswerBuilder.domain(""); // Domain is blank.
            }
        }
    }
@Test
    public void testParseReverseLookupDomain() {

        // Test all of the types of domains that parsing is performed for.
        PtrDnsAnswer result = buildReverseLookupDomainTest("subdomain.test.co.uk");
        assertEquals("subdomain.test.co.uk", result.fullDomain());
        assertEquals("test.co.uk", result.domain());

        result = buildReverseLookupDomainTest("subdomain.test.com");
        assertEquals("subdomain.test.com", result.fullDomain());
        assertEquals("test.com", result.domain());

        // Test some completely bogus domain to verify that the manual domain parsing is exercised.
        result = buildReverseLookupDomainTest("blah.blahblah.lala.blaaa");
        assertEquals("blah.blahblah.lala.blaaa", result.fullDomain());
        assertEquals("lala.blaaa", result.domain());

        // Test a single word domain
        result = buildReverseLookupDomainTest("HahaOneWordDomainTryingToBreakTheSoftware");
        assertEquals("HahaOneWordDomainTryingToBreakTheSoftware", result.fullDomain());
        assertEquals("HahaOneWordDomainTryingToBreakTheSoftware", result.domain());
    }