private void parseRecord(Message message, InetAddress address) { // We really only care about the ADDITIONAL section (specifically the text records) Record[] responses = message.getSectionArray(Section.ADDITIONAL); // We only want to process records that actually have a length, have an ANSWER // section that has stuff in it and that the ANSWER to our query is what we sent if (responses.length != 0 && message.getSectionArray(Section.ANSWER).length != 0 && message .getSectionArray(Section.ANSWER)[0] .getName() .toString() .equals(NvmDNS.MDNS_QUERY)) { Log.v("NvmDNS Response", "Got a packet from " + address.getCanonicalHostName()); Log.v( "NvmDNS Response", "Question: " + message.getSectionArray(Section.ANSWER)[0].getName().toString()); Log.v("NvmDNS Response", "Response: " + responses[0].getName().toString()); // TODO: The DNS entry we get is "XENITH._nvstream._tcp.local." // And the .'s in there are not actually periods. Or something. String hostname = responses[0].getName().toString(); // The records can be returned in any order, so we need to figure out which one is the // TXTRecord // We get three records back: A TXTRecord, a SRVRecord and an ARecord TXTRecord txtRecord = null; for (Record record : responses) { Log.v( "NvmDNS Response", "We recieved a DNS repsonse with a " + record.getClass().getName() + " record."); if (record instanceof TXTRecord) { txtRecord = (TXTRecord) record; } } if (txtRecord == null) { Log.e("NvmDNS Response", "We recieved a malformed DNS repsonse with no TXTRecord"); return; } this.parseTXTRecord(txtRecord, address, hostname); } }