From: <jlg...@us...> - 2007-03-08 13:06:37
|
Revision: 92 http://trivial.svn.sourceforge.net/trivial/?rev=92&view=rev Author: jlgeering Date: 2007-03-08 05:06:34 -0800 (Thu, 08 Mar 2007) Log Message: ----------- Better mDNS debug. Modified Paths: -------------- trunk/eclipse/bonjour/src/MCListen.java Modified: trunk/eclipse/bonjour/src/MCListen.java =================================================================== --- trunk/eclipse/bonjour/src/MCListen.java 2007-03-07 16:12:24 UTC (rev 91) +++ trunk/eclipse/bonjour/src/MCListen.java 2007-03-08 13:06:34 UTC (rev 92) @@ -6,7 +6,9 @@ import java.net.MulticastSocket; import java.net.UnknownHostException; +import org.xbill.DNS.Flags; import org.xbill.DNS.Message; +import org.xbill.DNS.Section; public class MCListen { @@ -19,14 +21,51 @@ group = InetAddress.getByName("224.0.0.251"); MulticastSocket s = new MulticastSocket(5353); s.joinGroup(group); -// System.out.println(s.getNetworkInterface().getName()); byte[] buf = new byte[60000]; DatagramPacket recv = new DatagramPacket(buf, buf.length); while (true) { s.receive(recv); Message m = new Message(recv.getData()); -// DNSIncoming truc = new DNSIncoming(recv); - System.out.println(m); + String from = recv.getAddress().getHostAddress() + ":" + recv.getPort(); + // 20.11 RCODE (Response Code) + // In both multicast query and multicast response messages, the Response + // Code MUST be zero on transmission. Multicast DNS messages received + // with non-zero Response Codes MUST be silently ignored. + if (m.getHeader().getRcode() != 0) { + continue; + } + // 20.3 OPCODE + // In both multicast query and multicast response messages, MUST be zero + // (only standard queries are currently supported over multicast, unless + // other queries are allowed by future IETF Standards Action). + if (m.getHeader().getOpcode() != 0) { + System.err.println("OPCODE must be zero."); + continue; + } + // 20.2 QR (Query/Response) Bit + // In query messages, MUST be zero. + // In response messages, MUST be one. + if (m.getHeader().getFlag(Flags.QR)) { + // Response + System.out.println("RESPONSE from " + from); + // Multicast DNS Responses MUST NOT contain any questions in the + // Question Section. Any questions in the Question Section of a received + // Multicast DNS Response MUST be silently ignored. Multicast DNS + // Queriers receiving Multicast DNS Responses do not care what question + // elicited the response; they care only that the information in the + // response is true and accurate. + if (m.getSectionArray(Section.QUESTION).length > 0) { + // Only for debugging: + System.err.println("Response contains questions !"); + } + System.out.println(m.sectionToString(Section.ANSWER)); + } + else { + // Query + System.out.println("QUERY from " + from); + System.out.println(m.sectionToString(Section.QUESTION)); + System.out.println(m.sectionToString(Section.ANSWER)); + } System.out.println("----------------------------------------------------------------------------------------------------------------------------------------------------------"); recv.setLength(buf.length); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |