Update of /cvsroot/pyxida/AsyncJ/src/edu/harvard/syrah/sbon/async/comm/dns In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21526/src/edu/harvard/syrah/sbon/async/comm/dns Added Files: NSRR.java MGRR.java DNSQuery.java PTRRR.java HINFORR.java TXTRR.java RR.java DNSQuestion.java SOARR.java AAAARR.java DNSCommIF.java WKSRR.java ARR.java NULLRR.java MDRR.java DNSComm.java LICENSE.txt MRRR.java MBRR.java MINFORR.java MXRR.java CNAMERR.java MFRR.java Log Message: Initial commit of AsyncJ project needed for Pyxida --- NEW FILE: MBRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>MB</code> RR record structure mapping. <pre> MB RDATA format (EXPERIMENTAL). +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / MADNAME / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: MADNAME A <domain-name> which specifies a host which has the specified mailbox. MB records cause additional section processing which looks up an A type RRs corresponding to MADNAME. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class MBRR extends CNAMERR { String aname; String cname; int recs = 1; int dlen; int sidx; public MBRR( byte[]pkt, int cidx ) { super(pkt, cidx); } public String getMAdName() { return getCName(); } } --- NEW FILE: ARR.java --- package edu.harvard.syrah.sbon.async.comm.dns; import edu.harvard.syrah.prp.Log; /** * This class provides the <code>A</code> RR record structure mapping. <pre> A RDATA format. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ADDRESS | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: ADDRESS A 32 bit Internet address. Hosts that have multiple Internet addresses will have multiple A records. A records cause no additional section processing. The RDATA section of an A line in a master file is an Internet address expressed as four decimal numbers separated by dots without any imbedded spaces (e.g., "10.2.0.52" or "192.0.5.6"). </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class ARR extends RR { private static final Log log = new Log(ARR.class); String host; String addr; byte[] byteAddr; int recs = 1; int dlen; public String toString() { return host+"\t\t"+super.toString()+"\t"+addr; } public ARR( byte[]pkt, int cidx ) { super(pkt, cidx, DNSQuestion.TYPE_A ); } public String getHost() { return host; } public String getIPAddress() { return addr; } public byte[] getByteIPAddress() { return byteAddr; } public int getRecordCount() { return recs; } public int dataLength() { return dlen; } public void processRecord( int cidx ) { StringBuffer buf = new StringBuffer(); int nmlen = cidx; int fidx = cidx; cidx = RR.extractName( rdata, cidx, rdata.length, buf ); host = buf.toString(); nmlen = cidx - nmlen; cidx = setParameters( rdata, cidx ); int b1 = rdata[cidx++]; int b2 = rdata[cidx++]; int b3 = rdata[cidx++]; int b4 = rdata[cidx++]; addr =(b1 & 0xff) + "." + (b2 & 0xff) + "." + (b3 & 0xff) + "." + (b4 & 0xff); byteAddr = new byte[] {(byte) (b1 & 0xff), (byte) (b2 & 0xff), (byte) (b3 & 0xff), (byte) (b4 & 0xff)}; dlen = cidx - fidx; //log.debug("A dlen=" + dlen); } } --- NEW FILE: AAAARR.java --- package edu.harvard.syrah.sbon.async.comm.dns; import edu.harvard.syrah.prp.Log; /** * * This class provides the <code>AAAA</code> RR record structure mapping. * * * @author Peter Pietzuch - pr...@do... */ public class AAAARR extends RR { private static final Log log = new Log(AAAARR.class); String host; String addrv6; byte[] ipv6; int dlen; public String toString() { return host + "\t\t" + super.toString() + "\t" + ipv6; } public String getIPv6Address() { return addrv6; } public AAAARR(byte[] pkt, int cidx) { super(pkt, cidx, DNSQuestion.TYPE_AAAA); } public byte[] getIPv6() { return ipv6; } public int dataLength() { return dlen; } public void processRecord(int cidx) { StringBuffer buf = new StringBuffer(); int nmlen = cidx; int fidx = cidx; cidx = RR.extractName(rdata, cidx, rdata.length, buf); host = buf.toString(); nmlen = cidx - nmlen; cidx = setParameters(rdata, cidx); int b1 = rdata[cidx++]; int b2 = rdata[cidx++]; int b3 = rdata[cidx++]; int b4 = rdata[cidx++]; int b5 = rdata[cidx++]; int b6 = rdata[cidx++]; int b7 = rdata[cidx++]; int b8 = rdata[cidx++]; int b9 = rdata[cidx++]; int b10 = rdata[cidx++]; int b11 = rdata[cidx++]; int b12 = rdata[cidx++]; int b13 = rdata[cidx++]; int b14 = rdata[cidx++]; int b15 = rdata[cidx++]; int b16 = rdata[cidx++]; addrv6 = (b1 & 0xff) + "." + (b2 & 0xff) + "." + (b3 & 0xff) + "." + (b4 & 0xff) + (b5 & 0xff) + "." + (b6 & 0xff) + "." + (b7 & 0xff) + "." + (b8 & 0xff) + "." + (b9 & 0xff) + "." + (b10 & 0xff) + "." + (b11 & 0xff) + "." + (b12 & 0xff) + "." + (b13 & 0xff) + "." + (b14 & 0xff) + "." + (b14 & 0xff) + "." + (b16 & 0xff); ipv6 = new byte[] { (byte) (b1 & 0xff), (byte) (b2 & 0xff), (byte) (b3 & 0xff), (byte) (b4 & 0xff), (byte) (b5 & 0xff), (byte) (b6 & 0xff), (byte) (b7 & 0xff), (byte) (b8 & 0xff), (byte) (b9 & 0xff), (byte) (b10 & 0xff), (byte) (b11 & 0xff), (byte) (b12 & 0xff), (byte) (b13 & 0xff), (byte) (b14 & 0xff), (byte) (b15 & 0xff), (byte) (b16 & 0xff)}; dlen = cidx - fidx; //log.debug("AAAA dlen=" + dlen); } } --- NEW FILE: MDRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>MD</code> RR record structure mapping. <pre> MD RDATA format (Obsolete). +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / MADNAME / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: MADNAME A <domain-name> which specifies a host which has a mail agent for the domain which should be able to deliver mail for the domain. MD records cause additional section processing which looks up an A type record corresponding to MADNAME. MD is obsolete. See the definition of MX and [RFC-974] for details of the new scheme. The recommended policy for dealing with MD RRs found in a master file is to reject them, or to convert them to MX RRs with a preference of 0. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class MDRR extends CNAMERR { String aname; String cname; int recs = 1; int dlen; int sidx; public MDRR( byte[]pkt, int cidx ) { super(pkt, cidx); } public String getMAdName() { return getCName(); } } --- NEW FILE: CNAMERR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>CNAME</code> RR record structure mapping. <pre> +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / CNAME / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: CNAME A <domain-name> which specifies the canonical or primary name for the owner. The owner name is an alias. CNAME RRs cause no additional section processing, but name servers may choose to restart the query at the canonical name in certain cases. See the description of name server logic in [RFC-1034] for details. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class CNAMERR extends RR { String aname; String cname; int recs = 1; int dlen; int sidx; public String toString() { return aname+"\t\t"+super.toString()+"\t"+cname; } public CNAMERR( byte[]pkt, int cidx ) { super(pkt, cidx, DNSQuestion.TYPE_CNAME ); } public String getHost( ) { return aname; } public String getCName( ) { return cname; } public int getRecordCount() { return recs; } public int dataLength() { return dlen; } public void processRecord( int cidx ) { StringBuffer buf = new StringBuffer(); sidx = cidx; int fcidx = cidx; cidx = RR.extractName( rdata, cidx, rdata.length, buf ); aname = buf.toString(); cidx = setParameters(rdata, cidx); buf.setLength(0); cidx = RR.extractName( rdata, cidx, rdata.length, buf ); dlen = (cidx - fcidx); cname = buf.toString(); } } --- NEW FILE: TXTRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>TXT</code> RR record structure mapping. <pre> TXT RDATA format. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / TXT-DATA / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: TXT-DATA One or more <character-string>s. TXT RRs are used to hold descriptive text. The semantics of the text depends on the domain where it is found. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class TXTRR extends RR { protected String aname; protected String text; protected byte data[]; protected int dlen; protected int sidx; public String toString() { if( text == null ) text = new String(data); return aname+"\t\t"+super.toString()+"\t"+text; } public TXTRR( byte[]pkt, int cidx ) { super(pkt, cidx, DNSQuestion.TYPE_TXT ); } public String getText( ) { if( text == null ) text = new String(data); return text; } public int dataLength() { return dlen; } public void processRecord( int cidx ) { StringBuffer buf = new StringBuffer(); sidx = cidx; int fcidx = cidx; cidx = RR.extractName( rdata, cidx, rdata.length, buf ); aname = buf.toString(); cidx = setParameters(rdata, cidx); buf.setLength(0); data = new byte[ rdlength ]; int cnt = 0; while( cnt < rdlength ) { int l = rdata[cnt+cidx] & 0xff; for( int i = 0; i < l; ++i ) buf.append( (char)rdata[cnt+cidx+1+i] ); buf.append(' '); cnt += l + 1; } cidx += rdlength; data = buf.toString().getBytes(); dlen = (cidx - fcidx); } } --- NEW FILE: LICENSE.txt --- Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --- NEW FILE: MFRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>MF</code> RR record structure mapping. <pre> MF RDATA format (Obsolete). +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / MADNAME / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: MADNAME A <domain-name> which specifies a host which has a mail agent for the domain which will accept mail for forwarding to the domain. MF records cause additional section processing which looks up an A type record corresponding to MADNAME. MF is obsolete. See the definition of MX and [RFC-974] for details ofw the new scheme. The recommended policy for dealing with MD RRs found in a master file is to reject them, or to convert them to MX RRs with a preference of 10. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class MFRR extends CNAMERR { String aname; String cname; int recs = 1; int dlen; int sidx; public MFRR( byte[]pkt, int cidx ) { super(pkt, cidx); } public String getMAdName() { return getCName(); } } --- NEW FILE: DNSQuestion.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** * This class wraps the 3 pieces of information needed to execute a DNS query. * The string value of concern (a domain structured name) and then the type * and class of query. <p> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class DNSQuestion { protected byte data[]; protected int len; protected String name; protected int qtype; protected int qclass; /** The Internet class */ public static final int CLASS_IN = 1; /** The "A" record/query type. */ public static final int TYPE_A = 1; /** The "NS" record/query type. */ public static final int TYPE_NS = 2; /** The "MD" record/query type. */ public static final int TYPE_MD = 3; /** The "MF" record/query type. */ public static final int TYPE_MF = 4; /** The "CNAME" record/query type. */ public static final int TYPE_CNAME = 5; /** The "SOA" record/query type. */ public static final int TYPE_SOA = 6; /** The "MB" record/query type. */ public static final int TYPE_MB = 7; /** The "MG" record/query type. */ public static final int TYPE_MG = 8; /** The "MR" record/query type. */ public static final int TYPE_MR = 9; /** The "NULL" record/query type. */ public static final int TYPE_NULL = 10; /** The "WKS" record/query type. */ public static final int TYPE_WKS = 11; /** The "PTR" record/query type. */ public static final int TYPE_PTR = 12; /** The "HINFO" record/query type. */ public static final int TYPE_HINFO = 13; /** The "MINFO" record/query type. */ public static final int TYPE_MINFO = 14; /** The "MX" record/query type. */ public static final int TYPE_MX = 15; /** The "TXT" record/query type. */ public static final int TYPE_TXT = 16; /** The "AAAA" record/query type. */ public static final int TYPE_AAAA = 28; /** * Formats a time in seconds into a string describing the amount of * time indicated. * * e.g. 601 becomes "10m1s" for 10 minutes 1 second. */ public static String toTime( int ttl ) { String buf = ""; while( ttl > 0 ) { int v = 0; if( ttl < 60 ) { buf += ttl+"s"; ttl = 0; } else if( ttl < 3600 ) { v = ttl / (60); buf += v+"m"; ttl = ttl % 60; } else if( ttl < 3600 * 24 ) { v = ttl / 3600; buf += v+"h"; ttl = ttl % 3600; } else if( ttl < (3600 * 24 * 7) ) { v = ttl / (3600 * 24); buf += v+"d"; ttl = ttl % (3600 * 24); } else { v = ttl / (3600 * 24 * 7); buf += v+"w"; ttl = ttl % (3600*24 * 7); } } return buf; } /** Formats the question data to a descriptive string */ public String toString() { return toType(qtype)+"["+toClass(qclass)+"] for "+name; } /** * Returns a string describing the indicated CLASS_* value. * currently only IN is supported */ public static String toClass( int cls ) { String buf = ""+cls; if( cls == CLASS_IN ) buf = "IN"; return buf; } /** * Translates one of the TYPE_* values into a string * that is the part after the TYPE_ part of the variable * name. */ public static String toType( int type ) { return RR.toType( type ); } /** * Used to change the name to reuse this Question for another query. * * @param name the name string to ask a question about. */ public void setName( String name ) { this.name = name; } /** * Used to change the type to reuse this Question for another query. * @param type one of the TYPE_* values. */ public void setType( int type ) { this.qtype = type; } /** * Used to change the class to reuse this Question for another query. * @param cls one of the CLASS_* values */ public void setClass( int cls ) { this.qclass = cls; } /** * Constructs a new Question. The query data is formatted * from this constructor and placed into the <code>data</code> * buffer. * * @param name the domain string to query about * @param qtype one of the TYPE_* query types. * @param qclass one of the CLASS_* values. */ public DNSQuestion( String name, int qtype, int qclass ) { int nlen = RR.nameLength(name); this.name = name; this.qtype = qtype; this.qclass = qclass; data = new byte[nlen + 4]; RR.copyInName( data, 0, name ); data[ nlen ] = (byte)(qtype>>8); data[ nlen+1 ] = (byte)(qtype & 0xff); data[ nlen+2 ] = (byte)(qclass>>8); data[ nlen+3 ] = (byte)(qclass & 0xff); len = nlen+4; } /** * Returns the total length in bytes of the query data buffer */ public int length() { return len; } /** Returns the data buffer for the query */ public byte[] getData() { return data; } } --- NEW FILE: MXRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>MX</code> RR record structure mapping. <pre> MX RDATA format. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | PREFERENCE | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / EXCHANGE / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: PREFERENCE A 16 bit integer which specifies the preference given to this RR among others at the same owner. Lower values are preferred. EXCHANGE A <domain-name> which specifies a host willing to act as a mail exchange for the owner name. MX records cause type A additional section processing for the host specified by EXCHANGE. The use of MX RRs is explained in detail in [RFC-974]. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class MXRR extends RR { int pref; String mxname; String mxfor; int dlen; int sidx; public String toString() { return mxfor+"\t\t"+super.toString()+"\t "+pref+" "+mxname; } public MXRR( byte[]pkt, int cidx ) { super(pkt, cidx, DNSQuestion.TYPE_MX ); } public int getPreference() { return pref; } public String getExchanger() { return mxname; } public int dataLength() { return dlen; } public void processRecord( int cidx ) { StringBuffer buf = new StringBuffer(); sidx = cidx; int fcidx = cidx; cidx = RR.extractName( rdata, cidx, rdata.length, buf ); mxfor = buf.toString(); cidx = setParameters(rdata, cidx); pref = ((rdata[cidx]&0xff)<<8) | (rdata[cidx+1]&0xff); cidx += 2; // preference buf.setLength(0); cidx = RR.extractName( rdata, cidx, rdata.length, buf ); dlen = (cidx - fcidx); mxname = buf.toString(); } } --- NEW FILE: HINFORR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>HINFO</code> RR record structure mapping. <pre> HINFO RDATA format. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / CPU / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / OS / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: CPU A <character-string> which specifies the CPU type. OS A <character-string> which specifies the operating system type. Standard values for CPU and OS can be found in [RFC 1010]. HINFO records are used to acquire general information about a host. The main use is for protocols such as FTP that can use special procedures when talking between machines or operating systems of the same type. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class HINFORR extends RR { String aname; String cpu; String os; int dlen; int sidx; public String toString() { return aname+"\t\t"+super.toString()+"\t"+cpu+" running "+os; } public HINFORR( byte[]pkt, int cidx ) { super(pkt, cidx, DNSQuestion.TYPE_HINFO ); } public String getCPU( ) { return cpu; } public String getOS( ) { return os; } public int dataLength() { return dlen; } public void processRecord( int cidx ) { StringBuffer buf = new StringBuffer(); sidx = cidx; int fcidx = cidx; cidx = RR.extractName( rdata, cidx, rdata.length, buf ); aname = buf.toString(); cidx = setParameters(rdata, cidx); buf.setLength(0); int len = rdata[cidx++] & 0xff; for( int i = 0; i < len; ++i ) buf.append( (char)rdata[i+cidx] ); cidx += len; cpu = buf.toString(); buf.setLength(0); len = rdata[cidx++] & 0xff; for( int i = 0; i < len; ++i ) buf.append( (char)rdata[i+cidx] ); os = buf.toString(); cidx += len; dlen = (cidx - fcidx); } } --- NEW FILE: WKSRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; import java.io.IOException; import java.net.InetAddress; import java.util.Enumeration; import java.util.Vector; /** This class provides the <code>WKS</code> RR record structure mapping. <pre> WKS RDATA format. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | 0 1 2 3 4 5 6 ADDRESS 10 11 12 13 14 15| +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | PROTOCOL | | +--+--+--+--+--+--+--+--+ | | | / <BIT MAP> / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: ADDRESS - An 32 bit ARPA Internet address PROTOCOL - An 8 bit IP protocol number <BIT MAP> - A variable length bit map. The bit map must be a multiple of 8 bits long. The WKS record is used to describe the well known services supported by a particular protocol on a particular internet address. The PROTOCOL field specifies an IP protocol number, and the bit map has one bit per port of the specified protocol. The first bit corresponds to port 0, the second to port 1, etc. If less than 256 bits are present, the remainder are assumed to be zero. The appropriate values for ports and protocols are specified in [13]. For example, if PROTOCOL=TCP (6), the 26th bit corresponds to TCP port 25 (SMTP). If this bit is set, a SMTP server should be listening on TCP port 25; if zero, SMTP service is not supported on the specified address. The anticipated use of WKS RRs is to provide availability information for servers for TCP and UDP. If a server supports both TCP and UDP, or has multiple Internet addresses, then multiple WKS RRs are used. WKS RRs cause no additional section processing. The RDATA section of a WKS record consists of a decimal protocol number followed by mnemonic identifiers which specify bits to be set to 1. </pre> <hr> Copyright (c) 2001-2005, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class WKSRR extends RR { String host; String addr; int recs = 1; int dlen; int proto; Vector<Integer> ports; public String toString() { return host+"\t\t"+super.toString()+"\t"+addr+", proto="+proto+", ports="+ports; } public WKSRR( byte[]pkt, int cidx ) { super(pkt, cidx, DNSQuestion.TYPE_WKS ); } public String getHost() { return host; } public InetAddress getHostAddress() throws IOException { return InetAddress.getByName( addr ); } public int getRecordCount() { return recs; } public int dataLength() { return dlen; } public Enumeration getPortsList() { return ports.elements(); } public void processRecord( int cidx ) { ports = new Vector<Integer>(10); StringBuffer buf = new StringBuffer(); int nmlen = cidx; int fidx = cidx; cidx = RR.extractName( rdata, cidx, rdata.length, buf ); host = buf.toString(); nmlen = cidx - nmlen; cidx = setParameters( rdata, cidx ); int b1 = rdata[cidx++]; int b2 = rdata[cidx++]; int b3 = rdata[cidx++]; int b4 = rdata[cidx++]; addr =(b1&0xff)+"."+ (b2&0xff)+"."+ (b3&0xff)+"."+ (b4&0xff); proto = rdata[cidx++] & 0xff; int cnt = rdlength - 5; for( int i = 0; i < cnt; ++i ) { int v = rdata[i + cidx] & 0xff; // System.out.println("data["+(i+cidx)+"]: "+v ); for( int j = 7; j >= 0; --j ) { int bit = (i * 8) + (7-j); // System.out.println( "bit no: "+bit+", set? "+(v & (1<<j))); if( (v & (1<<j)) != 0 ) { ports.addElement( new Integer( bit ) ); } } } dlen = (cidx - fidx) + cnt; } } --- NEW FILE: MGRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>MG</code> RR record structure mapping. <pre> MG RDATA format (EXPERIMENTAL). +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / MGMNAME / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: MGMNAME A <domain-name> which specifies a mailbox which is a member of the mail group specified by the domain name. MG records cause no additional section processing. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class MGRR extends CNAMERR { String emailbx; public MGRR( byte[]pkt, int cidx ) { super(pkt, cidx); } public String getRMailBX() { return getCName(); } public String getEMailBX() { return emailbx; } public void processRecord( int cidx ) { int fcidx = cidx; super.processRecord( cidx ); cidx += dlen; // StringBuffer buf = new StringBuffer(); // cidx = RR.extractName( rdata, cidx, rdata.length, buf ); // emailbx = buf.toString(); dlen = (cidx - fcidx); } } --- NEW FILE: SOARR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>SOA</code> RR record structure mapping. <pre> SOA RDATA format. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / MNAME / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / RNAME / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | SERIAL | | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | REFRESH | | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | RETRY | | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | EXPIRE | | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | MINIMUM | | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: MNAME The <domain-name> of the name server that was the original or primary source of data for this zone. RNAME A <domain-name> which specifies the mailbox of the person responsible for this zone. SERIAL The unsigned 32 bit version number of the original copy of the zone. Zone transfers preserve this value. This value wraps and should be compared using sequence space arithmetic. REFRESH A 32 bit time interval before the zone should be refreshed. RETRY A 32 bit time interval that should elapse before a failed refresh should be retried. EXPIRE A 32 bit time value that specifies the upper limit on the time interval that can elapse before the zone is no longer authoritative. MINIMUM The unsigned 32 bit minimum TTL field that should be exported with any RR from this zone. SOA records cause no additional section processing. All times are in units of seconds. Most of these fields are pertinent only for name server maintenance operations. However, MINIMUM is used in all query operations that retrieve RRs from a zone. Whenever a RR is sent in a response to a query, the TTL field is set to the maximum of the TTL field from the RR and the MINIMUM field in the appropriate SOA. Thus MINIMUM is a lower bound on the TTL field for all RRs in a zone. Note that this use of MINIMUM should occur when the RRs are copied into the response and not when the zone is loaded from a master file or via a zone transfer. The reason for this provison is to allow future dynamic update facilities to change the SOA RR with known semantics. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class SOARR extends RR { String rname; String mname; String dname; int recs = 1; int dlen; int serial; int refresh; int retry; int expire; int minimum; public String toString() { return dname+"\t\t"+super.toString()+"\t"+mname+", "+rname+"\n"+ " SERIAL "+serial+"\n"+ " REFRESH "+DNSQuestion.toTime(refresh)+"\n"+ " RETRY "+DNSQuestion.toTime(retry)+"\n"+ " EXPIRE "+DNSQuestion.toTime(expire)+"\n"+ " MINIMUM "+DNSQuestion.toTime(minimum) ; } public SOARR( byte[]pkt, int cidx ) { super(pkt, cidx, DNSQuestion.TYPE_SOA); } public String getNSHost() { return mname; } public String getResponsibleEmail() { return rname; } public int getRecordCount() { return recs; } public int dataLength() { return dlen; } public void processRecord( int cidx ) { StringBuffer buf = new StringBuffer(); int fidx = cidx; cidx = extractName( rdata, cidx, rdata.length, buf ); dname = buf.toString(); cidx = setParameters( rdata, cidx ); buf.setLength(0); cidx = extractName( rdata, cidx, rdata.length, buf ); mname = buf.toString(); buf.setLength(0); cidx = RR.extractName( rdata, cidx, rdata.length, buf ); rname = buf.toString(); serial = ((rdata[cidx]&0xff) << 24) | ((rdata[cidx+1] & 0xff)<<16) | ((rdata[cidx+2]&0xff) << 8) | (rdata[cidx+3] & 0xff); cidx += 4; refresh = ((rdata[cidx]&0xff) << 24) | ((rdata[cidx+1] & 0xff)<<16) | ((rdata[cidx+2]&0xff) << 8) | (rdata[cidx+3] & 0xff); cidx += 4; retry = ((rdata[cidx]&0xff) << 24) | ((rdata[cidx+1] & 0xff)<<16) | ((rdata[cidx+2]&0xff) << 8) | (rdata[cidx+3] & 0xff); cidx += 4; expire = ((rdata[cidx]&0xff) << 24) | ((rdata[cidx+1] & 0xff)<<16) | ((rdata[cidx+2]&0xff) << 8) | (rdata[cidx+3] & 0xff); cidx += 4; minimum = ((rdata[cidx]&0xff) << 24) | ((rdata[cidx+1] & 0xff)<<16) | ((rdata[cidx+2]&0xff) << 8) | (rdata[cidx+3] & 0xff); cidx += 4; dlen = cidx - fidx; // System.out.println("cidx: "+cidx); } } --- NEW FILE: MRRR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>MR</code> RR record structure mapping. <pre> MR RDATA format (EXPERIMENTAL). +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / NEWNAME / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: NEWNAME A <domain-name> which specifies a mailbox which is the proper rename of the specified mailbox. MR records cause no additional section processing. The main use for MR is as a forwarding entry for a user who has moved to a different mailbox. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class MRRR extends CNAMERR { String emailbx; public String toString() { return aname+"\t\t"+super.toString()+"\t"+cname; } public MRRR( byte[]pkt, int cidx ) { super(pkt, cidx); } public void processRecord( int cidx ) { int fcidx = cidx; super.processRecord( cidx ); cidx += dlen; StringBuffer buf = new StringBuffer(); cidx = RR.extractName( rdata, cidx, rdata.length, buf ); emailbx = buf.toString(); dlen = (cidx - fcidx); } } --- NEW FILE: MINFORR.java --- package edu.harvard.syrah.sbon.async.comm.dns; /** This class provides the <code>MINFO</code> RR record structure mapping. <pre> MINFO RDATA format (EXPERIMENTAL). +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / RMAILBX / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ / EMAILBX / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ where: RMAILBX A <domain-name> which specifies a mailbox which is responsible for the mailing list or mailbox. If this domain name names the root, the owner of the MINFO RR is responsible for itself. Note that many existing mailing lists use a mailbox X-request for the RMAILBX field of mailing list X, e.g., Msgroup-request for Msgroup. This field provides a more general mechanism. EMAILBX A <domain-name> which specifies a mailbox which is to receive error messages related to the mailing list or mailbox specified by the owner of the MINFO RR (similar to the ERRORS-TO: field which has been proposed). If this domain name names the root, errors should be returned to the sender of the message. MINFO records cause no additional section processing. Although these records can be associated with a simple mailbox, they are usually used with a mailing list. </pre> <hr> Copyright (c) 2001-2004, Gregg Wonderly All rights reserved. <p> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: <p> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. <p> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. <p> Neither the name of Gregg Wonderly nor the names of contributors to this software may be used to endorse or promote products derived from this software without specific prior written permission. <p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Gregg Wonderly - gre...@po... */ public class MINFORR extends CNAMERR { String emailbx; public String toString() { return super.toString()+", "+emailbx; } public MINFORR( byte[]pkt, int cidx ) { super(pkt, cidx); } public String getRMailBX() { return getCName(); } public String getEMailBX() { return emailbx; } public void processRecord( int cidx ) { int fcidx = cidx; super.processRecord( cidx ); cidx += dlen; StringBuffer buf = new StringBuffer(); cidx = RR.extractName( rdata, cidx, rdata.length, buf ); emailbx = buf.toString(); dlen = (cidx - fcidx); } } --- NEW FILE: DNSComm.java --- /* * @author Last modified by $Author: prp $ * @version $Revision: 1.1 $ on $Date: 2007/06/04 17:55:40 $ * @since Aug 10, 2005 */ package edu.harvard.syrah.sbon.async.comm.dns; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.*; import sun.net.dns.ResolverConfiguration; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.prp.NetUtil; import edu.harvard.syrah.prp.PUtil; import edu.harvard.syrah.sbon.async.CBResult; import edu.harvard.syrah.sbon.async.EL; import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.async.EL.Priority; import edu.harvard.syrah.sbon.async.comm.*; /** * Communication module for DNS * */ public class DNSComm extends UDPComm implements DNSCommIF { protected static final Log log = new Log(DNSComm.class); private static final long START_DNS_TIMEOUT = 1000; // 1000 ms private Map<String, Integer> dnsCache = new HashMap<String, Integer>(); private Map<Integer, String> reverseDNSCache = new HashMap<Integer, String>(); int MAX_DNS_RETRY_COUNT = 10; private Set<AddressIF> dnsServerList; public DNSComm() { super(Priority.NORMAL); log.debug("Initialising DNSComm..."); } @SuppressWarnings("unchecked") public void initServer(CB0 cbInit) { List<String> nsList = ResolverConfiguration.open().nameservers(); // log.debug("dnsServers=" + Util.toString(nsList)); dnsServerList = new HashSet<AddressIF>(); int i; for (i = 0; i < nsList.size(); i++) { dnsServerList.add(AddressFactory.createUnresolved(nsList.get(i), 53)); } log.debug("Initialising DNSComm with " + i + " DNS servers: " + dnsServerList); // dnsServer = AddressFactory.createUnresolved("192.168.5.10", 53); // Bind this to the wildcard address - does this mean that we'll see all UDP // packets? // AddressIF localBindAddress = AddressFactory.createServer(0); // super.initServer(localBindAddress, cbInit); } public void getHostByName(final String hostname, final CB1<InetAddress> cbInetAddress) { getIPAddrByName(hostname, new CB1<byte[]>() { protected void cb(CBResult result, byte[] byteIPAddr) { switch (result.state) { case OK: { InetAddress ipAddr = null; try { ipAddr = InetAddress.getByAddress(hostname, byteIPAddr); } catch (UnknownHostException e) { log.error("Unknown host after IP address resolution? " + e); } cbInetAddress.call(result, ipAddr); break; } case TIMEOUT: { cbInetAddress.call(CBResult.TIMEOUT("DNS timeout for host=" + hostname), null); break; } case ERROR: { cbInetAddress.call(result, null); break; } } } }); } public void getIPAddrByName(final String hostname, final CB1<byte[]> cbByteIPAddr) { // log.debug("getIPAddrByName.hostname=" + hostname); // Check the cache final byte[] cachedByteIPAddr = lookupCacheHostname(hostname); if (cachedByteIPAddr != null) { log.debug("DNS cache hit: cachedByteIPAddr=" + NetUtil.byteIPAddrToString(cachedByteIPAddr)); EL.get().registerTimerCB(new CB0() { protected void cb(CBResult result) { cbByteIPAddr.call(CBResult.OK(), cachedByteIPAddr); } }); return; } doQueryByName(hostname, cbByteIPAddr, 0); } public AddressIF getDNSServer() { return PUtil.getRandomObject(dnsServerList); } public void doQueryByName(final String hostname, final CB1<byte[]> cbByteIPAddr, final int queryCount) { DNSQuestion aQuestion = new DNSQuestion(hostname, DNSQuestion.TYPE_A, DNSQuestion.CLASS_IN); DNSQuery q = new DNSQuery(new DNSQuestion[] { aQuestion }); final AddressIF dnsServer = getDNSServer(); log.debug("Sending DNS query to " + dnsServer); long dnsTimeout = START_DNS_TIMEOUT * (queryCount + 1); q.runQuery(this, dnsServer, new CB1<DNSQuery>(dnsTimeout) { protected void cb(CBResult result, DNSQuery query) { switch (result.state) { case OK: { byte[] byteIPAddr = null; for (RR rr : query.getAnswers()) { if (rr instanceof ARR) { ARR arr = (ARR) rr; byteIPAddr = arr.byteAddr; } } if (byteIPAddr != null) { updateCache(hostname, byteIPAddr); cbByteIPAddr.call(CBResult.OK(), byteIPAddr); } else { log.debug("Unknown host=" + hostname); cbByteIPAddr.call(CBResult.ERROR("Unknown host: " + hostna... [truncated message content] |