├── .editorconfig ├── .gitignore ├── .travis.yml ├── Changelog ├── EXAMPLES.md ├── LICENSE ├── Makefile ├── README.md ├── README.vrsn.md ├── USAGE ├── build.xml ├── dig.java ├── jnamed.java ├── lookup.java ├── org └── xbill │ └── DNS │ ├── A6Record.java │ ├── AAAARecord.java │ ├── AFSDBRecord.java │ ├── APLRecord.java │ ├── ARecord.java │ ├── Address.java │ ├── CAARecord.java │ ├── CDNSKEYRecord.java │ ├── CDSRecord.java │ ├── CERTRecord.java │ ├── CNAMERecord.java │ ├── Cache.java │ ├── Client.java │ ├── ClientSubnetOption.java │ ├── Compression.java │ ├── Credibility.java │ ├── DClass.java │ ├── DHCIDRecord.java │ ├── DLVRecord.java │ ├── DNAMERecord.java │ ├── DNSInput.java │ ├── DNSKEYRecord.java │ ├── DNSOutput.java │ ├── DNSSEC.java │ ├── DSRecord.java │ ├── EDNSOption.java │ ├── EmptyRecord.java │ ├── ExtendedFlags.java │ ├── ExtendedResolver.java │ ├── Flags.java │ ├── FormattedTime.java │ ├── GPOSRecord.java │ ├── Generator.java │ ├── GenericEDNSOption.java │ ├── HINFORecord.java │ ├── Header.java │ ├── IPSECKEYRecord.java │ ├── ISDNRecord.java │ ├── InvalidDClassException.java │ ├── InvalidTTLException.java │ ├── InvalidTypeException.java │ ├── KEYBase.java │ ├── KEYRecord.java │ ├── KXRecord.java │ ├── LOCRecord.java │ ├── Lookup.java │ ├── MBRecord.java │ ├── MDRecord.java │ ├── MFRecord.java │ ├── MGRecord.java │ ├── MINFORecord.java │ ├── MRRecord.java │ ├── MXRecord.java │ ├── Master.java │ ├── Message.java │ ├── Mnemonic.java │ ├── NAPTRRecord.java │ ├── NSAPRecord.java │ ├── NSAP_PTRRecord.java │ ├── NSEC3PARAMRecord.java │ ├── NSEC3Record.java │ ├── NSECRecord.java │ ├── NSIDOption.java │ ├── NSRecord.java │ ├── NULLRecord.java │ ├── NXTRecord.java │ ├── Name.java │ ├── NameTooLongException.java │ ├── OPENPGPKEYRecord.java │ ├── OPTRecord.java │ ├── Opcode.java │ ├── Options.java │ ├── PTRRecord.java │ ├── PXRecord.java │ ├── PacketLogger.java │ ├── RPRecord.java │ ├── RRSIGRecord.java │ ├── RRset.java │ ├── RTRecord.java │ ├── Rcode.java │ ├── Record.java │ ├── RelativeNameException.java │ ├── ResolveThread.java │ ├── Resolver.java │ ├── ResolverConfig.java │ ├── ResolverListener.java │ ├── ReverseMap.java │ ├── SIG0.java │ ├── SIGBase.java │ ├── SIGRecord.java │ ├── SMIMEARecord.java │ ├── SOARecord.java │ ├── SPFRecord.java │ ├── SRVRecord.java │ ├── SSHFPRecord.java │ ├── Section.java │ ├── Serial.java │ ├── SetResponse.java │ ├── SimpleResolver.java │ ├── SingleCompressedNameBase.java │ ├── SingleNameBase.java │ ├── TCPClient.java │ ├── TKEYRecord.java │ ├── TLSARecord.java │ ├── TSIG.java │ ├── TSIGRecord.java │ ├── TTL.java │ ├── TXTBase.java │ ├── TXTRecord.java │ ├── TextParseException.java │ ├── Tokenizer.java │ ├── Type.java │ ├── TypeBitmap.java │ ├── U16NameBase.java │ ├── UDPClient.java │ ├── UNKRecord.java │ ├── URIRecord.java │ ├── Update.java │ ├── WKSRecord.java │ ├── WireParseException.java │ ├── X25Record.java │ ├── Zone.java │ ├── ZoneTransferException.java │ ├── ZoneTransferIn.java │ ├── spi │ ├── DNSJavaNameService.java │ ├── DNSJavaNameServiceDescriptor.java │ └── services │ │ └── sun.net.spi.nameservice.NameServiceDescriptor │ ├── tests │ ├── primary.java │ └── xfrin.java │ ├── utils │ ├── base16.java │ ├── base32.java │ ├── base64.java │ └── hexdump.java │ └── windows │ ├── DNSServer.properties │ ├── DNSServer_de.properties │ ├── DNSServer_fr.properties │ ├── DNSServer_ja.properties │ └── DNSServer_pl.properties ├── pom.xml ├── tests ├── junit-3.8.1.jar └── org │ └── xbill │ └── DNS │ ├── A6RecordTest.java │ ├── AAAARecordTest.java │ ├── AFSDBRecordTest.java │ ├── APLRecordTest.java │ ├── ARecordTest.java │ ├── AddressTest.java │ ├── CNAMERecordTest.java │ ├── CompressionTest.java │ ├── DClassTest.java │ ├── DNAMERecordTest.java │ ├── DNSInputTest.java │ ├── DNSKEYRecordTest.java │ ├── DNSOutputTest.java │ ├── DNSSECSIG0Test.java │ ├── DNSSECTest.java │ ├── DNSSECWithLunaProviderTest.java.disabled │ ├── DNSSECWithProviderTest.java │ ├── DSRecordTest.java │ ├── EmptyRecordTest.java │ ├── ExceptionTest.java │ ├── ExtendedFlagsTest.java │ ├── FlagsTest.java │ ├── FormattedTimeTest.java │ ├── GPOSRecordTest.java │ ├── HINFORecordTest.java │ ├── HeaderTest.java │ ├── KEYBaseTest.java │ ├── KEYRecordTest.java │ ├── KXRecordTest.java │ ├── MBRecordTest.java │ ├── MDRecordTest.java │ ├── MFRecordTest.java │ ├── MGRecordTest.java │ ├── MRRecordTest.java │ ├── MXRecordTest.java │ ├── MessageTest.java │ ├── MnemonicTest.java │ ├── NSAP_PTRRecordTest.java │ ├── NSRecordTest.java │ ├── NameTest.java │ ├── OPTRecordTest.java │ ├── OpcodeTest.java │ ├── OptionsTest.java │ ├── RRsetTest.java │ ├── RTRecordTest.java │ ├── RcodeTest.java │ ├── RecordTest.java │ ├── ReverseMapTest.java │ ├── SOARecordTest.java │ ├── SectionTest.java │ ├── SerialTest.java │ ├── SetResponseTest.java │ ├── SingleCompressedNameBaseTest.java │ ├── SingleNameBaseTest.java │ ├── TSIGTest.java │ ├── TTLTest.java │ ├── TokenizerTest.java │ ├── TypeBitmapTest.java │ ├── TypeTest.java │ ├── U16NameBaseTest.java │ ├── URIRecordTest.java │ └── utils │ ├── base16Test.java │ ├── base32Test.java │ ├── base64Test.java │ └── hexdumpTest.java └── update.java /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 8 6 | insert_final_newline = true 7 | charset = latin1 8 | 9 | [*.yml] 10 | indent_style = space 11 | indent_size = 2 12 | 13 | [{pom.xml,*.md}] 14 | indent_style = space 15 | indent_size = 4 16 | 17 | [.editorconfig] 18 | charset = utf-8 19 | 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.jar 3 | .classpath 4 | .project 5 | .settings/ 6 | .idea/ 7 | *.iml 8 | target/ 9 | 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | 5 | language: java 6 | jdk: 7 | - openjdk8 8 | 9 | install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip -B -V 10 | script: mvn test jacoco:report coveralls:report -Dgpg.skip -B 11 | -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dblacka/jdnssec-dnsjava/c8b55cd406721e04f1ec8a349f00712fcce1df9b/Changelog -------------------------------------------------------------------------------- /EXAMPLES.md: -------------------------------------------------------------------------------- 1 | # dnsjava examples 2 | 3 | All of these examples are code fragments. Code using these fragments should 4 | check exceptions when appropriate, and should: 5 | 6 | ```java 7 | import org.xbill.DNS.*; 8 | ``` 9 | 10 | ## Get the IP address associated with a name 11 | 12 | ```java 13 | InetAddress addr = Address.getByName("www.dnsjava.org"); 14 | ``` 15 | 16 | ## Get the MX target and preference of a name 17 | 18 | ```java 19 | Record [] records = new Lookup("gmail.com", Type.MX).run(); 20 | for (int i = 0; i < records.length; i++) { 21 | MXRecord mx = (MXRecord) records[i]; 22 | System.out.println("Host " + mx.getTarget() + " has preference " + mx.getPriority()); 23 | } 24 | ``` 25 | 26 | ## Query a remote name server for its version 27 | 28 | ```java 29 | Lookup l = new Lookup("version.bind.", Type.TXT, DClass.CH); 30 | l.setResolver(new SimpleResolver(args[0])); 31 | l.run(); 32 | if (l.getResult() == Lookup.SUCCESSFUL) 33 | System.out.println(l.getAnswers()[0].rdataToString()); 34 | ``` 35 | 36 | ## Transfer a zone from a server and print it 37 | 38 | ```java 39 | ZoneTransferIn xfr = ZoneTransferIn.newAXFR(new Name("."), "192.5.5.241", null); 40 | List records = xfr.run(); 41 | for (Iterator it = records.iterator(); it.hasNext(); ) 42 | System.out.println(it.next()); 43 | ``` 44 | 45 | ## Use DNS dynamic update to set the address of a host to a value specified on the command line 46 | 47 | ```java 48 | Name zone = Name.fromString("dyn.test.example."); 49 | Name host = Name.fromString("host", zone); 50 | Update update = new Update(zone); 51 | update.replace(host, Type.A, 3600, args[0]); 52 | 53 | Resolver res = new SimpleResolver("10.0.0.1"); 54 | res.setTSIGKey(new TSIG(host, base64.fromString("1234"))); 55 | res.setTCP(true); 56 | 57 | Message response = res.send(update); 58 | ``` 59 | 60 | ## Manipulate domain names 61 | 62 | ```java 63 | Name n = Name.fromString("www.dnsjava.org"); 64 | Name o = Name.fromString("dnsjava.org"); 65 | System.out.println(n.subdomain(o)); // True 66 | 67 | System.out.println(n.compareTo(o)); // > 0 68 | 69 | Name rel = n.relativize(o); // the relative name 'www' 70 | Name n2 = Name.concatenate(rel, o); 71 | System.out.println(n2.equals(n)); // True 72 | 73 | // www 74 | // dnsjava 75 | // org 76 | for (int i = 0; i < n.labels(); i++) 77 | System.out.println(n.getLabelString(i)); 78 | ``` 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 1998-2011, Brian Wellington. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | JAVAC = javac 2 | JFLAGS = -g 3 | JAR = jar cf 4 | 5 | SUNAPIDOC = http://java.sun.com/j2se/1.4/docs/api 6 | JAVADOC=javadoc -classpath . -d doc -windowtitle "dnsjava documentation" -link ${SUNAPIDOC} 7 | 8 | VERSION = 2.1.9-vrsn-1 9 | 10 | DNSSRC = org/xbill/DNS/*.java \ 11 | org/xbill/DNS/utils/*.java 12 | PROGSRC = *.java 13 | 14 | DNSCLASS = org/xbill/DNS/*.class \ 15 | org/xbill/DNS/utils/*.class 16 | PROGCLASS = *.class 17 | 18 | CLASSLIST = org.xbill.DNS org.xbill.DNS.utils 19 | 20 | JARFILE = dnsjava-${VERSION}.jar 21 | 22 | all: 23 | ${JAVAC} ${JFLAGS} ${PROGSRC} ${DNSSRC} 24 | 25 | jar: 26 | ${JAR} ${JARFILE} ${PROGCLASS} ${DNSCLASS} 27 | 28 | clean: 29 | rm -f ${PROGCLASS} ${DNSCLASS} ${JARFILE} 30 | 31 | doc docs: docsclean 32 | if test ! -d doc ; then mkdir doc ; fi 33 | ${JAVADOC} ${CLASSLIST} 34 | 35 | docclean docsclean: 36 | rm -rf doc/* 37 | -------------------------------------------------------------------------------- /README.vrsn.md: -------------------------------------------------------------------------------- 1 | 2 | The differences between this version of DNSJava and the official version are: 3 | 4 | 1. The build.xml has been modified to compile to the build/classes directory. 5 | 6 | 2. org.xbill.DNS.Message.toString() has been modified to create an "OPT PSEUDOSECTION" section rather than attempt to render the OPT record in the additional section. 7 | 8 | 3. org.xbill.DNS.NSEC3Record has a "comment" field that can be specified in an alternate constructor. If specified, the toString() method will append the comment. This feature exists so that the jdnssec-signzone tool can add the original ownername as a comment. 9 | 10 | 4. A base32 test driver exists. Unfortunately, this was left out of the patch submission that added the base32 class to DNSJava. 11 | 12 | 5. The testcase, org.xbill.DNS.DNSSECWithLunaDriverTest has been disabled (by renaming it to DNSSECWithLunaDriverTest.java.disabled), as it won't compile without the Luna API present. 13 | -------------------------------------------------------------------------------- /USAGE: -------------------------------------------------------------------------------- 1 | dnsjava v2.0 2 | 3 | dnsjava provides several command line programs, which are documented here. 4 | For examples of API usage, see examples.html. 5 | 6 | - dig: 7 | A clone of dig (as distributed with BIND) 8 | dig @server [-x] name type [class] [-p port] [-k name/secret] [-t] \ 9 | [-i] [-e n] [-d] 10 | -x : reverse lookup, name must be a dotted quad 11 | -k : use TSIG transaction security 12 | -t : use TCP by default 13 | -i : ignore truncation errors 14 | -e n: Use EDNS level n (only 0 is defined) 15 | -d : Set the DNSSEC OK bit 16 | 17 | - update: 18 | A dynamic update client with some extra functionality. This can be 19 | used either interactively or by specifying a file containing commands 20 | to be executed. Running 'help' lists all other commands. 21 | update [file] 22 | 23 | 24 | - jnamed: 25 | A basic authoritative only (non-caching, non-recursive) server. It's 26 | not very good, but it's also a whole lot better than it used to be. 27 | 28 | The config file (jnamed.conf by default) supports the following 29 | directives: 30 | primary 31 | secondary 32 | cache 33 | key [algorithm] 34 | address 35 | port 36 | 37 | If no addresses are specified, jnamed will listen on all addresses, 38 | using a wildcard socket. If no ports are specified, jnamed will 39 | listen on port 53. 40 | 41 | The following is an example: 42 | primary internal /etc/namedb/internal.db 43 | secondary xbill.org 127.0.0.1 44 | cache /etc/namedb/cache.db 45 | key xbill.org 1234 46 | address 127.0.0.1 47 | port 12345 48 | 49 | To run: 50 | jnamed [config_file] 51 | 52 | jnamed should not be used for production, and should probably 53 | not be used for testing. If the above documentation is not enough, 54 | please do not ask for more, because it really should not be used. 55 | 56 | - lookup: 57 | A simple program that looks up records associated with names. 58 | If no type is specified, address lookups are done. 59 | 60 | lookup [-t type] name ... 61 | -------------------------------------------------------------------------------- /lookup.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | import org.xbill.DNS.*; 4 | 5 | /** @author Brian Wellington <bwelling@xbill.org> */ 6 | 7 | public class lookup { 8 | 9 | public static void 10 | printAnswer(String name, Lookup lookup) { 11 | System.out.print(name + ":"); 12 | int result = lookup.getResult(); 13 | if (result != Lookup.SUCCESSFUL) 14 | System.out.print(" " + lookup.getErrorString()); 15 | System.out.println(); 16 | Name [] aliases = lookup.getAliases(); 17 | if (aliases.length > 0) { 18 | System.out.print("# aliases: "); 19 | for (int i = 0; i < aliases.length; i++) { 20 | System.out.print(aliases[i]); 21 | if (i < aliases.length - 1) 22 | System.out.print(" "); 23 | } 24 | System.out.println(); 25 | } 26 | if (lookup.getResult() == Lookup.SUCCESSFUL) { 27 | Record [] answers = lookup.getAnswers(); 28 | for (int i = 0; i < answers.length; i++) 29 | System.out.println(answers[i]); 30 | } 31 | } 32 | 33 | public static void 34 | main(String [] args) throws Exception { 35 | int type = Type.A; 36 | int start = 0; 37 | if (args.length > 2 && args[0].equals("-t")) { 38 | type = Type.value(args[1]); 39 | if (type < 0) 40 | throw new IllegalArgumentException("invalid type"); 41 | start = 2; 42 | } 43 | for (int i = start; i < args.length; i++) { 44 | Lookup l = new Lookup(args[i], type); 45 | l.run(); 46 | printAnswer(args[i], l); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /org/xbill/DNS/A6Record.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import java.net.*; 7 | 8 | /** 9 | * A6 Record - maps a domain name to an IPv6 address (experimental) 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class A6Record extends Record { 15 | 16 | private static final long serialVersionUID = -8815026887337346789L; 17 | 18 | private int prefixBits; 19 | private InetAddress suffix; 20 | private Name prefix; 21 | 22 | A6Record() {} 23 | 24 | Record 25 | getObject() { 26 | return new A6Record(); 27 | } 28 | 29 | /** 30 | * Creates an A6 Record from the given data 31 | * @param prefixBits The number of bits in the address prefix 32 | * @param suffix The address suffix 33 | * @param prefix The name of the prefix 34 | */ 35 | public 36 | A6Record(Name name, int dclass, long ttl, int prefixBits, 37 | InetAddress suffix, Name prefix) 38 | { 39 | super(name, Type.A6, dclass, ttl); 40 | this.prefixBits = checkU8("prefixBits", prefixBits); 41 | if (suffix != null && Address.familyOf(suffix) != Address.IPv6) 42 | throw new IllegalArgumentException("invalid IPv6 address"); 43 | this.suffix = suffix; 44 | if (prefix != null) 45 | this.prefix = checkName("prefix", prefix); 46 | } 47 | 48 | void 49 | rrFromWire(DNSInput in) throws IOException { 50 | prefixBits = in.readU8(); 51 | int suffixbits = 128 - prefixBits; 52 | int suffixbytes = (suffixbits + 7) / 8; 53 | if (prefixBits < 128) { 54 | byte [] bytes = new byte[16]; 55 | in.readByteArray(bytes, 16 - suffixbytes, suffixbytes); 56 | suffix = InetAddress.getByAddress(bytes); 57 | } 58 | if (prefixBits > 0) 59 | prefix = new Name(in); 60 | } 61 | 62 | void 63 | rdataFromString(Tokenizer st, Name origin) throws IOException { 64 | prefixBits = st.getUInt8(); 65 | if (prefixBits > 128) { 66 | throw st.exception("prefix bits must be [0..128]"); 67 | } else if (prefixBits < 128) { 68 | String s = st.getString(); 69 | try { 70 | suffix = Address.getByAddress(s, Address.IPv6); 71 | } 72 | catch (UnknownHostException e) { 73 | throw st.exception("invalid IPv6 address: " + s); 74 | } 75 | } 76 | if (prefixBits > 0) 77 | prefix = st.getName(origin); 78 | } 79 | 80 | /** Converts rdata to a String */ 81 | String 82 | rrToString() { 83 | StringBuffer sb = new StringBuffer(); 84 | sb.append(prefixBits); 85 | if (suffix != null) { 86 | sb.append(" "); 87 | sb.append(suffix.getHostAddress()); 88 | } 89 | if (prefix != null) { 90 | sb.append(" "); 91 | sb.append(prefix); 92 | } 93 | return sb.toString(); 94 | } 95 | 96 | /** Returns the number of bits in the prefix */ 97 | public int 98 | getPrefixBits() { 99 | return prefixBits; 100 | } 101 | 102 | /** Returns the address suffix */ 103 | public InetAddress 104 | getSuffix() { 105 | return suffix; 106 | } 107 | 108 | /** Returns the address prefix */ 109 | public Name 110 | getPrefix() { 111 | return prefix; 112 | } 113 | 114 | void 115 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 116 | out.writeU8(prefixBits); 117 | if (suffix != null) { 118 | int suffixbits = 128 - prefixBits; 119 | int suffixbytes = (suffixbits + 7) / 8; 120 | byte [] data = suffix.getAddress(); 121 | out.writeByteArray(data, 16 - suffixbytes, suffixbytes); 122 | } 123 | if (prefix != null) 124 | prefix.toWire(out, null, canonical); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /org/xbill/DNS/AAAARecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import java.net.*; 7 | 8 | /** 9 | * IPv6 Address Record - maps a domain name to an IPv6 address 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class AAAARecord extends Record { 15 | 16 | private static final long serialVersionUID = -4588601512069748050L; 17 | 18 | private byte [] address; 19 | 20 | AAAARecord() {} 21 | 22 | Record 23 | getObject() { 24 | return new AAAARecord(); 25 | } 26 | 27 | /** 28 | * Creates an AAAA Record from the given data 29 | * @param address The address suffix 30 | */ 31 | public 32 | AAAARecord(Name name, int dclass, long ttl, InetAddress address) { 33 | super(name, Type.AAAA, dclass, ttl); 34 | if (Address.familyOf(address) != Address.IPv6) 35 | throw new IllegalArgumentException("invalid IPv6 address"); 36 | this.address = address.getAddress(); 37 | } 38 | 39 | void 40 | rrFromWire(DNSInput in) throws IOException { 41 | address = in.readByteArray(16); 42 | } 43 | 44 | void 45 | rdataFromString(Tokenizer st, Name origin) throws IOException { 46 | address = st.getAddressBytes(Address.IPv6); 47 | } 48 | 49 | /** Converts rdata to a String */ 50 | String 51 | rrToString() { 52 | InetAddress addr; 53 | try { 54 | addr = InetAddress.getByAddress(null, address); 55 | } catch (UnknownHostException e) { 56 | return null; 57 | } 58 | if (addr.getAddress().length == 4) { 59 | // Deal with Java's broken handling of mapped IPv4 addresses. 60 | StringBuffer sb = new StringBuffer("0:0:0:0:0:ffff:"); 61 | int high = ((address[12] & 0xFF) << 8) + (address[13] & 0xFF); 62 | int low = ((address[14] & 0xFF) << 8) + (address[15] & 0xFF); 63 | sb.append(Integer.toHexString(high)); 64 | sb.append(':'); 65 | sb.append(Integer.toHexString(low)); 66 | return sb.toString(); 67 | } 68 | return addr.getHostAddress(); 69 | } 70 | 71 | /** Returns the address */ 72 | public InetAddress 73 | getAddress() { 74 | try { 75 | if (name == null) 76 | return InetAddress.getByAddress(address); 77 | else 78 | return InetAddress.getByAddress(name.toString(), 79 | address); 80 | } catch (UnknownHostException e) { 81 | return null; 82 | } 83 | } 84 | 85 | void 86 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 87 | out.writeByteArray(address); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /org/xbill/DNS/AFSDBRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * AFS Data Base Record - maps a domain name to the name of an AFS cell 7 | * database server. 8 | * 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class AFSDBRecord extends U16NameBase { 14 | 15 | private static final long serialVersionUID = 3034379930729102437L; 16 | 17 | AFSDBRecord() {} 18 | 19 | Record 20 | getObject() { 21 | return new AFSDBRecord(); 22 | } 23 | 24 | /** 25 | * Creates an AFSDB Record from the given data. 26 | * @param subtype Indicates the type of service provided by the host. 27 | * @param host The host providing the service. 28 | */ 29 | public 30 | AFSDBRecord(Name name, int dclass, long ttl, int subtype, Name host) { 31 | super(name, Type.AFSDB, dclass, ttl, subtype, "subtype", host, "host"); 32 | } 33 | 34 | /** Gets the subtype indicating the service provided by the host. */ 35 | public int 36 | getSubtype() { 37 | return getU16Field(); 38 | } 39 | 40 | /** Gets the host providing service for the domain. */ 41 | public Name 42 | getHost() { 43 | return getNameField(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /org/xbill/DNS/ARecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.net.*; 6 | import java.io.*; 7 | 8 | /** 9 | * Address Record - maps a domain name to an Internet address 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class ARecord extends Record { 15 | 16 | private static final long serialVersionUID = -2172609200849142323L; 17 | 18 | private int addr; 19 | 20 | ARecord() {} 21 | 22 | Record 23 | getObject() { 24 | return new ARecord(); 25 | } 26 | 27 | private static final int 28 | fromArray(byte [] array) { 29 | return (((array[0] & 0xFF) << 24) | 30 | ((array[1] & 0xFF) << 16) | 31 | ((array[2] & 0xFF) << 8) | 32 | (array[3] & 0xFF)); 33 | } 34 | 35 | private static final byte [] 36 | toArray(int addr) { 37 | byte [] bytes = new byte[4]; 38 | bytes[0] = (byte) ((addr >>> 24) & 0xFF); 39 | bytes[1] = (byte) ((addr >>> 16) & 0xFF); 40 | bytes[2] = (byte) ((addr >>> 8) & 0xFF); 41 | bytes[3] = (byte) (addr & 0xFF); 42 | return bytes; 43 | } 44 | 45 | /** 46 | * Creates an A Record from the given data 47 | * @param address The address that the name refers to 48 | */ 49 | public 50 | ARecord(Name name, int dclass, long ttl, InetAddress address) { 51 | super(name, Type.A, dclass, ttl); 52 | if (Address.familyOf(address) != Address.IPv4) 53 | throw new IllegalArgumentException("invalid IPv4 address"); 54 | addr = fromArray(address.getAddress()); 55 | } 56 | 57 | void 58 | rrFromWire(DNSInput in) throws IOException { 59 | addr = fromArray(in.readByteArray(4)); 60 | } 61 | 62 | void 63 | rdataFromString(Tokenizer st, Name origin) throws IOException { 64 | addr = fromArray(st.getAddressBytes(Address.IPv4)); 65 | } 66 | 67 | /** Converts rdata to a String */ 68 | String 69 | rrToString() { 70 | return (Address.toDottedQuad(toArray(addr))); 71 | } 72 | 73 | /** Returns the Internet address */ 74 | public InetAddress 75 | getAddress() { 76 | try { 77 | if (name == null) 78 | return InetAddress.getByAddress(toArray(addr)); 79 | else 80 | return InetAddress.getByAddress(name.toString(), 81 | toArray(addr)); 82 | } catch (UnknownHostException e) { 83 | return null; 84 | } 85 | } 86 | 87 | void 88 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 89 | out.writeU32(((long)addr) & 0xFFFFFFFFL); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /org/xbill/DNS/CAARecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import org.xbill.DNS.utils.*; 7 | 8 | /** 9 | * Certification Authority Authorization 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class CAARecord extends Record { 15 | 16 | private static final long serialVersionUID = 8544304287274216443L; 17 | 18 | public static class Flags { 19 | private Flags() {} 20 | 21 | public static final int IssuerCritical = 128; 22 | } 23 | 24 | private int flags; 25 | private byte [] tag; 26 | private byte [] value; 27 | 28 | CAARecord() {} 29 | 30 | Record 31 | getObject() { 32 | return new CAARecord(); 33 | } 34 | 35 | /** 36 | * Creates an CAA Record from the given data. 37 | * @param flags The flags. 38 | * @param tag The tag. 39 | * @param value The value. 40 | */ 41 | public 42 | CAARecord(Name name, int dclass, long ttl, int flags, String tag, String value) 43 | { 44 | super(name, Type.CAA, dclass, ttl); 45 | this.flags = checkU8("flags", flags); 46 | try { 47 | this.tag = byteArrayFromString(tag); 48 | this.value = byteArrayFromString(value); 49 | } 50 | catch (TextParseException e) { 51 | throw new IllegalArgumentException(e.getMessage()); 52 | } 53 | } 54 | 55 | void 56 | rrFromWire(DNSInput in) throws IOException { 57 | flags = in.readU8(); 58 | tag = in.readCountedString(); 59 | value = in.readByteArray(); 60 | } 61 | 62 | void 63 | rdataFromString(Tokenizer st, Name origin) throws IOException { 64 | flags = st.getUInt8(); 65 | try { 66 | tag = byteArrayFromString(st.getString()); 67 | value = byteArrayFromString(st.getString()); 68 | } 69 | catch (TextParseException e) { 70 | throw st.exception(e.getMessage()); 71 | } 72 | } 73 | 74 | String 75 | rrToString() { 76 | StringBuffer sb = new StringBuffer(); 77 | sb.append(flags); 78 | sb.append(" "); 79 | sb.append(byteArrayToString(tag, false)); 80 | sb.append(" "); 81 | sb.append(byteArrayToString(value, true)); 82 | return sb.toString(); 83 | } 84 | 85 | /** Returns the flags. */ 86 | public int 87 | getFlags() { 88 | return flags; 89 | } 90 | 91 | /** Returns the tag. */ 92 | public String 93 | getTag() { 94 | return byteArrayToString(tag, false); 95 | } 96 | 97 | /** Returns the value */ 98 | public String 99 | getValue() { 100 | return byteArrayToString(value, false); 101 | } 102 | 103 | void 104 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 105 | out.writeU8(flags); 106 | out.writeCountedString(tag); 107 | out.writeByteArray(value); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /org/xbill/DNS/CDNSKEYRecord.java: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: BSD-2-Clause 2 | package org.xbill.DNS; 3 | 4 | import java.security.PublicKey; 5 | 6 | /** 7 | * Child DNSKEY record as specified in RFC 8078. 8 | * 9 | * @see DNSSEC 10 | */ 11 | public class CDNSKEYRecord extends DNSKEYRecord { 12 | 13 | private static final long serialVersionUID = 1307874430666933615L; 14 | 15 | CDNSKEYRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new CDNSKEYRecord(); 20 | } 21 | 22 | /** 23 | * Creates a CDNSKEY Record from the given data 24 | * @param flags Flags describing the key's properties 25 | * @param proto The protocol that the key was created for 26 | * @param alg The key's algorithm 27 | * @param key Binary representation of the key 28 | */ 29 | public 30 | CDNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg, 31 | byte [] key) 32 | { 33 | super(name, Type.CDNSKEY, dclass, ttl, flags, proto, alg, key); 34 | } 35 | 36 | /** 37 | * Creates a CDNSKEY Record from the given data 38 | * @param flags Flags describing the key's properties 39 | * @param proto The protocol that the key was created for 40 | * @param alg The key's algorithm 41 | * @param key The key as a PublicKey 42 | * @throws DNSSEC.DNSSECException The PublicKey could not be converted into DNS 43 | * format. 44 | */ 45 | public 46 | CDNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg, 47 | PublicKey key) throws DNSSEC.DNSSECException 48 | { 49 | super(name, Type.CDNSKEY, dclass, ttl, flags, proto, alg, 50 | DNSSEC.fromPublicKey(key, alg)); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /org/xbill/DNS/CDSRecord.java: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: BSD-2-Clause 2 | package org.xbill.DNS; 3 | 4 | /** 5 | * Child Delegation Signer record as specified in RFC 8078. 6 | * 7 | * @see DNSSEC 8 | */ 9 | public class CDSRecord extends DSRecord { 10 | 11 | private static final long serialVersionUID = -3156174257356976006L; 12 | 13 | CDSRecord() {} 14 | 15 | Record 16 | getObject() { 17 | return new CDSRecord(); 18 | } 19 | 20 | /** 21 | * Creates a CDS Record from the given data 22 | * @param footprint The original KEY record's footprint (keyid). 23 | * @param alg The original key algorithm. 24 | * @param digestid The digest id code. 25 | * @param digest A hash of the original key. 26 | */ 27 | public 28 | CDSRecord(Name name, int dclass, long ttl, int footprint, int alg, 29 | int digestid, byte [] digest) 30 | { 31 | super(name, Type.CDS, dclass, ttl, footprint, alg, digestid, digest); 32 | } 33 | 34 | /** 35 | * Creates a CDS Record from the given data 36 | * @param digestid The digest id code. 37 | * @param key The key to digest 38 | */ 39 | public 40 | CDSRecord(Name name, int dclass, long ttl, int digestid, DNSKEYRecord key) 41 | { 42 | super(name, Type.CDS, dclass, ttl, key.getFootprint(), 43 | key.getAlgorithm(), digestid, 44 | DNSSEC.generateDSDigest(key, digestid)); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /org/xbill/DNS/CNAMERecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * CNAME Record - maps an alias to its real name 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class CNAMERecord extends SingleCompressedNameBase { 12 | 13 | private static final long serialVersionUID = -4020373886892538580L; 14 | 15 | CNAMERecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new CNAMERecord(); 20 | } 21 | 22 | /** 23 | * Creates a new CNAMERecord with the given data 24 | * @param alias The name to which the CNAME alias points 25 | */ 26 | public 27 | CNAMERecord(Name name, int dclass, long ttl, Name alias) { 28 | super(name, Type.CNAME, dclass, ttl, alias, "alias"); 29 | } 30 | 31 | /** 32 | * Gets the target of the CNAME Record 33 | */ 34 | public Name 35 | getTarget() { 36 | return getSingleName(); 37 | } 38 | 39 | /** Gets the alias specified by the CNAME Record */ 40 | public Name 41 | getAlias() { 42 | return getSingleName(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /org/xbill/DNS/Client.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2005 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import java.net.*; 7 | import java.nio.channels.*; 8 | import org.xbill.DNS.utils.hexdump; 9 | 10 | class Client { 11 | 12 | protected long endTime; 13 | protected SelectionKey key; 14 | 15 | /** 16 | * Packet logger, if available. 17 | */ 18 | private static PacketLogger packetLogger = null; 19 | 20 | protected 21 | Client(SelectableChannel channel, long endTime) throws IOException { 22 | boolean done = false; 23 | Selector selector = null; 24 | this.endTime = endTime; 25 | try { 26 | selector = Selector.open(); 27 | channel.configureBlocking(false); 28 | key = channel.register(selector, SelectionKey.OP_READ); 29 | done = true; 30 | } 31 | finally { 32 | if (!done && selector != null) 33 | selector.close(); 34 | if (!done) 35 | channel.close(); 36 | } 37 | } 38 | 39 | static protected void 40 | blockUntil(SelectionKey key, long endTime) throws IOException { 41 | long timeout = endTime - System.currentTimeMillis(); 42 | int nkeys = 0; 43 | if (timeout > 0) 44 | nkeys = key.selector().select(timeout); 45 | else if (timeout == 0) 46 | nkeys = key.selector().selectNow(); 47 | if (nkeys == 0) 48 | throw new SocketTimeoutException(); 49 | } 50 | 51 | static protected void 52 | verboseLog(String prefix, SocketAddress local, SocketAddress remote, 53 | byte [] data) 54 | { 55 | if (Options.check("verbosemsg")) 56 | System.err.println(hexdump.dump(prefix, data)); 57 | if (packetLogger != null) 58 | packetLogger.log(prefix, local, remote, data); 59 | } 60 | 61 | void 62 | cleanup() throws IOException { 63 | key.selector().close(); 64 | key.channel().close(); 65 | } 66 | 67 | static void setPacketLogger(PacketLogger logger) 68 | { 69 | packetLogger = logger; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /org/xbill/DNS/Compression.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * DNS Name Compression object. 7 | * @see Message 8 | * @see Name 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class Compression { 14 | 15 | private static class Entry { 16 | Name name; 17 | int pos; 18 | Entry next; 19 | } 20 | 21 | private static final int TABLE_SIZE = 17; 22 | private static final int MAX_POINTER = 0x3FFF; 23 | private Entry [] table; 24 | private boolean verbose = Options.check("verbosecompression"); 25 | 26 | /** 27 | * Creates a new Compression object. 28 | */ 29 | public 30 | Compression() { 31 | table = new Entry[TABLE_SIZE]; 32 | } 33 | 34 | /** 35 | * Adds a compression entry mapping a name to a position in a message. 36 | * @param pos The position at which the name is added. 37 | * @param name The name being added to the message. 38 | */ 39 | public void 40 | add(int pos, Name name) { 41 | if (pos > MAX_POINTER) 42 | return; 43 | int row = (name.hashCode() & 0x7FFFFFFF) % TABLE_SIZE; 44 | Entry entry = new Entry(); 45 | entry.name = name; 46 | entry.pos = pos; 47 | entry.next = table[row]; 48 | table[row] = entry; 49 | if (verbose) 50 | System.err.println("Adding " + name + " at " + pos); 51 | } 52 | 53 | /** 54 | * Retrieves the position of the given name, if it has been previously 55 | * included in the message. 56 | * @param name The name to find in the compression table. 57 | * @return The position of the name, or -1 if not found. 58 | */ 59 | public int 60 | get(Name name) { 61 | int row = (name.hashCode() & 0x7FFFFFFF) % TABLE_SIZE; 62 | int pos = -1; 63 | for (Entry entry = table[row]; entry != null; entry = entry.next) { 64 | if (entry.name.equals(name)) 65 | pos = entry.pos; 66 | } 67 | if (verbose) 68 | System.err.println("Looking for " + name + ", found " + pos); 69 | return pos; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /org/xbill/DNS/Credibility.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Constants relating to the credibility of cached data, which is based on 7 | * the data's source. The constants NORMAL and ANY should be used by most 8 | * callers. 9 | * @see Cache 10 | * @see Section 11 | * 12 | * @author Brian Wellington 13 | */ 14 | 15 | public final class Credibility { 16 | 17 | private 18 | Credibility() {} 19 | 20 | /** A hint or cache file on disk. */ 21 | public static final int HINT = 0; 22 | 23 | /** The additional section of a response. */ 24 | public static final int ADDITIONAL = 1; 25 | 26 | /** The additional section of a response. */ 27 | public static final int GLUE = 2; 28 | 29 | /** The authority section of a nonauthoritative response. */ 30 | public static final int NONAUTH_AUTHORITY = 3; 31 | 32 | /** The answer section of a nonauthoritative response. */ 33 | public static final int NONAUTH_ANSWER = 3; 34 | 35 | /** The authority section of an authoritative response. */ 36 | public static final int AUTH_AUTHORITY = 4; 37 | 38 | /** The answer section of a authoritative response. */ 39 | public static final int AUTH_ANSWER = 4; 40 | 41 | /** A zone. */ 42 | public static final int ZONE = 5; 43 | 44 | /** Credible data. */ 45 | public static final int NORMAL = 3; 46 | 47 | /** Data not required to be credible. */ 48 | public static final int ANY = 1; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /org/xbill/DNS/DClass.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Constants and functions relating to DNS classes. This is called DClass 7 | * to avoid confusion with Class. 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | public final class DClass { 13 | 14 | /** Internet */ 15 | public static final int IN = 1; 16 | 17 | /** Chaos network (MIT) */ 18 | public static final int CH = 3; 19 | 20 | /** Chaos network (MIT, alternate name) */ 21 | public static final int CHAOS = 3; 22 | 23 | /** Hesiod name server (MIT) */ 24 | public static final int HS = 4; 25 | 26 | /** Hesiod name server (MIT, alternate name) */ 27 | public static final int HESIOD = 4; 28 | 29 | /** Special value used in dynamic update messages */ 30 | public static final int NONE = 254; 31 | 32 | /** Matches any class */ 33 | public static final int ANY = 255; 34 | 35 | private static class DClassMnemonic extends Mnemonic { 36 | public 37 | DClassMnemonic() { 38 | super("DClass", CASE_UPPER); 39 | setPrefix("CLASS"); 40 | } 41 | 42 | public void 43 | check(int val) { 44 | DClass.check(val); 45 | } 46 | } 47 | 48 | private static Mnemonic classes = new DClassMnemonic(); 49 | 50 | static { 51 | classes.add(IN, "IN"); 52 | classes.add(CH, "CH"); 53 | classes.addAlias(CH, "CHAOS"); 54 | classes.add(HS, "HS"); 55 | classes.addAlias(HS, "HESIOD"); 56 | classes.add(NONE, "NONE"); 57 | classes.add(ANY, "ANY"); 58 | } 59 | 60 | private 61 | DClass() {} 62 | 63 | /** 64 | * Checks that a numeric DClass is valid. 65 | * @throws InvalidDClassException The class is out of range. 66 | */ 67 | public static void 68 | check(int i) { 69 | if (i < 0 || i > 0xFFFF) 70 | throw new InvalidDClassException(i); 71 | } 72 | 73 | /** 74 | * Converts a numeric DClass into a String 75 | * @return The canonical string representation of the class 76 | * @throws InvalidDClassException The class is out of range. 77 | */ 78 | public static String 79 | string(int i) { 80 | return classes.getText(i); 81 | } 82 | 83 | /** 84 | * Converts a String representation of a DClass into its numeric value 85 | * @return The class code, or -1 on error. 86 | */ 87 | public static int 88 | value(String s) { 89 | return classes.getValue(s); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /org/xbill/DNS/DHCIDRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import org.xbill.DNS.utils.base64; 7 | 8 | /** 9 | * DHCID - Dynamic Host Configuration Protocol (DHCP) ID (RFC 4701) 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class DHCIDRecord extends Record { 15 | 16 | private static final long serialVersionUID = -8214820200808997707L; 17 | 18 | private byte [] data; 19 | 20 | DHCIDRecord() {} 21 | 22 | Record 23 | getObject() { 24 | return new DHCIDRecord(); 25 | } 26 | 27 | /** 28 | * Creates an DHCID Record from the given data 29 | * @param data The binary data, which is opaque to DNS. 30 | */ 31 | public 32 | DHCIDRecord(Name name, int dclass, long ttl, byte [] data) { 33 | super(name, Type.DHCID, dclass, ttl); 34 | this.data = data; 35 | } 36 | 37 | void 38 | rrFromWire(DNSInput in) throws IOException { 39 | data = in.readByteArray(); 40 | } 41 | 42 | void 43 | rdataFromString(Tokenizer st, Name origin) throws IOException { 44 | data = st.getBase64(); 45 | } 46 | 47 | void 48 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 49 | out.writeByteArray(data); 50 | } 51 | 52 | String 53 | rrToString() { 54 | return base64.toString(data); 55 | } 56 | 57 | /** 58 | * Returns the binary data. 59 | */ 60 | public byte [] 61 | getData() { 62 | return data; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /org/xbill/DNS/DLVRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2002-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import org.xbill.DNS.utils.*; 7 | 8 | /** 9 | * DLV - contains a Delegation Lookaside Validation record, which acts 10 | * as the equivalent of a DS record in a lookaside zone. 11 | * @see DNSSEC 12 | * @see DSRecord 13 | * 14 | * @author David Blacka 15 | * @author Brian Wellington 16 | */ 17 | 18 | public class DLVRecord extends Record { 19 | 20 | public static final int SHA1_DIGEST_ID = DSRecord.Digest.SHA1; 21 | public static final int SHA256_DIGEST_ID = DSRecord.Digest.SHA1; 22 | 23 | private static final long serialVersionUID = 1960742375677534148L; 24 | 25 | private int footprint; 26 | private int alg; 27 | private int digestid; 28 | private byte [] digest; 29 | 30 | DLVRecord() {} 31 | 32 | Record 33 | getObject() { 34 | return new DLVRecord(); 35 | } 36 | 37 | /** 38 | * Creates a DLV Record from the given data 39 | * @param footprint The original KEY record's footprint (keyid). 40 | * @param alg The original key algorithm. 41 | * @param digestid The digest id code. 42 | * @param digest A hash of the original key. 43 | */ 44 | public 45 | DLVRecord(Name name, int dclass, long ttl, int footprint, int alg, 46 | int digestid, byte [] digest) 47 | { 48 | super(name, Type.DLV, dclass, ttl); 49 | this.footprint = checkU16("footprint", footprint); 50 | this.alg = checkU8("alg", alg); 51 | this.digestid = checkU8("digestid", digestid); 52 | this.digest = digest; 53 | } 54 | 55 | void 56 | rrFromWire(DNSInput in) throws IOException { 57 | footprint = in.readU16(); 58 | alg = in.readU8(); 59 | digestid = in.readU8(); 60 | digest = in.readByteArray(); 61 | } 62 | 63 | void 64 | rdataFromString(Tokenizer st, Name origin) throws IOException { 65 | footprint = st.getUInt16(); 66 | alg = st.getUInt8(); 67 | digestid = st.getUInt8(); 68 | digest = st.getHex(); 69 | } 70 | 71 | /** 72 | * Converts rdata to a String 73 | */ 74 | String 75 | rrToString() { 76 | StringBuffer sb = new StringBuffer(); 77 | sb.append(footprint); 78 | sb.append(" "); 79 | sb.append(alg); 80 | sb.append(" "); 81 | sb.append(digestid); 82 | if (digest != null) { 83 | sb.append(" "); 84 | sb.append(base16.toString(digest)); 85 | } 86 | 87 | return sb.toString(); 88 | } 89 | 90 | /** 91 | * Returns the key's algorithm. 92 | */ 93 | public int 94 | getAlgorithm() { 95 | return alg; 96 | } 97 | 98 | /** 99 | * Returns the key's Digest ID. 100 | */ 101 | public int 102 | getDigestID() 103 | { 104 | return digestid; 105 | } 106 | 107 | /** 108 | * Returns the binary hash of the key. 109 | */ 110 | public byte [] 111 | getDigest() { 112 | return digest; 113 | } 114 | 115 | /** 116 | * Returns the key's footprint. 117 | */ 118 | public int 119 | getFootprint() { 120 | return footprint; 121 | } 122 | 123 | void 124 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 125 | out.writeU16(footprint); 126 | out.writeU8(alg); 127 | out.writeU8(digestid); 128 | if (digest != null) 129 | out.writeByteArray(digest); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /org/xbill/DNS/DNAMERecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * DNAME Record - maps a nonterminal alias (subtree) to a different domain 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class DNAMERecord extends SingleNameBase { 12 | 13 | private static final long serialVersionUID = 2670767677200844154L; 14 | 15 | DNAMERecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new DNAMERecord(); 20 | } 21 | 22 | /** 23 | * Creates a new DNAMERecord with the given data 24 | * @param alias The name to which the DNAME alias points 25 | */ 26 | public 27 | DNAMERecord(Name name, int dclass, long ttl, Name alias) { 28 | super(name, Type.DNAME, dclass, ttl, alias, "alias"); 29 | } 30 | 31 | /** 32 | * Gets the target of the DNAME Record 33 | */ 34 | public Name 35 | getTarget() { 36 | return getSingleName(); 37 | } 38 | 39 | /** Gets the alias specified by the DNAME Record */ 40 | public Name 41 | getAlias() { 42 | return getSingleName(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /org/xbill/DNS/DNSKEYRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import java.security.PublicKey; 7 | 8 | /** 9 | * Key - contains a cryptographic public key for use by DNS. 10 | * The data can be converted to objects implementing 11 | * java.security.interfaces.PublicKey 12 | * @see DNSSEC 13 | * 14 | * @author Brian Wellington 15 | */ 16 | 17 | public class DNSKEYRecord extends KEYBase { 18 | 19 | public static class Protocol { 20 | private Protocol() {} 21 | 22 | /** Key will be used for DNSSEC */ 23 | public static final int DNSSEC = 3; 24 | } 25 | 26 | public static class Flags { 27 | private Flags() {} 28 | 29 | /** Key is a zone key */ 30 | public static final int ZONE_KEY = 0x100; 31 | 32 | /** Key is a secure entry point key */ 33 | public static final int SEP_KEY = 0x1; 34 | 35 | /** Key has been revoked */ 36 | public static final int REVOKE = 0x80; 37 | } 38 | 39 | private static final long serialVersionUID = -8679800040426675002L; 40 | 41 | DNSKEYRecord() {} 42 | 43 | Record 44 | getObject() { 45 | return new DNSKEYRecord(); 46 | } 47 | 48 | /** 49 | * Creates a DNSKEY Record from the given data 50 | * @param flags Flags describing the key's properties 51 | * @param proto The protocol that the key was created for 52 | * @param alg The key's algorithm 53 | * @param key Binary representation of the key 54 | */ 55 | protected 56 | DNSKEYRecord(Name name, int type, int dclass, long ttl, int flags, int proto, 57 | int alg, byte [] key) 58 | { 59 | super(name, type, dclass, ttl, flags, proto, alg, key); 60 | } 61 | 62 | /** 63 | * Creates a DNSKEY Record from the given data 64 | * @param flags Flags describing the key's properties 65 | * @param proto The protocol that the key was created for 66 | * @param alg The key's algorithm 67 | * @param key Binary representation of the key 68 | */ 69 | public 70 | DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg, 71 | byte [] key) 72 | { 73 | this(name, Type.DNSKEY, dclass, ttl, flags, proto, alg, key); 74 | } 75 | 76 | /** 77 | * Creates a DNSKEY Record from the given data 78 | * @param flags Flags describing the key's properties 79 | * @param proto The protocol that the key was created for 80 | * @param alg The key's algorithm 81 | * @param key The key as a PublicKey 82 | * @throws DNSSEC.DNSSECException The PublicKey could not be converted into DNS 83 | * format. 84 | */ 85 | public 86 | DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg, 87 | PublicKey key) throws DNSSEC.DNSSECException 88 | { 89 | super(name, Type.DNSKEY, dclass, ttl, flags, proto, alg, 90 | DNSSEC.fromPublicKey(key, alg)); 91 | publicKey = key; 92 | } 93 | 94 | void 95 | rdataFromString(Tokenizer st, Name origin) throws IOException { 96 | flags = st.getUInt16(); 97 | proto = st.getUInt8(); 98 | String algString = st.getString(); 99 | alg = DNSSEC.Algorithm.value(algString); 100 | if (alg < 0) 101 | throw st.exception("Invalid algorithm: " + algString); 102 | key = st.getBase64(); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /org/xbill/DNS/EmptyRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * A class implementing Records with no data; that is, records used in 9 | * the question section of messages and meta-records in dynamic update. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | class EmptyRecord extends Record { 15 | 16 | private static final long serialVersionUID = 3601852050646429582L; 17 | 18 | EmptyRecord() {} 19 | 20 | Record 21 | getObject() { 22 | return new EmptyRecord(); 23 | } 24 | 25 | void 26 | rrFromWire(DNSInput in) throws IOException { 27 | } 28 | 29 | void 30 | rdataFromString(Tokenizer st, Name origin) throws IOException { 31 | } 32 | 33 | String 34 | rrToString() { 35 | return ""; 36 | } 37 | 38 | void 39 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /org/xbill/DNS/ExtendedFlags.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Constants and functions relating to EDNS flags. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public final class ExtendedFlags { 12 | 13 | private static Mnemonic extflags = new Mnemonic("EDNS Flag", 14 | Mnemonic.CASE_LOWER); 15 | 16 | /** dnssec ok */ 17 | public static final int DO = 0x8000; 18 | 19 | static { 20 | extflags.setMaximum(0xFFFF); 21 | extflags.setPrefix("FLAG"); 22 | extflags.setNumericAllowed(true); 23 | 24 | extflags.add(DO, "do"); 25 | } 26 | 27 | private 28 | ExtendedFlags() {} 29 | 30 | /** Converts a numeric extended flag into a String */ 31 | public static String 32 | string(int i) { 33 | return extflags.getText(i); 34 | } 35 | 36 | /** 37 | * Converts a textual representation of an extended flag into its numeric 38 | * value 39 | */ 40 | public static int 41 | value(String s) { 42 | return extflags.getValue(s); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /org/xbill/DNS/Flags.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Constants and functions relating to flags in the DNS header. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public final class Flags { 12 | 13 | private static Mnemonic flags = new Mnemonic("DNS Header Flag", 14 | Mnemonic.CASE_LOWER); 15 | 16 | /** query/response */ 17 | public static final byte QR = 0; 18 | 19 | /** authoritative answer */ 20 | public static final byte AA = 5; 21 | 22 | /** truncated */ 23 | public static final byte TC = 6; 24 | 25 | /** recursion desired */ 26 | public static final byte RD = 7; 27 | 28 | /** recursion available */ 29 | public static final byte RA = 8; 30 | 31 | /** authenticated data */ 32 | public static final byte AD = 10; 33 | 34 | /** (security) checking disabled */ 35 | public static final byte CD = 11; 36 | 37 | /** dnssec ok (extended) */ 38 | public static final int DO = ExtendedFlags.DO; 39 | 40 | static { 41 | flags.setMaximum(0xF); 42 | flags.setPrefix("FLAG"); 43 | flags.setNumericAllowed(true); 44 | 45 | flags.add(QR, "qr"); 46 | flags.add(AA, "aa"); 47 | flags.add(TC, "tc"); 48 | flags.add(RD, "rd"); 49 | flags.add(RA, "ra"); 50 | flags.add(AD, "ad"); 51 | flags.add(CD, "cd"); 52 | } 53 | 54 | private 55 | Flags() {} 56 | 57 | /** Converts a numeric Flag into a String */ 58 | public static String 59 | string(int i) { 60 | return flags.getText(i); 61 | } 62 | 63 | /** Converts a String representation of an Flag into its numeric value */ 64 | public static int 65 | value(String s) { 66 | return flags.getValue(s); 67 | } 68 | 69 | /** 70 | * Indicates if a bit in the flags field is a flag or not. If it's part of 71 | * the rcode or opcode, it's not. 72 | */ 73 | public static boolean 74 | isFlag(int index) { 75 | flags.check(index); 76 | if ((index >= 1 && index <= 4) || (index >= 12)) 77 | return false; 78 | return true; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /org/xbill/DNS/FormattedTime.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.util.*; 6 | import java.text.*; 7 | 8 | /** 9 | * Routines for converting time values to and from YYYYMMDDHHMMSS format. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | final class FormattedTime { 14 | 15 | private static NumberFormat w2, w4; 16 | 17 | static { 18 | w2 = new DecimalFormat(); 19 | w2.setMinimumIntegerDigits(2); 20 | 21 | w4 = new DecimalFormat(); 22 | w4.setMinimumIntegerDigits(4); 23 | w4.setGroupingUsed(false); 24 | } 25 | 26 | private 27 | FormattedTime() {} 28 | 29 | /** 30 | * Converts a Date into a formatted string. 31 | * @param date The Date to convert. 32 | * @return The formatted string. 33 | */ 34 | public static String 35 | format(Date date) { 36 | Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC")); 37 | StringBuffer sb = new StringBuffer(); 38 | 39 | c.setTime(date); 40 | sb.append(w4.format(c.get(Calendar.YEAR))); 41 | sb.append(w2.format(c.get(Calendar.MONTH)+1)); 42 | sb.append(w2.format(c.get(Calendar.DAY_OF_MONTH))); 43 | sb.append(w2.format(c.get(Calendar.HOUR_OF_DAY))); 44 | sb.append(w2.format(c.get(Calendar.MINUTE))); 45 | sb.append(w2.format(c.get(Calendar.SECOND))); 46 | return sb.toString(); 47 | } 48 | 49 | /** 50 | * Parses a formatted time string into a Date. 51 | * @param s The string, in the form YYYYMMDDHHMMSS. 52 | * @return The Date object. 53 | * @throws TextParseException The string was invalid. 54 | */ 55 | public static Date 56 | parse(String s) throws TextParseException { 57 | if (s.length() != 14) { 58 | throw new TextParseException("Invalid time encoding: " + s); 59 | } 60 | 61 | Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC")); 62 | c.clear(); 63 | try { 64 | int year = Integer.parseInt(s.substring(0, 4)); 65 | int month = Integer.parseInt(s.substring(4, 6)) - 1; 66 | int date = Integer.parseInt(s.substring(6, 8)); 67 | int hour = Integer.parseInt(s.substring(8, 10)); 68 | int minute = Integer.parseInt(s.substring(10, 12)); 69 | int second = Integer.parseInt(s.substring(12, 14)); 70 | c.set(year, month, date, hour, minute, second); 71 | } 72 | catch (NumberFormatException e) { 73 | throw new TextParseException("Invalid time encoding: " + s); 74 | } 75 | return c.getTime(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /org/xbill/DNS/GenericEDNSOption.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | package org.xbill.DNS; 3 | 4 | import java.io.*; 5 | 6 | import org.xbill.DNS.utils.base16; 7 | 8 | /** 9 | * An EDNSOption with no internal structure. 10 | * 11 | * @author Ming Zhou <mizhou@bnivideo.com>, Beaumaris Networks 12 | * @author Brian Wellington 13 | */ 14 | public class GenericEDNSOption extends EDNSOption { 15 | 16 | private byte [] data; 17 | 18 | GenericEDNSOption(int code) { 19 | super(code); 20 | } 21 | 22 | /** 23 | * Construct a generic EDNS option. 24 | * @param data The contents of the option. 25 | */ 26 | public 27 | GenericEDNSOption(int code, byte [] data) { 28 | super(code); 29 | this.data = Record.checkByteArrayLength("option data", data, 0xFFFF); 30 | } 31 | 32 | void 33 | optionFromWire(DNSInput in) throws IOException { 34 | data = in.readByteArray(); 35 | } 36 | 37 | void 38 | optionToWire(DNSOutput out) { 39 | out.writeByteArray(data); 40 | } 41 | 42 | String 43 | optionToString() { 44 | return "<" + base16.toString(data) + ">"; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /org/xbill/DNS/HINFORecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Host Information - describes the CPU and OS of a host 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class HINFORecord extends Record { 14 | 15 | private static final long serialVersionUID = -4732870630947452112L; 16 | 17 | private byte [] cpu, os; 18 | 19 | HINFORecord() {} 20 | 21 | Record 22 | getObject() { 23 | return new HINFORecord(); 24 | } 25 | 26 | /** 27 | * Creates an HINFO Record from the given data 28 | * @param cpu A string describing the host's CPU 29 | * @param os A string describing the host's OS 30 | * @throws IllegalArgumentException One of the strings has invalid escapes 31 | */ 32 | public 33 | HINFORecord(Name name, int dclass, long ttl, String cpu, String os) { 34 | super(name, Type.HINFO, dclass, ttl); 35 | try { 36 | this.cpu = byteArrayFromString(cpu); 37 | this.os = byteArrayFromString(os); 38 | } 39 | catch (TextParseException e) { 40 | throw new IllegalArgumentException(e.getMessage()); 41 | } 42 | } 43 | 44 | void 45 | rrFromWire(DNSInput in) throws IOException { 46 | cpu = in.readCountedString(); 47 | os = in.readCountedString(); 48 | } 49 | 50 | void 51 | rdataFromString(Tokenizer st, Name origin) throws IOException { 52 | try { 53 | cpu = byteArrayFromString(st.getString()); 54 | os = byteArrayFromString(st.getString()); 55 | } 56 | catch (TextParseException e) { 57 | throw st.exception(e.getMessage()); 58 | } 59 | } 60 | 61 | /** 62 | * Returns the host's CPU 63 | */ 64 | public String 65 | getCPU() { 66 | return byteArrayToString(cpu, false); 67 | } 68 | 69 | /** 70 | * Returns the host's OS 71 | */ 72 | public String 73 | getOS() { 74 | return byteArrayToString(os, false); 75 | } 76 | 77 | void 78 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 79 | out.writeCountedString(cpu); 80 | out.writeCountedString(os); 81 | } 82 | 83 | /** 84 | * Converts to a string 85 | */ 86 | String 87 | rrToString() { 88 | StringBuffer sb = new StringBuffer(); 89 | sb.append(byteArrayToString(cpu, true)); 90 | sb.append(" "); 91 | sb.append(byteArrayToString(os, true)); 92 | return sb.toString(); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /org/xbill/DNS/ISDNRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * ISDN - identifies the ISDN number and subaddress associated with a name. 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class ISDNRecord extends Record { 14 | 15 | private static final long serialVersionUID = -8730801385178968798L; 16 | 17 | private byte [] address; 18 | private byte [] subAddress; 19 | 20 | ISDNRecord() {} 21 | 22 | Record 23 | getObject() { 24 | return new ISDNRecord(); 25 | } 26 | 27 | /** 28 | * Creates an ISDN Record from the given data 29 | * @param address The ISDN number associated with the domain. 30 | * @param subAddress The subaddress, if any. 31 | * @throws IllegalArgumentException One of the strings is invalid. 32 | */ 33 | public 34 | ISDNRecord(Name name, int dclass, long ttl, String address, String subAddress) { 35 | super(name, Type.ISDN, dclass, ttl); 36 | try { 37 | this.address = byteArrayFromString(address); 38 | if (subAddress != null) 39 | this.subAddress = byteArrayFromString(subAddress); 40 | } 41 | catch (TextParseException e) { 42 | throw new IllegalArgumentException(e.getMessage()); 43 | } 44 | } 45 | 46 | void 47 | rrFromWire(DNSInput in) throws IOException { 48 | address = in.readCountedString(); 49 | if (in.remaining() > 0) 50 | subAddress = in.readCountedString(); 51 | } 52 | 53 | void 54 | rdataFromString(Tokenizer st, Name origin) throws IOException { 55 | try { 56 | address = byteArrayFromString(st.getString()); 57 | Tokenizer.Token t = st.get(); 58 | if (t.isString()) { 59 | subAddress = byteArrayFromString(t.value); 60 | } else { 61 | st.unget(); 62 | } 63 | } 64 | catch (TextParseException e) { 65 | throw st.exception(e.getMessage()); 66 | } 67 | } 68 | 69 | /** 70 | * Returns the ISDN number associated with the domain. 71 | */ 72 | public String 73 | getAddress() { 74 | return byteArrayToString(address, false); 75 | } 76 | 77 | /** 78 | * Returns the ISDN subaddress, or null if there is none. 79 | */ 80 | public String 81 | getSubAddress() { 82 | if (subAddress == null) 83 | return null; 84 | return byteArrayToString(subAddress, false); 85 | } 86 | 87 | void 88 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 89 | out.writeCountedString(address); 90 | if (subAddress != null) 91 | out.writeCountedString(subAddress); 92 | } 93 | 94 | String 95 | rrToString() { 96 | StringBuffer sb = new StringBuffer(); 97 | sb.append(byteArrayToString(address, true)); 98 | if (subAddress != null) { 99 | sb.append(" "); 100 | sb.append(byteArrayToString(subAddress, true)); 101 | } 102 | return sb.toString(); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /org/xbill/DNS/InvalidDClassException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * An exception thrown when an invalid dclass code is specified. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class InvalidDClassException extends IllegalArgumentException { 12 | 13 | public 14 | InvalidDClassException(int dclass) { 15 | super("Invalid DNS class: " + dclass); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /org/xbill/DNS/InvalidTTLException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * An exception thrown when an invalid TTL is specified. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class InvalidTTLException extends IllegalArgumentException { 12 | 13 | public 14 | InvalidTTLException(long ttl) { 15 | super("Invalid DNS TTL: " + ttl); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /org/xbill/DNS/InvalidTypeException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * An exception thrown when an invalid type code is specified. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class InvalidTypeException extends IllegalArgumentException { 12 | 13 | public 14 | InvalidTypeException(int type) { 15 | super("Invalid DNS type: " + type); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /org/xbill/DNS/KXRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Key Exchange - delegation of authority 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class KXRecord extends U16NameBase { 12 | 13 | private static final long serialVersionUID = 7448568832769757809L; 14 | 15 | KXRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new KXRecord(); 20 | } 21 | 22 | /** 23 | * Creates a KX Record from the given data 24 | * @param preference The preference of this KX. Records with lower priority 25 | * are preferred. 26 | * @param target The host that authority is delegated to 27 | */ 28 | public 29 | KXRecord(Name name, int dclass, long ttl, int preference, Name target) { 30 | super(name, Type.KX, dclass, ttl, preference, "preference", 31 | target, "target"); 32 | } 33 | 34 | /** Returns the target of the KX record */ 35 | public Name 36 | getTarget() { 37 | return getNameField(); 38 | } 39 | 40 | /** Returns the preference of this KX record */ 41 | public int 42 | getPreference() { 43 | return getU16Field(); 44 | } 45 | 46 | public Name 47 | getAdditionalName() { 48 | return getNameField(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /org/xbill/DNS/MBRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Mailbox Record - specifies a host containing a mailbox. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class MBRecord extends SingleNameBase { 12 | 13 | private static final long serialVersionUID = 532349543479150419L; 14 | 15 | MBRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new MBRecord(); 20 | } 21 | 22 | /** 23 | * Creates a new MB Record with the given data 24 | * @param mailbox The host containing the mailbox for the domain. 25 | */ 26 | public 27 | MBRecord(Name name, int dclass, long ttl, Name mailbox) { 28 | super(name, Type.MB, dclass, ttl, mailbox, "mailbox"); 29 | } 30 | 31 | /** Gets the mailbox for the domain */ 32 | public Name 33 | getMailbox() { 34 | return getSingleName(); 35 | } 36 | 37 | public Name 38 | getAdditionalName() { 39 | return getSingleName(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /org/xbill/DNS/MDRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Mail Destination Record - specifies a mail agent which delivers mail 7 | * for a domain (obsolete) 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | public class MDRecord extends SingleNameBase { 13 | 14 | private static final long serialVersionUID = 5268878603762942202L; 15 | 16 | MDRecord() {} 17 | 18 | Record 19 | getObject() { 20 | return new MDRecord(); 21 | } 22 | 23 | /** 24 | * Creates a new MD Record with the given data 25 | * @param mailAgent The mail agent that delivers mail for the domain. 26 | */ 27 | public 28 | MDRecord(Name name, int dclass, long ttl, Name mailAgent) { 29 | super(name, Type.MD, dclass, ttl, mailAgent, "mail agent"); 30 | } 31 | 32 | /** Gets the mail agent for the domain */ 33 | public Name 34 | getMailAgent() { 35 | return getSingleName(); 36 | } 37 | 38 | public Name 39 | getAdditionalName() { 40 | return getSingleName(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /org/xbill/DNS/MFRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Mail Forwarder Record - specifies a mail agent which forwards mail 7 | * for a domain (obsolete) 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | public class MFRecord extends SingleNameBase { 13 | 14 | private static final long serialVersionUID = -6670449036843028169L; 15 | 16 | MFRecord() {} 17 | 18 | Record 19 | getObject() { 20 | return new MFRecord(); 21 | } 22 | 23 | /** 24 | * Creates a new MF Record with the given data 25 | * @param mailAgent The mail agent that forwards mail for the domain. 26 | */ 27 | public 28 | MFRecord(Name name, int dclass, long ttl, Name mailAgent) { 29 | super(name, Type.MF, dclass, ttl, mailAgent, "mail agent"); 30 | } 31 | 32 | /** Gets the mail agent for the domain */ 33 | public Name 34 | getMailAgent() { 35 | return getSingleName(); 36 | } 37 | 38 | public Name 39 | getAdditionalName() { 40 | return getSingleName(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /org/xbill/DNS/MGRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Mail Group Record - specifies a mailbox which is a member of a mail group. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class MGRecord extends SingleNameBase { 12 | 13 | private static final long serialVersionUID = -3980055550863644582L; 14 | 15 | MGRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new MGRecord(); 20 | } 21 | 22 | /** 23 | * Creates a new MG Record with the given data 24 | * @param mailbox The mailbox that is a member of the group specified by the 25 | * domain. 26 | */ 27 | public 28 | MGRecord(Name name, int dclass, long ttl, Name mailbox) { 29 | super(name, Type.MG, dclass, ttl, mailbox, "mailbox"); 30 | } 31 | 32 | /** Gets the mailbox in the mail group specified by the domain */ 33 | public Name 34 | getMailbox() { 35 | return getSingleName(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /org/xbill/DNS/MINFORecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Mailbox information Record - lists the address responsible for a mailing 9 | * list/mailbox and the address to receive error messages relating to the 10 | * mailing list/mailbox. 11 | * 12 | * @author Brian Wellington 13 | */ 14 | 15 | public class MINFORecord extends Record { 16 | 17 | private static final long serialVersionUID = -3962147172340353796L; 18 | 19 | private Name responsibleAddress; 20 | private Name errorAddress; 21 | 22 | MINFORecord() {} 23 | 24 | Record 25 | getObject() { 26 | return new MINFORecord(); 27 | } 28 | 29 | /** 30 | * Creates an MINFO Record from the given data 31 | * @param responsibleAddress The address responsible for the 32 | * mailing list/mailbox. 33 | * @param errorAddress The address to receive error messages relating to the 34 | * mailing list/mailbox. 35 | */ 36 | public 37 | MINFORecord(Name name, int dclass, long ttl, 38 | Name responsibleAddress, Name errorAddress) 39 | { 40 | super(name, Type.MINFO, dclass, ttl); 41 | 42 | this.responsibleAddress = checkName("responsibleAddress", 43 | responsibleAddress); 44 | this.errorAddress = checkName("errorAddress", errorAddress); 45 | } 46 | 47 | void 48 | rrFromWire(DNSInput in) throws IOException { 49 | responsibleAddress = new Name(in); 50 | errorAddress = new Name(in); 51 | } 52 | 53 | void 54 | rdataFromString(Tokenizer st, Name origin) throws IOException { 55 | responsibleAddress = st.getName(origin); 56 | errorAddress = st.getName(origin); 57 | } 58 | 59 | /** Converts the MINFO Record to a String */ 60 | String 61 | rrToString() { 62 | StringBuffer sb = new StringBuffer(); 63 | sb.append(responsibleAddress); 64 | sb.append(" "); 65 | sb.append(errorAddress); 66 | return sb.toString(); 67 | } 68 | 69 | /** Gets the address responsible for the mailing list/mailbox. */ 70 | public Name 71 | getResponsibleAddress() { 72 | return responsibleAddress; 73 | } 74 | 75 | /** 76 | * Gets the address to receive error messages relating to the mailing 77 | * list/mailbox. 78 | */ 79 | public Name 80 | getErrorAddress() { 81 | return errorAddress; 82 | } 83 | 84 | void 85 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 86 | responsibleAddress.toWire(out, null, canonical); 87 | errorAddress.toWire(out, null, canonical); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /org/xbill/DNS/MRRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Mailbox Rename Record - specifies a rename of a mailbox. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class MRRecord extends SingleNameBase { 12 | 13 | private static final long serialVersionUID = -5617939094209927533L; 14 | 15 | MRRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new MRRecord(); 20 | } 21 | 22 | /** 23 | * Creates a new MR Record with the given data 24 | * @param newName The new name of the mailbox specified by the domain. 25 | * domain. 26 | */ 27 | public 28 | MRRecord(Name name, int dclass, long ttl, Name newName) { 29 | super(name, Type.MR, dclass, ttl, newName, "new name"); 30 | } 31 | 32 | /** Gets the new name of the mailbox specified by the domain */ 33 | public Name 34 | getNewName() { 35 | return getSingleName(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /org/xbill/DNS/MXRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Mail Exchange - specifies where mail to a domain is sent 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class MXRecord extends U16NameBase { 12 | 13 | private static final long serialVersionUID = 2914841027584208546L; 14 | 15 | MXRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new MXRecord(); 20 | } 21 | 22 | /** 23 | * Creates an MX Record from the given data 24 | * @param priority The priority of this MX. Records with lower priority 25 | * are preferred. 26 | * @param target The host that mail is sent to 27 | */ 28 | public 29 | MXRecord(Name name, int dclass, long ttl, int priority, Name target) { 30 | super(name, Type.MX, dclass, ttl, priority, "priority", 31 | target, "target"); 32 | } 33 | 34 | /** Returns the target of the MX record */ 35 | public Name 36 | getTarget() { 37 | return getNameField(); 38 | } 39 | 40 | /** Returns the priority of this MX record */ 41 | public int 42 | getPriority() { 43 | return getU16Field(); 44 | } 45 | 46 | void 47 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 48 | out.writeU16(u16Field); 49 | nameField.toWire(out, c, canonical); 50 | } 51 | 52 | public Name 53 | getAdditionalName() { 54 | return getNameField(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /org/xbill/DNS/NSAPRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import org.xbill.DNS.utils.*; 7 | 8 | /** 9 | * NSAP Address Record. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class NSAPRecord extends Record { 15 | 16 | private static final long serialVersionUID = -1037209403185658593L; 17 | 18 | private byte [] address; 19 | 20 | NSAPRecord() {} 21 | 22 | Record 23 | getObject() { 24 | return new NSAPRecord(); 25 | } 26 | 27 | private static final byte [] 28 | checkAndConvertAddress(String address) { 29 | if (!address.substring(0, 2).equalsIgnoreCase("0x")) { 30 | return null; 31 | } 32 | ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 33 | boolean partial = false; 34 | int current = 0; 35 | for (int i = 2; i < address.length(); i++) { 36 | char c = address.charAt(i); 37 | if (c == '.') { 38 | continue; 39 | } 40 | int value = Character.digit(c, 16); 41 | if (value == -1) { 42 | return null; 43 | } 44 | if (partial) { 45 | current += value; 46 | bytes.write(current); 47 | partial = false; 48 | } else { 49 | current = value << 4; 50 | partial = true; 51 | } 52 | 53 | } 54 | if (partial) { 55 | return null; 56 | } 57 | return bytes.toByteArray(); 58 | } 59 | 60 | /** 61 | * Creates an NSAP Record from the given data 62 | * @param address The NSAP address. 63 | * @throws IllegalArgumentException The address is not a valid NSAP address. 64 | */ 65 | public 66 | NSAPRecord(Name name, int dclass, long ttl, String address) { 67 | super(name, Type.NSAP, dclass, ttl); 68 | this.address = checkAndConvertAddress(address); 69 | if (this.address == null) { 70 | throw new IllegalArgumentException("invalid NSAP address " + 71 | address); 72 | } 73 | } 74 | 75 | void 76 | rrFromWire(DNSInput in) throws IOException { 77 | address = in.readByteArray(); 78 | } 79 | 80 | void 81 | rdataFromString(Tokenizer st, Name origin) throws IOException { 82 | String addr = st.getString(); 83 | this.address = checkAndConvertAddress(addr); 84 | if (this.address == null) 85 | throw st.exception("invalid NSAP address " + addr); 86 | } 87 | 88 | /** 89 | * Returns the NSAP address. 90 | */ 91 | public String 92 | getAddress() { 93 | return byteArrayToString(address, false); 94 | } 95 | 96 | void 97 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 98 | out.writeByteArray(address); 99 | } 100 | 101 | String 102 | rrToString() { 103 | return "0x" + base16.toString(address); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /org/xbill/DNS/NSAP_PTRRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * NSAP Pointer Record - maps a domain name representing an NSAP Address to 7 | * a hostname. 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | public class NSAP_PTRRecord extends SingleNameBase { 13 | 14 | private static final long serialVersionUID = 2386284746382064904L; 15 | 16 | NSAP_PTRRecord() {} 17 | 18 | Record 19 | getObject() { 20 | return new NSAP_PTRRecord(); 21 | } 22 | 23 | /** 24 | * Creates a new NSAP_PTR Record with the given data 25 | * @param target The name of the host with this address 26 | */ 27 | public 28 | NSAP_PTRRecord(Name name, int dclass, long ttl, Name target) { 29 | super(name, Type.NSAP_PTR, dclass, ttl, target, "target"); 30 | } 31 | 32 | /** Gets the target of the NSAP_PTR Record */ 33 | public Name 34 | getTarget() { 35 | return getSingleName(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /org/xbill/DNS/NSECRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Next SECure name - this record contains the following name in an 9 | * ordered list of names in the zone, and a set of types for which 10 | * records exist for this name. The presence of this record in a response 11 | * signifies a negative response from a DNSSEC-signed zone. 12 | * 13 | * This replaces the NXT record. 14 | * 15 | * @author Brian Wellington 16 | * @author David Blacka 17 | */ 18 | 19 | public class NSECRecord extends Record { 20 | 21 | private static final long serialVersionUID = -5165065768816265385L; 22 | 23 | private Name next; 24 | private TypeBitmap types; 25 | 26 | NSECRecord() {} 27 | 28 | Record 29 | getObject() { 30 | return new NSECRecord(); 31 | } 32 | 33 | /** 34 | * Creates an NSEC Record from the given data. 35 | * @param next The following name in an ordered list of the zone 36 | * @param types An array containing the types present. 37 | */ 38 | public 39 | NSECRecord(Name name, int dclass, long ttl, Name next, int [] types) { 40 | super(name, Type.NSEC, dclass, ttl); 41 | this.next = checkName("next", next); 42 | for (int i = 0; i < types.length; i++) { 43 | Type.check(types[i]); 44 | } 45 | this.types = new TypeBitmap(types); 46 | } 47 | 48 | void 49 | rrFromWire(DNSInput in) throws IOException { 50 | next = new Name(in); 51 | types = new TypeBitmap(in); 52 | } 53 | 54 | void 55 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 56 | // Note: The next name is not lowercased. 57 | next.toWire(out, null, false); 58 | types.toWire(out); 59 | } 60 | 61 | void 62 | rdataFromString(Tokenizer st, Name origin) throws IOException { 63 | next = st.getName(origin); 64 | types = new TypeBitmap(st); 65 | } 66 | 67 | /** Converts rdata to a String */ 68 | String 69 | rrToString() 70 | { 71 | StringBuffer sb = new StringBuffer(); 72 | sb.append(next); 73 | if (!types.empty()) { 74 | sb.append(' '); 75 | sb.append(types.toString()); 76 | } 77 | return sb.toString(); 78 | } 79 | 80 | /** Returns the next name */ 81 | public Name 82 | getNext() { 83 | return next; 84 | } 85 | 86 | /** Returns the set of types defined for this name */ 87 | public int [] 88 | getTypes() { 89 | return types.toArray(); 90 | } 91 | 92 | /** Returns whether a specific type is in the set of types. */ 93 | public boolean 94 | hasType(int type) { 95 | return types.contains(type); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /org/xbill/DNS/NSIDOption.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * The Name Server Identifier Option, define in RFC 5001. 7 | * 8 | * @see OPTRecord 9 | * 10 | * @author Brian Wellington 11 | */ 12 | public class NSIDOption extends GenericEDNSOption { 13 | 14 | private static final long serialVersionUID = 74739759292589056L; 15 | 16 | NSIDOption() { 17 | super(EDNSOption.Code.NSID); 18 | } 19 | 20 | /** 21 | * Construct an NSID option. 22 | * @param data The contents of the option. 23 | */ 24 | public 25 | NSIDOption(byte [] data) { 26 | super(EDNSOption.Code.NSID, data); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /org/xbill/DNS/NSRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Name Server Record - contains the name server serving the named zone 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class NSRecord extends SingleCompressedNameBase { 12 | 13 | private static final long serialVersionUID = 487170758138268838L; 14 | 15 | NSRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new NSRecord(); 20 | } 21 | 22 | /** 23 | * Creates a new NS Record with the given data 24 | * @param target The name server for the given domain 25 | */ 26 | public 27 | NSRecord(Name name, int dclass, long ttl, Name target) { 28 | super(name, Type.NS, dclass, ttl, target, "target"); 29 | } 30 | 31 | /** Gets the target of the NS Record */ 32 | public Name 33 | getTarget() { 34 | return getSingleName(); 35 | } 36 | 37 | public Name 38 | getAdditionalName() { 39 | return getSingleName(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /org/xbill/DNS/NULLRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * The NULL Record. This has no defined purpose, but can be used to 9 | * hold arbitrary data. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class NULLRecord extends Record { 15 | 16 | private static final long serialVersionUID = -5796493183235216538L; 17 | 18 | private byte [] data; 19 | 20 | NULLRecord() {} 21 | 22 | Record 23 | getObject() { 24 | return new NULLRecord(); 25 | } 26 | 27 | /** 28 | * Creates a NULL record from the given data. 29 | * @param data The contents of the record. 30 | */ 31 | public 32 | NULLRecord(Name name, int dclass, long ttl, byte [] data) { 33 | super(name, Type.NULL, dclass, ttl); 34 | 35 | if (data.length > 0xFFFF) { 36 | throw new IllegalArgumentException("data must be <65536 bytes"); 37 | } 38 | this.data = data; 39 | } 40 | 41 | void 42 | rrFromWire(DNSInput in) throws IOException { 43 | data = in.readByteArray(); 44 | } 45 | 46 | void 47 | rdataFromString(Tokenizer st, Name origin) throws IOException { 48 | throw st.exception("no defined text format for NULL records"); 49 | } 50 | 51 | String 52 | rrToString() { 53 | return unknownToString(data); 54 | } 55 | 56 | /** Returns the contents of this record. */ 57 | public byte [] 58 | getData() { 59 | return data; 60 | } 61 | 62 | void 63 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 64 | out.writeByteArray(data); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /org/xbill/DNS/NXTRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import java.util.*; 7 | 8 | /** 9 | * Next name - this record contains the following name in an ordered list 10 | * of names in the zone, and a set of types for which records exist for 11 | * this name. The presence of this record in a response signifies a 12 | * failed query for data in a DNSSEC-signed zone. 13 | * 14 | * @author Brian Wellington 15 | */ 16 | 17 | public class NXTRecord extends Record { 18 | 19 | private static final long serialVersionUID = -8851454400765507520L; 20 | 21 | private Name next; 22 | private BitSet bitmap; 23 | 24 | NXTRecord() {} 25 | 26 | Record 27 | getObject() { 28 | return new NXTRecord(); 29 | } 30 | 31 | /** 32 | * Creates an NXT Record from the given data 33 | * @param next The following name in an ordered list of the zone 34 | * @param bitmap The set of type for which records exist at this name 35 | */ 36 | public 37 | NXTRecord(Name name, int dclass, long ttl, Name next, BitSet bitmap) { 38 | super(name, Type.NXT, dclass, ttl); 39 | this.next = checkName("next", next); 40 | this.bitmap = bitmap; 41 | } 42 | 43 | void 44 | rrFromWire(DNSInput in) throws IOException { 45 | next = new Name(in); 46 | bitmap = new BitSet(); 47 | int bitmapLength = in.remaining(); 48 | for (int i = 0; i < bitmapLength; i++) { 49 | int t = in.readU8(); 50 | for (int j = 0; j < 8; j++) 51 | if ((t & (1 << (7 - j))) != 0) 52 | bitmap.set(i * 8 + j); 53 | } 54 | } 55 | 56 | void 57 | rdataFromString(Tokenizer st, Name origin) throws IOException { 58 | next = st.getName(origin); 59 | bitmap = new BitSet(); 60 | while (true) { 61 | Tokenizer.Token t = st.get(); 62 | if (!t.isString()) 63 | break; 64 | int typecode = Type.value(t.value, true); 65 | if (typecode <= 0 || typecode > 128) 66 | throw st.exception("Invalid type: " + t.value); 67 | bitmap.set(typecode); 68 | } 69 | st.unget(); 70 | } 71 | 72 | /** Converts rdata to a String */ 73 | String 74 | rrToString() { 75 | StringBuffer sb = new StringBuffer(); 76 | sb.append(next); 77 | int length = bitmap.length(); 78 | for (short i = 0; i < length; i++) 79 | if (bitmap.get(i)) { 80 | sb.append(" "); 81 | sb.append(Type.string(i)); 82 | } 83 | return sb.toString(); 84 | } 85 | 86 | /** Returns the next name */ 87 | public Name 88 | getNext() { 89 | return next; 90 | } 91 | 92 | /** Returns the set of types defined for this name */ 93 | public BitSet 94 | getBitmap() { 95 | return bitmap; 96 | } 97 | 98 | void 99 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 100 | next.toWire(out, null, canonical); 101 | int length = bitmap.length(); 102 | for (int i = 0, t = 0; i < length; i++) { 103 | t |= (bitmap.get(i) ? (1 << (7 - i % 8)) : 0); 104 | if (i % 8 == 7 || i == length - 1) { 105 | out.writeU8(t); 106 | t = 0; 107 | } 108 | } 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /org/xbill/DNS/NameTooLongException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2002-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * An exception thrown when a name is longer than the maximum length of a DNS 7 | * name. 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | public class NameTooLongException extends WireParseException { 13 | 14 | public 15 | NameTooLongException() { 16 | super(); 17 | } 18 | 19 | public 20 | NameTooLongException(String s) { 21 | super(s); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /org/xbill/DNS/OPENPGPKEYRecord.java: -------------------------------------------------------------------------------- 1 | package org.xbill.DNS; 2 | 3 | import java.io.IOException; 4 | 5 | import org.xbill.DNS.utils.base64; 6 | 7 | /** 8 | * OPENPGPKEY Record - Stores an OpenPGP certificate associated with a name. 9 | * RFC 7929. 10 | * 11 | * @author Brian Wellington 12 | * @author Valentin Hauner 13 | * 14 | */ 15 | public class OPENPGPKEYRecord extends Record { 16 | 17 | private static final long serialVersionUID = -1277262990243423062L; 18 | 19 | private byte [] cert; 20 | 21 | OPENPGPKEYRecord() {} 22 | 23 | Record 24 | getObject() { 25 | return new OPENPGPKEYRecord(); 26 | } 27 | 28 | /** 29 | * Creates an OPENPGPKEY Record from the given data 30 | * 31 | * @param cert Binary data representing the certificate 32 | */ 33 | public 34 | OPENPGPKEYRecord(Name name, int dclass, long ttl, byte [] cert) 35 | { 36 | super(name, Type.OPENPGPKEY, dclass, ttl); 37 | this.cert = cert; 38 | } 39 | 40 | void 41 | rrFromWire(DNSInput in) throws IOException { 42 | cert = in.readByteArray(); 43 | } 44 | 45 | void 46 | rdataFromString(Tokenizer st, Name origin) throws IOException { 47 | cert = st.getBase64(); 48 | } 49 | 50 | /** 51 | * Converts rdata to a String 52 | */ 53 | String 54 | rrToString() { 55 | StringBuffer sb = new StringBuffer(); 56 | if (cert != null) { 57 | if (Options.check("multiline")) { 58 | sb.append("(\n"); 59 | sb.append(base64.formatString(cert, 64, "\t", true)); 60 | } else { 61 | sb.append(base64.toString(cert)); 62 | } 63 | } 64 | return sb.toString(); 65 | } 66 | 67 | /** 68 | * Returns the binary representation of the certificate 69 | */ 70 | public byte [] 71 | getCert() 72 | { 73 | return cert; 74 | } 75 | 76 | void 77 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 78 | out.writeByteArray(cert); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /org/xbill/DNS/Opcode.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Constants and functions relating to DNS opcodes 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public final class Opcode { 12 | 13 | /** A standard query */ 14 | public static final int QUERY = 0; 15 | 16 | /** An inverse query (deprecated) */ 17 | public static final int IQUERY = 1; 18 | 19 | /** A server status request (not used) */ 20 | public static final int STATUS = 2; 21 | 22 | /** 23 | * A message from a primary to a secondary server to initiate a zone transfer 24 | */ 25 | public static final int NOTIFY = 4; 26 | 27 | /** A dynamic update message */ 28 | public static final int UPDATE = 5; 29 | 30 | private static Mnemonic opcodes = new Mnemonic("DNS Opcode", 31 | Mnemonic.CASE_UPPER); 32 | 33 | static { 34 | opcodes.setMaximum(0xF); 35 | opcodes.setPrefix("RESERVED"); 36 | opcodes.setNumericAllowed(true); 37 | 38 | opcodes.add(QUERY, "QUERY"); 39 | opcodes.add(IQUERY, "IQUERY"); 40 | opcodes.add(STATUS, "STATUS"); 41 | opcodes.add(NOTIFY, "NOTIFY"); 42 | opcodes.add(UPDATE, "UPDATE"); 43 | } 44 | 45 | private 46 | Opcode() {} 47 | 48 | /** Converts a numeric Opcode into a String */ 49 | public static String 50 | string(int i) { 51 | return opcodes.getText(i); 52 | } 53 | 54 | /** Converts a String representation of an Opcode into its numeric value */ 55 | public static int 56 | value(String s) { 57 | return opcodes.getValue(s); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /org/xbill/DNS/Options.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * Boolean options:
9 | * bindttl - Print TTLs in BIND format
10 | * multiline - Print records in multiline format
11 | * noprintin - Don't print the class of a record if it's IN
12 | * verbose - Turn on general debugging statements
13 | * verbosemsg - Print all messages sent or received by SimpleResolver
14 | * verbosecompression - Print messages related to name compression
15 | * verbosesec - Print messages related to signature verification
16 | * verbosecache - Print messages related to cache lookups
17 | *
18 | * Valued options:
19 | * tsigfudge=n - Sets the default TSIG fudge value (in seconds)
20 | * sig0validity=n - Sets the default SIG(0) validity period (in seconds)
21 | * 22 | * @author Brian Wellington 23 | */ 24 | 25 | public final class Options { 26 | 27 | private static Map table; 28 | 29 | static { 30 | try { 31 | refresh(); 32 | } 33 | catch (SecurityException e) { 34 | } 35 | } 36 | 37 | private 38 | Options() {} 39 | 40 | public static void 41 | refresh() { 42 | String s = System.getProperty("dnsjava.options"); 43 | if (s != null) { 44 | StringTokenizer st = new StringTokenizer(s, ","); 45 | while (st.hasMoreTokens()) { 46 | String token = st.nextToken(); 47 | int index = token.indexOf('='); 48 | if (index == -1) 49 | set(token); 50 | else { 51 | String option = token.substring(0, index); 52 | String value = token.substring(index + 1); 53 | set(option, value); 54 | } 55 | } 56 | } 57 | } 58 | 59 | /** Clears all defined options */ 60 | public static void 61 | clear() { 62 | table = null; 63 | } 64 | 65 | /** Sets an option to "true" */ 66 | public static void 67 | set(String option) { 68 | if (table == null) 69 | table = new HashMap(); 70 | table.put(option.toLowerCase(), "true"); 71 | } 72 | 73 | /** Sets an option to the the supplied value */ 74 | public static void 75 | set(String option, String value) { 76 | if (table == null) 77 | table = new HashMap(); 78 | table.put(option.toLowerCase(), value.toLowerCase()); 79 | } 80 | 81 | /** Removes an option */ 82 | public static void 83 | unset(String option) { 84 | if (table == null) 85 | return; 86 | table.remove(option.toLowerCase()); 87 | } 88 | 89 | /** Checks if an option is defined */ 90 | public static boolean 91 | check(String option) { 92 | if (table == null) 93 | return false; 94 | return (table.get(option.toLowerCase()) != null); 95 | } 96 | 97 | /** Returns the value of an option */ 98 | public static String 99 | value(String option) { 100 | if (table == null) 101 | return null; 102 | return ((String)table.get(option.toLowerCase())); 103 | } 104 | 105 | /** 106 | * Returns the value of an option as an integer, or -1 if not defined. 107 | */ 108 | public static int 109 | intValue(String option) { 110 | String s = value(option); 111 | if (s != null) { 112 | try { 113 | int val = Integer.parseInt(s); 114 | if (val > 0) 115 | return (val); 116 | } 117 | catch (NumberFormatException e) { 118 | } 119 | } 120 | return (-1); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /org/xbill/DNS/PTRRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Pointer Record - maps a domain name representing an Internet Address to 7 | * a hostname. 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | public class PTRRecord extends SingleCompressedNameBase { 13 | 14 | private static final long serialVersionUID = -8321636610425434192L; 15 | 16 | PTRRecord() {} 17 | 18 | Record 19 | getObject() { 20 | return new PTRRecord(); 21 | } 22 | 23 | /** 24 | * Creates a new PTR Record with the given data 25 | * @param target The name of the machine with this address 26 | */ 27 | public 28 | PTRRecord(Name name, int dclass, long ttl, Name target) { 29 | super(name, Type.PTR, dclass, ttl, target, "target"); 30 | } 31 | 32 | /** Gets the target of the PTR Record */ 33 | public Name 34 | getTarget() { 35 | return getSingleName(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /org/xbill/DNS/PXRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * X.400 mail mapping record. 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class PXRecord extends Record { 14 | 15 | private static final long serialVersionUID = 1811540008806660667L; 16 | 17 | private int preference; 18 | private Name map822; 19 | private Name mapX400; 20 | 21 | PXRecord() {} 22 | 23 | Record 24 | getObject() { 25 | return new PXRecord(); 26 | } 27 | 28 | /** 29 | * Creates an PX Record from the given data 30 | * @param preference The preference of this mail address. 31 | * @param map822 The RFC 822 component of the mail address. 32 | * @param mapX400 The X.400 component of the mail address. 33 | */ 34 | public 35 | PXRecord(Name name, int dclass, long ttl, int preference, 36 | Name map822, Name mapX400) 37 | { 38 | super(name, Type.PX, dclass, ttl); 39 | 40 | this.preference = checkU16("preference", preference); 41 | this.map822 = checkName("map822", map822); 42 | this.mapX400 = checkName("mapX400", mapX400); 43 | } 44 | 45 | void 46 | rrFromWire(DNSInput in) throws IOException { 47 | preference = in.readU16(); 48 | map822 = new Name(in); 49 | mapX400 = new Name(in); 50 | } 51 | 52 | void 53 | rdataFromString(Tokenizer st, Name origin) throws IOException { 54 | preference = st.getUInt16(); 55 | map822 = st.getName(origin); 56 | mapX400 = st.getName(origin); 57 | } 58 | 59 | /** Converts the PX Record to a String */ 60 | String 61 | rrToString() { 62 | StringBuffer sb = new StringBuffer(); 63 | sb.append(preference); 64 | sb.append(" "); 65 | sb.append(map822); 66 | sb.append(" "); 67 | sb.append(mapX400); 68 | return sb.toString(); 69 | } 70 | 71 | void 72 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 73 | out.writeU16(preference); 74 | map822.toWire(out, null, canonical); 75 | mapX400.toWire(out, null, canonical); 76 | } 77 | 78 | /** Gets the preference of the route. */ 79 | public int 80 | getPreference() { 81 | return preference; 82 | } 83 | 84 | /** Gets the RFC 822 component of the mail address. */ 85 | public Name 86 | getMap822() { 87 | return map822; 88 | } 89 | 90 | /** Gets the X.400 component of the mail address. */ 91 | public Name 92 | getMapX400() { 93 | return mapX400; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /org/xbill/DNS/PacketLogger.java: -------------------------------------------------------------------------------- 1 | package org.xbill.DNS; 2 | 3 | import java.net.*; 4 | 5 | /** 6 | * Custom logger that can log all the packets that were send or received. 7 | * @author Damian Minkov 8 | */ 9 | public interface PacketLogger { 10 | public void log(String prefix, SocketAddress local, SocketAddress remote, 11 | byte [] data); 12 | } 13 | -------------------------------------------------------------------------------- /org/xbill/DNS/RPRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Responsible Person Record - lists the mail address of a responsible person 9 | * and a domain where TXT records are available. 10 | * 11 | * @author Tom Scola (tscola@research.att.com) 12 | * @author Brian Wellington 13 | */ 14 | 15 | public class RPRecord extends Record { 16 | 17 | private static final long serialVersionUID = 8124584364211337460L; 18 | 19 | private Name mailbox; 20 | private Name textDomain; 21 | 22 | RPRecord() {} 23 | 24 | Record 25 | getObject() { 26 | return new RPRecord(); 27 | } 28 | 29 | /** 30 | * Creates an RP Record from the given data 31 | * @param mailbox The responsible person 32 | * @param textDomain The address where TXT records can be found 33 | */ 34 | public 35 | RPRecord(Name name, int dclass, long ttl, Name mailbox, Name textDomain) { 36 | super(name, Type.RP, dclass, ttl); 37 | 38 | this.mailbox = checkName("mailbox", mailbox); 39 | this.textDomain = checkName("textDomain", textDomain); 40 | } 41 | 42 | void 43 | rrFromWire(DNSInput in) throws IOException { 44 | mailbox = new Name(in); 45 | textDomain = new Name(in); 46 | } 47 | 48 | void 49 | rdataFromString(Tokenizer st, Name origin) throws IOException { 50 | mailbox = st.getName(origin); 51 | textDomain = st.getName(origin); 52 | } 53 | 54 | /** Converts the RP Record to a String */ 55 | String 56 | rrToString() { 57 | StringBuffer sb = new StringBuffer(); 58 | sb.append(mailbox); 59 | sb.append(" "); 60 | sb.append(textDomain); 61 | return sb.toString(); 62 | } 63 | 64 | /** Gets the mailbox address of the RP Record */ 65 | public Name 66 | getMailbox() { 67 | return mailbox; 68 | } 69 | 70 | /** Gets the text domain info of the RP Record */ 71 | public Name 72 | getTextDomain() { 73 | return textDomain; 74 | } 75 | 76 | void 77 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 78 | mailbox.toWire(out, null, canonical); 79 | textDomain.toWire(out, null, canonical); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /org/xbill/DNS/RRSIGRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * Recource Record Signature - An RRSIG provides the digital signature of an 9 | * RRset, so that the data can be authenticated by a DNSSEC-capable resolver. 10 | * The signature is generated by a key contained in a DNSKEY Record. 11 | * @see RRset 12 | * @see DNSSEC 13 | * @see KEYRecord 14 | * 15 | * @author Brian Wellington 16 | */ 17 | 18 | public class RRSIGRecord extends SIGBase { 19 | 20 | private static final long serialVersionUID = -2609150673537226317L; 21 | 22 | RRSIGRecord() {} 23 | 24 | Record 25 | getObject() { 26 | return new RRSIGRecord(); 27 | } 28 | 29 | /** 30 | * Creates an RRSIG Record from the given data 31 | * @param covered The RRset type covered by this signature 32 | * @param alg The cryptographic algorithm of the key that generated the 33 | * signature 34 | * @param origttl The original TTL of the RRset 35 | * @param expire The time at which the signature expires 36 | * @param timeSigned The time at which this signature was generated 37 | * @param footprint The footprint/key id of the signing key. 38 | * @param signer The owner of the signing key 39 | * @param signature Binary data representing the signature 40 | */ 41 | public 42 | RRSIGRecord(Name name, int dclass, long ttl, int covered, int alg, long origttl, 43 | Date expire, Date timeSigned, int footprint, Name signer, 44 | byte [] signature) 45 | { 46 | super(name, Type.RRSIG, dclass, ttl, covered, alg, origttl, expire, 47 | timeSigned, footprint, signer, signature); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /org/xbill/DNS/RTRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Route Through Record - lists a route preference and intermediate host. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class RTRecord extends U16NameBase { 12 | 13 | private static final long serialVersionUID = -3206215651648278098L; 14 | 15 | RTRecord() {} 16 | 17 | Record 18 | getObject() { 19 | return new RTRecord(); 20 | } 21 | 22 | /** 23 | * Creates an RT Record from the given data 24 | * @param preference The preference of the route. Smaller numbers indicate 25 | * more preferred routes. 26 | * @param intermediateHost The domain name of the host to use as a router. 27 | */ 28 | public 29 | RTRecord(Name name, int dclass, long ttl, int preference, 30 | Name intermediateHost) 31 | { 32 | super(name, Type.RT, dclass, ttl, preference, "preference", 33 | intermediateHost, "intermediateHost"); 34 | } 35 | 36 | /** Gets the preference of the route. */ 37 | public int 38 | getPreference() { 39 | return getU16Field(); 40 | } 41 | 42 | /** Gets the host to use as a router. */ 43 | public Name 44 | getIntermediateHost() { 45 | return getNameField(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /org/xbill/DNS/RelativeNameException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * An exception thrown when a relative name is passed as an argument to 7 | * a method requiring an absolute name. 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | public class RelativeNameException extends IllegalArgumentException { 13 | 14 | public 15 | RelativeNameException(Name name) { 16 | super("'" + name + "' is not an absolute name"); 17 | } 18 | 19 | public 20 | RelativeNameException(String s) { 21 | super(s); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /org/xbill/DNS/ResolveThread.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * A special-purpose thread used by Resolvers (both SimpleResolver and 7 | * ExtendedResolver) to perform asynchronous queries. 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | class ResolveThread extends Thread { 13 | 14 | private Message query; 15 | private Object id; 16 | private ResolverListener listener; 17 | private Resolver res; 18 | 19 | /** Creates a new ResolveThread */ 20 | public 21 | ResolveThread(Resolver res, Message query, Object id, 22 | ResolverListener listener) 23 | { 24 | this.res = res; 25 | this.query = query; 26 | this.id = id; 27 | this.listener = listener; 28 | } 29 | 30 | 31 | /** 32 | * Performs the query, and executes the callback. 33 | */ 34 | public void 35 | run() { 36 | try { 37 | Message response = res.send(query); 38 | listener.receiveMessage(id, response); 39 | } 40 | catch (Exception e) { 41 | listener.handleException(id, e); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /org/xbill/DNS/Resolver.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import java.util.*; 7 | 8 | /** 9 | * Interface describing a resolver. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public interface Resolver { 15 | 16 | /** 17 | * Sets the port to communicate with on the server 18 | * @param port The port to send messages to 19 | */ 20 | void setPort(int port); 21 | 22 | /** 23 | * Sets whether TCP connections will be sent by default 24 | * @param flag Indicates whether TCP connections are made 25 | */ 26 | void setTCP(boolean flag); 27 | 28 | /** 29 | * Sets whether truncated responses will be ignored. If not, a truncated 30 | * response over UDP will cause a retransmission over TCP. 31 | * @param flag Indicates whether truncated responses should be ignored. 32 | */ 33 | void setIgnoreTruncation(boolean flag); 34 | 35 | /** 36 | * Sets the EDNS version used on outgoing messages. 37 | * @param level The EDNS level to use. 0 indicates EDNS0 and -1 indicates no 38 | * EDNS. 39 | * @throws IllegalArgumentException An invalid level was indicated. 40 | */ 41 | void setEDNS(int level); 42 | 43 | /** 44 | * Sets the EDNS information on outgoing messages. 45 | * @param level The EDNS level to use. 0 indicates EDNS0 and -1 indicates no 46 | * EDNS. 47 | * @param payloadSize The maximum DNS packet size that this host is capable 48 | * of receiving over UDP. If 0 is specified, the default (1280) is used. 49 | * @param flags EDNS extended flags to be set in the OPT record. 50 | * @param options EDNS options to be set in the OPT record, specified as a 51 | * List of OPTRecord.Option elements. 52 | * @throws IllegalArgumentException An invalid field was specified. 53 | * @see OPTRecord 54 | */ 55 | void setEDNS(int level, int payloadSize, int flags, List options); 56 | 57 | /** 58 | * Specifies the TSIG key that messages will be signed with 59 | * @param key The key 60 | */ 61 | void setTSIGKey(TSIG key); 62 | 63 | /** 64 | * Sets the amount of time to wait for a response before giving up. 65 | * @param secs The number of seconds to wait. 66 | * @param msecs The number of milliseconds to wait. 67 | */ 68 | void setTimeout(int secs, int msecs); 69 | 70 | /** 71 | * Sets the amount of time to wait for a response before giving up. 72 | * @param secs The number of seconds to wait. 73 | */ 74 | void setTimeout(int secs); 75 | 76 | /** 77 | * Sends a message and waits for a response. 78 | * @param query The query to send. 79 | * @return The response 80 | * @throws IOException An error occurred while sending or receiving. 81 | */ 82 | Message send(Message query) throws IOException; 83 | 84 | /** 85 | * Asynchronously sends a message registering a listener to receive a callback 86 | * on success or exception. Multiple asynchronous lookups can be performed 87 | * in parallel. Since the callback may be invoked before the function returns, 88 | * external synchronization is necessary. 89 | * @param query The query to send 90 | * @param listener The object containing the callbacks. 91 | * @return An identifier, which is also a parameter in the callback 92 | */ 93 | Object sendAsync(final Message query, final ResolverListener listener); 94 | 95 | } 96 | -------------------------------------------------------------------------------- /org/xbill/DNS/ResolverListener.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.util.EventListener; 6 | 7 | /** 8 | * An interface to the asynchronous resolver. 9 | * @see Resolver 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public interface ResolverListener extends EventListener { 15 | 16 | /** 17 | * The callback used by an asynchronous resolver 18 | * @param id The identifier returned by Resolver.sendAsync() 19 | * @param m The response message as returned by the Resolver 20 | */ 21 | void receiveMessage(Object id, Message m); 22 | 23 | /** 24 | * The callback used by an asynchronous resolver when an exception is thrown 25 | * @param id The identifier returned by Resolver.sendAsync() 26 | * @param e The thrown exception 27 | */ 28 | void handleException(Object id, Exception e); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /org/xbill/DNS/SIG0.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2001-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.security.PrivateKey; 6 | import java.util.Date; 7 | 8 | /** 9 | * Creates SIG(0) transaction signatures. 10 | * 11 | * @author Pasi Eronen 12 | * @author Brian Wellington 13 | */ 14 | 15 | public class SIG0 { 16 | 17 | /** 18 | * The default validity period for outgoing SIG(0) signed messages. 19 | * Can be overriden by the sig0validity option. 20 | */ 21 | private static final short VALIDITY = 300; 22 | 23 | private 24 | SIG0() { } 25 | 26 | /** 27 | * Sign a message with SIG(0). The DNS key and private key must refer to the 28 | * same underlying cryptographic key. 29 | * @param message The message to be signed 30 | * @param key The DNSKEY record to use as part of signing 31 | * @param privkey The PrivateKey to use when signing 32 | * @param previous If this message is a response, the SIG(0) from the query 33 | */ 34 | public static void 35 | signMessage(Message message, KEYRecord key, PrivateKey privkey, 36 | SIGRecord previous) throws DNSSEC.DNSSECException 37 | { 38 | 39 | int validity = Options.intValue("sig0validity"); 40 | if (validity < 0) 41 | validity = VALIDITY; 42 | 43 | long now = System.currentTimeMillis(); 44 | Date timeSigned = new Date(now); 45 | Date timeExpires = new Date(now + validity * 1000); 46 | 47 | SIGRecord sig = DNSSEC.signMessage(message, previous, key, privkey, 48 | timeSigned, timeExpires); 49 | 50 | message.addRecord(sig, Section.ADDITIONAL); 51 | } 52 | 53 | /** 54 | * Verify a message using SIG(0). 55 | * @param message The message to be signed 56 | * @param b An array containing the message in unparsed form. This is 57 | * necessary since SIG(0) signs the message in wire format, and we can't 58 | * recreate the exact wire format (with the same name compression). 59 | * @param key The KEY record to verify the signature with. 60 | * @param previous If this message is a response, the SIG(0) from the query 61 | */ 62 | public static void 63 | verifyMessage(Message message, byte [] b, KEYRecord key, SIGRecord previous) 64 | throws DNSSEC.DNSSECException 65 | { 66 | SIGRecord sig = null; 67 | Record [] additional = message.getSectionArray(Section.ADDITIONAL); 68 | for (int i = 0; i < additional.length; i++) { 69 | if (additional[i].getType() != Type.SIG) 70 | continue; 71 | if (((SIGRecord) additional[i]).getTypeCovered() != 0) 72 | continue; 73 | sig = (SIGRecord) additional[i]; 74 | break; 75 | } 76 | DNSSEC.verifyMessage(message, b, sig, previous, key); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /org/xbill/DNS/SIGRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * Signature - A SIG provides the digital signature of an RRset, so that 9 | * the data can be authenticated by a DNSSEC-capable resolver. The 10 | * signature is usually generated by a key contained in a KEYRecord 11 | * @see RRset 12 | * @see DNSSEC 13 | * @see KEYRecord 14 | * 15 | * @author Brian Wellington 16 | */ 17 | 18 | public class SIGRecord extends SIGBase { 19 | 20 | private static final long serialVersionUID = 4963556060953589058L; 21 | 22 | SIGRecord() {} 23 | 24 | Record 25 | getObject() { 26 | return new SIGRecord(); 27 | } 28 | 29 | /** 30 | * Creates an SIG Record from the given data 31 | * @param covered The RRset type covered by this signature 32 | * @param alg The cryptographic algorithm of the key that generated the 33 | * signature 34 | * @param origttl The original TTL of the RRset 35 | * @param expire The time at which the signature expires 36 | * @param timeSigned The time at which this signature was generated 37 | * @param footprint The footprint/key id of the signing key. 38 | * @param signer The owner of the signing key 39 | * @param signature Binary data representing the signature 40 | */ 41 | public 42 | SIGRecord(Name name, int dclass, long ttl, int covered, int alg, long origttl, 43 | Date expire, Date timeSigned, int footprint, Name signer, 44 | byte [] signature) 45 | { 46 | super(name, Type.SIG, dclass, ttl, covered, alg, origttl, expire, 47 | timeSigned, footprint, signer, signature); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /org/xbill/DNS/SPFRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * Sender Policy Framework (RFC 4408, experimental) 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class SPFRecord extends TXTBase { 14 | 15 | private static final long serialVersionUID = -2100754352801658722L; 16 | 17 | SPFRecord() {} 18 | 19 | Record 20 | getObject() { 21 | return new SPFRecord(); 22 | } 23 | 24 | /** 25 | * Creates a SPF Record from the given data 26 | * @param strings The text strings 27 | * @throws IllegalArgumentException One of the strings has invalid escapes 28 | */ 29 | public 30 | SPFRecord(Name name, int dclass, long ttl, List strings) { 31 | super(name, Type.SPF, dclass, ttl, strings); 32 | } 33 | 34 | /** 35 | * Creates a SPF Record from the given data 36 | * @param string One text string 37 | * @throws IllegalArgumentException The string has invalid escapes 38 | */ 39 | public 40 | SPFRecord(Name name, int dclass, long ttl, String string) { 41 | super(name, Type.SPF, dclass, ttl, string); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /org/xbill/DNS/SRVRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Server Selection Record - finds hosts running services in a domain. An 9 | * SRV record will normally be named _<service>._<protocol>.domain 10 | * - examples would be _sips._tcp.example.org (for the secure SIP protocol) and 11 | * _http._tcp.example.com (if HTTP used SRV records) 12 | * 13 | * @author Brian Wellington 14 | */ 15 | 16 | public class SRVRecord extends Record { 17 | 18 | private static final long serialVersionUID = -3886460132387522052L; 19 | 20 | private int priority, weight, port; 21 | private Name target; 22 | 23 | SRVRecord() {} 24 | 25 | Record 26 | getObject() { 27 | return new SRVRecord(); 28 | } 29 | 30 | /** 31 | * Creates an SRV Record from the given data 32 | * @param priority The priority of this SRV. Records with lower priority 33 | * are preferred. 34 | * @param weight The weight, used to select between records at the same 35 | * priority. 36 | * @param port The TCP/UDP port that the service uses 37 | * @param target The host running the service 38 | */ 39 | public 40 | SRVRecord(Name name, int dclass, long ttl, int priority, 41 | int weight, int port, Name target) 42 | { 43 | super(name, Type.SRV, dclass, ttl); 44 | this.priority = checkU16("priority", priority); 45 | this.weight = checkU16("weight", weight); 46 | this.port = checkU16("port", port); 47 | this.target = checkName("target", target); 48 | } 49 | 50 | void 51 | rrFromWire(DNSInput in) throws IOException { 52 | priority = in.readU16(); 53 | weight = in.readU16(); 54 | port = in.readU16(); 55 | target = new Name(in); 56 | } 57 | 58 | void 59 | rdataFromString(Tokenizer st, Name origin) throws IOException { 60 | priority = st.getUInt16(); 61 | weight = st.getUInt16(); 62 | port = st.getUInt16(); 63 | target = st.getName(origin); 64 | } 65 | 66 | /** Converts rdata to a String */ 67 | String 68 | rrToString() { 69 | StringBuffer sb = new StringBuffer(); 70 | sb.append(priority + " "); 71 | sb.append(weight + " "); 72 | sb.append(port + " "); 73 | sb.append(target); 74 | return sb.toString(); 75 | } 76 | 77 | /** Returns the priority */ 78 | public int 79 | getPriority() { 80 | return priority; 81 | } 82 | 83 | /** Returns the weight */ 84 | public int 85 | getWeight() { 86 | return weight; 87 | } 88 | 89 | /** Returns the port that the service runs on */ 90 | public int 91 | getPort() { 92 | return port; 93 | } 94 | 95 | /** Returns the host running that the service */ 96 | public Name 97 | getTarget() { 98 | return target; 99 | } 100 | 101 | void 102 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 103 | out.writeU16(priority); 104 | out.writeU16(weight); 105 | out.writeU16(port); 106 | target.toWire(out, null, canonical); 107 | } 108 | 109 | public Name 110 | getAdditionalName() { 111 | return target; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /org/xbill/DNS/SSHFPRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import org.xbill.DNS.utils.*; 7 | 8 | /** 9 | * SSH Fingerprint - stores the fingerprint of an SSH host key. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class SSHFPRecord extends Record { 15 | 16 | private static final long serialVersionUID = -8104701402654687025L; 17 | 18 | public static class Algorithm { 19 | private Algorithm() {} 20 | 21 | public static final int RSA = 1; 22 | public static final int DSS = 2; 23 | } 24 | 25 | public static class Digest { 26 | private Digest() {} 27 | 28 | public static final int SHA1 = 1; 29 | } 30 | 31 | private int alg; 32 | private int digestType; 33 | private byte [] fingerprint; 34 | 35 | SSHFPRecord() {} 36 | 37 | Record 38 | getObject() { 39 | return new SSHFPRecord(); 40 | } 41 | 42 | /** 43 | * Creates an SSHFP Record from the given data. 44 | * @param alg The public key's algorithm. 45 | * @param digestType The public key's digest type. 46 | * @param fingerprint The public key's fingerprint. 47 | */ 48 | public 49 | SSHFPRecord(Name name, int dclass, long ttl, int alg, int digestType, 50 | byte [] fingerprint) 51 | { 52 | super(name, Type.SSHFP, dclass, ttl); 53 | this.alg = checkU8("alg", alg); 54 | this.digestType = checkU8("digestType", digestType); 55 | this.fingerprint = fingerprint; 56 | } 57 | 58 | void 59 | rrFromWire(DNSInput in) throws IOException { 60 | alg = in.readU8(); 61 | digestType = in.readU8(); 62 | fingerprint = in.readByteArray(); 63 | } 64 | 65 | void 66 | rdataFromString(Tokenizer st, Name origin) throws IOException { 67 | alg = st.getUInt8(); 68 | digestType = st.getUInt8(); 69 | fingerprint = st.getHex(true); 70 | } 71 | 72 | String 73 | rrToString() { 74 | StringBuffer sb = new StringBuffer(); 75 | sb.append(alg); 76 | sb.append(" "); 77 | sb.append(digestType); 78 | sb.append(" "); 79 | sb.append(base16.toString(fingerprint)); 80 | return sb.toString(); 81 | } 82 | 83 | /** Returns the public key's algorithm. */ 84 | public int 85 | getAlgorithm() { 86 | return alg; 87 | } 88 | 89 | /** Returns the public key's digest type. */ 90 | public int 91 | getDigestType() { 92 | return digestType; 93 | } 94 | 95 | /** Returns the fingerprint */ 96 | public byte [] 97 | getFingerPrint() { 98 | return fingerprint; 99 | } 100 | 101 | void 102 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 103 | out.writeU8(alg); 104 | out.writeU8(digestType); 105 | out.writeByteArray(fingerprint); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /org/xbill/DNS/Section.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Constants and functions relating to DNS message sections 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public final class Section { 12 | 13 | /** The question (first) section */ 14 | public static final int QUESTION = 0; 15 | 16 | /** The answer (second) section */ 17 | public static final int ANSWER = 1; 18 | 19 | /** The authority (third) section */ 20 | public static final int AUTHORITY = 2; 21 | 22 | /** The additional (fourth) section */ 23 | public static final int ADDITIONAL = 3; 24 | 25 | /* Aliases for dynamic update */ 26 | /** The zone (first) section of a dynamic update message */ 27 | public static final int ZONE = 0; 28 | 29 | /** The prerequisite (second) section of a dynamic update message */ 30 | public static final int PREREQ = 1; 31 | 32 | /** The update (third) section of a dynamic update message */ 33 | public static final int UPDATE = 2; 34 | 35 | private static Mnemonic sections = new Mnemonic("Message Section", 36 | Mnemonic.CASE_LOWER); 37 | private static String [] longSections = new String[4]; 38 | private static String [] updateSections = new String[4]; 39 | 40 | static { 41 | sections.setMaximum(3); 42 | sections.setNumericAllowed(true); 43 | 44 | sections.add(QUESTION, "qd"); 45 | sections.add(ANSWER, "an"); 46 | sections.add(AUTHORITY, "au"); 47 | sections.add(ADDITIONAL, "ad"); 48 | 49 | longSections[QUESTION] = "QUESTIONS"; 50 | longSections[ANSWER] = "ANSWERS"; 51 | longSections[AUTHORITY] = "AUTHORITY RECORDS"; 52 | longSections[ADDITIONAL] = "ADDITIONAL RECORDS"; 53 | 54 | updateSections[ZONE] = "ZONE"; 55 | updateSections[PREREQ] = "PREREQUISITES"; 56 | updateSections[UPDATE] = "UPDATE RECORDS"; 57 | updateSections[ADDITIONAL] = "ADDITIONAL RECORDS"; 58 | } 59 | 60 | private 61 | Section() {} 62 | 63 | /** Converts a numeric Section into an abbreviation String */ 64 | public static String 65 | string(int i) { 66 | return sections.getText(i); 67 | } 68 | 69 | /** Converts a numeric Section into a full description String */ 70 | public static String 71 | longString(int i) { 72 | sections.check(i); 73 | return longSections[i]; 74 | } 75 | 76 | /** 77 | * Converts a numeric Section into a full description String for an update 78 | * Message. 79 | */ 80 | public static String 81 | updString(int i) { 82 | sections.check(i); 83 | return updateSections[i]; 84 | } 85 | 86 | /** Converts a String representation of a Section into its numeric value */ 87 | public static int 88 | value(String s) { 89 | return sections.getValue(s); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /org/xbill/DNS/Serial.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Helper functions for doing serial arithmetic. These should be used when 7 | * setting/checking SOA serial numbers. SOA serial number arithmetic is 8 | * defined in RFC 1982. 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public final class Serial { 14 | 15 | private static final long MAX32 = 0xFFFFFFFFL; 16 | 17 | private 18 | Serial() { 19 | } 20 | 21 | /** 22 | * Compares two numbers using serial arithmetic. The numbers are assumed 23 | * to be 32 bit unsigned integers stored in longs. 24 | * @param serial1 The first integer 25 | * @param serial2 The second integer 26 | * @return 0 if the 2 numbers are equal, a positive number if serial1 is greater 27 | * than serial2, and a negative number if serial2 is greater than serial1. 28 | * @throws IllegalArgumentException serial1 or serial2 is out of range 29 | */ 30 | public static int 31 | compare(long serial1, long serial2) { 32 | if (serial1 < 0 || serial1 > MAX32) 33 | throw new IllegalArgumentException(serial1 + " out of range"); 34 | if (serial2 < 0 || serial2 > MAX32) 35 | throw new IllegalArgumentException(serial2 + " out of range"); 36 | long diff = serial1 - serial2; 37 | if (diff >= MAX32) 38 | diff -= (MAX32 + 1); 39 | else if (diff < -MAX32) 40 | diff += (MAX32 + 1); 41 | return (int)diff; 42 | } 43 | 44 | /** 45 | * Increments a serial number. The number is assumed to be a 32 bit unsigned 46 | * integer stored in a long. This basically adds 1 and resets the value to 47 | * 0 if it is 2^32. 48 | * @param serial The serial number 49 | * @return The incremented serial number 50 | * @throws IllegalArgumentException serial is out of range 51 | */ 52 | public static long 53 | increment(long serial) { 54 | if (serial < 0 || serial > MAX32) 55 | throw new IllegalArgumentException(serial + " out of range"); 56 | if (serial == MAX32) 57 | return 0; 58 | return serial + 1; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /org/xbill/DNS/SingleCompressedNameBase.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Implements common functionality for the many record types whose format 7 | * is a single compressed name. 8 | * 9 | * @author Brian Wellington 10 | */ 11 | 12 | abstract class SingleCompressedNameBase extends SingleNameBase { 13 | 14 | private static final long serialVersionUID = -236435396815460677L; 15 | 16 | protected 17 | SingleCompressedNameBase() {} 18 | 19 | protected 20 | SingleCompressedNameBase(Name name, int type, int dclass, long ttl, 21 | Name singleName, String description) 22 | { 23 | super(name, type, dclass, ttl, singleName, description); 24 | } 25 | 26 | void 27 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 28 | singleName.toWire(out, c, canonical); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /org/xbill/DNS/SingleNameBase.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Implements common functionality for the many record types whose format 9 | * is a single name. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | abstract class SingleNameBase extends Record { 15 | 16 | private static final long serialVersionUID = -18595042501413L; 17 | 18 | protected Name singleName; 19 | 20 | protected 21 | SingleNameBase() {} 22 | 23 | protected 24 | SingleNameBase(Name name, int type, int dclass, long ttl) { 25 | super(name, type, dclass, ttl); 26 | } 27 | 28 | protected 29 | SingleNameBase(Name name, int type, int dclass, long ttl, Name singleName, 30 | String description) 31 | { 32 | super(name, type, dclass, ttl); 33 | this.singleName = checkName(description, singleName); 34 | } 35 | 36 | void 37 | rrFromWire(DNSInput in) throws IOException { 38 | singleName = new Name(in); 39 | } 40 | 41 | void 42 | rdataFromString(Tokenizer st, Name origin) throws IOException { 43 | singleName = st.getName(origin); 44 | } 45 | 46 | String 47 | rrToString() { 48 | return singleName.toString(); 49 | } 50 | 51 | protected Name 52 | getSingleName() { 53 | return singleName; 54 | } 55 | 56 | void 57 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 58 | singleName.toWire(out, null, canonical); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /org/xbill/DNS/TTL.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * Routines for parsing BIND-style TTL values. These values consist of 7 | * numbers followed by 1 letter units of time (W - week, D - day, H - hour, 8 | * M - minute, S - second). 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public final class TTL { 14 | 15 | public static final long MAX_VALUE = 0x7FFFFFFFL; 16 | 17 | private 18 | TTL() {} 19 | 20 | static void 21 | check(long i) { 22 | if (i < 0 || i > MAX_VALUE) 23 | throw new InvalidTTLException(i); 24 | } 25 | 26 | /** 27 | * Parses a TTL-like value, which can either be expressed as a number or a 28 | * BIND-style string with numbers and units. 29 | * @param s The string representing the numeric value. 30 | * @param clamp Whether to clamp values in the range [MAX_VALUE + 1, 2^32 -1] 31 | * to MAX_VALUE. This should be donw for TTLs, but not other values which 32 | * can be expressed in this format. 33 | * @return The value as a number of seconds 34 | * @throws NumberFormatException The string was not in a valid TTL format. 35 | */ 36 | public static long 37 | parse(String s, boolean clamp) { 38 | if (s == null || s.length() == 0 || !Character.isDigit(s.charAt(0))) 39 | throw new NumberFormatException(); 40 | long value = 0; 41 | long ttl = 0; 42 | for (int i = 0; i < s.length(); i++) { 43 | char c = s.charAt(i); 44 | long oldvalue = value; 45 | if (Character.isDigit(c)) { 46 | value = (value * 10) + Character.getNumericValue(c); 47 | if (value < oldvalue) 48 | throw new NumberFormatException(); 49 | } else { 50 | switch (Character.toUpperCase(c)) { 51 | case 'W': value *= 7; 52 | case 'D': value *= 24; 53 | case 'H': value *= 60; 54 | case 'M': value *= 60; 55 | case 'S': break; 56 | default: throw new NumberFormatException(); 57 | } 58 | ttl += value; 59 | value = 0; 60 | if (ttl > 0xFFFFFFFFL) 61 | throw new NumberFormatException(); 62 | } 63 | } 64 | if (ttl == 0) 65 | ttl = value; 66 | 67 | if (ttl > 0xFFFFFFFFL) 68 | throw new NumberFormatException(); 69 | else if (ttl > MAX_VALUE && clamp) 70 | ttl = MAX_VALUE; 71 | return ttl; 72 | } 73 | 74 | /** 75 | * Parses a TTL, which can either be expressed as a number or a BIND-style 76 | * string with numbers and units. 77 | * @param s The string representing the TTL 78 | * @return The TTL as a number of seconds 79 | * @throws NumberFormatException The string was not in a valid TTL format. 80 | */ 81 | public static long 82 | parseTTL(String s) { 83 | return parse(s, true); 84 | } 85 | 86 | public static String 87 | format(long ttl) { 88 | TTL.check(ttl); 89 | StringBuffer sb = new StringBuffer(); 90 | long secs, mins, hours, days, weeks; 91 | secs = ttl % 60; 92 | ttl /= 60; 93 | mins = ttl % 60; 94 | ttl /= 60; 95 | hours = ttl % 24; 96 | ttl /= 24; 97 | days = ttl % 7; 98 | ttl /= 7; 99 | weeks = ttl; 100 | if (weeks > 0) 101 | sb.append(weeks + "W"); 102 | if (days > 0) 103 | sb.append(days + "D"); 104 | if (hours > 0) 105 | sb.append(hours + "H"); 106 | if (mins > 0) 107 | sb.append(mins + "M"); 108 | if (secs > 0 || (weeks == 0 && days == 0 && hours == 0 && mins == 0)) 109 | sb.append(secs + "S"); 110 | return sb.toString(); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /org/xbill/DNS/TXTBase.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | import java.util.*; 7 | 8 | /** 9 | * Implements common functionality for the many record types whose format 10 | * is a list of strings. 11 | * 12 | * @author Brian Wellington 13 | */ 14 | 15 | abstract class TXTBase extends Record { 16 | 17 | private static final long serialVersionUID = -4319510507246305931L; 18 | 19 | protected List strings; 20 | 21 | protected 22 | TXTBase() {} 23 | 24 | protected 25 | TXTBase(Name name, int type, int dclass, long ttl) { 26 | super(name, type, dclass, ttl); 27 | } 28 | 29 | protected 30 | TXTBase(Name name, int type, int dclass, long ttl, List strings) { 31 | super(name, type, dclass, ttl); 32 | if (strings == null) 33 | throw new IllegalArgumentException("strings must not be null"); 34 | this.strings = new ArrayList(strings.size()); 35 | Iterator it = strings.iterator(); 36 | try { 37 | while (it.hasNext()) { 38 | String s = (String) it.next(); 39 | this.strings.add(byteArrayFromString(s)); 40 | } 41 | } 42 | catch (TextParseException e) { 43 | throw new IllegalArgumentException(e.getMessage()); 44 | } 45 | } 46 | 47 | protected 48 | TXTBase(Name name, int type, int dclass, long ttl, String string) { 49 | this(name, type, dclass, ttl, Collections.singletonList(string)); 50 | } 51 | 52 | void 53 | rrFromWire(DNSInput in) throws IOException { 54 | strings = new ArrayList(2); 55 | while (in.remaining() > 0) { 56 | byte [] b = in.readCountedString(); 57 | strings.add(b); 58 | } 59 | } 60 | 61 | void 62 | rdataFromString(Tokenizer st, Name origin) throws IOException { 63 | strings = new ArrayList(2); 64 | while (true) { 65 | Tokenizer.Token t = st.get(); 66 | if (!t.isString()) 67 | break; 68 | try { 69 | strings.add(byteArrayFromString(t.value)); 70 | } 71 | catch (TextParseException e) { 72 | throw st.exception(e.getMessage()); 73 | } 74 | 75 | } 76 | st.unget(); 77 | } 78 | 79 | /** converts to a String */ 80 | String 81 | rrToString() { 82 | StringBuffer sb = new StringBuffer(); 83 | Iterator it = strings.iterator(); 84 | while (it.hasNext()) { 85 | byte [] array = (byte []) it.next(); 86 | sb.append(byteArrayToString(array, true)); 87 | if (it.hasNext()) 88 | sb.append(" "); 89 | } 90 | return sb.toString(); 91 | } 92 | 93 | /** 94 | * Returns the text strings 95 | * @return A list of Strings corresponding to the text strings. 96 | */ 97 | public List 98 | getStrings() { 99 | List list = new ArrayList(strings.size()); 100 | for (int i = 0; i < strings.size(); i++) 101 | list.add(byteArrayToString((byte []) strings.get(i), false)); 102 | return list; 103 | } 104 | 105 | /** 106 | * Returns the text strings 107 | * @return A list of byte arrays corresponding to the text strings. 108 | */ 109 | public List 110 | getStringsAsByteArrays() { 111 | return strings; 112 | } 113 | 114 | void 115 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 116 | Iterator it = strings.iterator(); 117 | while (it.hasNext()) { 118 | byte [] b = (byte []) it.next(); 119 | out.writeCountedString(b); 120 | } 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /org/xbill/DNS/TXTRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * Text - stores text strings 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class TXTRecord extends TXTBase { 14 | 15 | private static final long serialVersionUID = -5780785764284221342L; 16 | 17 | TXTRecord() {} 18 | 19 | Record 20 | getObject() { 21 | return new TXTRecord(); 22 | } 23 | 24 | /** 25 | * Creates a TXT Record from the given data 26 | * @param strings The text strings 27 | * @throws IllegalArgumentException One of the strings has invalid escapes 28 | */ 29 | public 30 | TXTRecord(Name name, int dclass, long ttl, List strings) { 31 | super(name, Type.TXT, dclass, ttl, strings); 32 | } 33 | 34 | /** 35 | * Creates a TXT Record from the given data 36 | * @param string One text string 37 | * @throws IllegalArgumentException The string has invalid escapes 38 | */ 39 | public 40 | TXTRecord(Name name, int dclass, long ttl, String string) { 41 | super(name, Type.TXT, dclass, ttl, string); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /org/xbill/DNS/TextParseException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2002-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * An exception thrown when unable to parse text. 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class TextParseException extends IOException { 14 | 15 | public 16 | TextParseException() { 17 | super(); 18 | } 19 | 20 | public 21 | TextParseException(String s) { 22 | super(s); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /org/xbill/DNS/U16NameBase.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Implements common functionality for the many record types whose format 9 | * is an unsigned 16 bit integer followed by a name. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | abstract class U16NameBase extends Record { 15 | 16 | private static final long serialVersionUID = -8315884183112502995L; 17 | 18 | protected int u16Field; 19 | protected Name nameField; 20 | 21 | protected 22 | U16NameBase() {} 23 | 24 | protected 25 | U16NameBase(Name name, int type, int dclass, long ttl) { 26 | super(name, type, dclass, ttl); 27 | } 28 | 29 | protected 30 | U16NameBase(Name name, int type, int dclass, long ttl, int u16Field, 31 | String u16Description, Name nameField, String nameDescription) 32 | { 33 | super(name, type, dclass, ttl); 34 | this.u16Field = checkU16(u16Description, u16Field); 35 | this.nameField = checkName(nameDescription, nameField); 36 | } 37 | 38 | void 39 | rrFromWire(DNSInput in) throws IOException { 40 | u16Field = in.readU16(); 41 | nameField = new Name(in); 42 | } 43 | 44 | void 45 | rdataFromString(Tokenizer st, Name origin) throws IOException { 46 | u16Field = st.getUInt16(); 47 | nameField = st.getName(origin); 48 | } 49 | 50 | String 51 | rrToString() { 52 | StringBuffer sb = new StringBuffer(); 53 | sb.append(u16Field); 54 | sb.append(" "); 55 | sb.append(nameField); 56 | return sb.toString(); 57 | } 58 | 59 | protected int 60 | getU16Field() { 61 | return u16Field; 62 | } 63 | 64 | protected Name 65 | getNameField() { 66 | return nameField; 67 | } 68 | 69 | void 70 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 71 | out.writeU16(u16Field); 72 | nameField.toWire(out, null, canonical); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /org/xbill/DNS/UNKRecord.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * A class implementing Records of unknown and/or unimplemented types. This 9 | * class can only be initialized using static Record initializers. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class UNKRecord extends Record { 15 | 16 | private static final long serialVersionUID = -4193583311594626915L; 17 | 18 | private byte [] data; 19 | 20 | UNKRecord() {} 21 | 22 | Record 23 | getObject() { 24 | return new UNKRecord(); 25 | } 26 | 27 | void 28 | rrFromWire(DNSInput in) throws IOException { 29 | data = in.readByteArray(); 30 | } 31 | 32 | void 33 | rdataFromString(Tokenizer st, Name origin) throws IOException { 34 | throw st.exception("invalid unknown RR encoding"); 35 | } 36 | 37 | /** Converts this Record to the String "unknown format" */ 38 | String 39 | rrToString() { 40 | return unknownToString(data); 41 | } 42 | 43 | /** Returns the contents of this record. */ 44 | public byte [] 45 | getData() { 46 | return data; 47 | } 48 | 49 | void 50 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 51 | out.writeByteArray(data); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /org/xbill/DNS/URIRecord.java: -------------------------------------------------------------------------------- 1 | // Implemented by Anthony Kirby (anthony@anthony.org) 2 | // based on SRVRecord.java Copyright (c) 1999-2004 Brian Wellington 3 | 4 | package org.xbill.DNS; 5 | 6 | import java.io.*; 7 | 8 | /** 9 | * Uniform Resource Identifier (URI) DNS Resource Record 10 | * 11 | * @author Anthony Kirby 12 | * @see http://tools.ietf.org/html/draft-faltstrom-uri 13 | */ 14 | 15 | public class URIRecord extends Record { 16 | 17 | private static final long serialVersionUID = 7955422413971804232L; 18 | 19 | private int priority, weight; 20 | private byte[] target; 21 | 22 | URIRecord() { 23 | target = new byte[]{}; 24 | } 25 | 26 | Record 27 | getObject() { 28 | return new URIRecord(); 29 | } 30 | 31 | /** 32 | * Creates a URI Record from the given data 33 | * @param priority The priority of this URI. Records with lower priority 34 | * are preferred. 35 | * @param weight The weight, used to select between records at the same 36 | * priority. 37 | * @param target The host/port running the service 38 | */ 39 | public 40 | URIRecord(Name name, int dclass, long ttl, int priority, 41 | int weight, String target) 42 | { 43 | super(name, Type.URI, dclass, ttl); 44 | this.priority = checkU16("priority", priority); 45 | this.weight = checkU16("weight", weight); 46 | try { 47 | this.target = byteArrayFromString(target); 48 | } 49 | catch (TextParseException e) { 50 | throw new IllegalArgumentException(e.getMessage()); 51 | } 52 | } 53 | 54 | void 55 | rrFromWire(DNSInput in) throws IOException { 56 | priority = in.readU16(); 57 | weight = in.readU16(); 58 | target = in.readByteArray(); 59 | } 60 | 61 | void 62 | rdataFromString(Tokenizer st, Name origin) throws IOException { 63 | priority = st.getUInt16(); 64 | weight = st.getUInt16(); 65 | try { 66 | target = byteArrayFromString(st.getString()); 67 | } 68 | catch (TextParseException e) { 69 | throw st.exception(e.getMessage()); 70 | } 71 | } 72 | 73 | /** Converts rdata to a String */ 74 | String 75 | rrToString() { 76 | StringBuffer sb = new StringBuffer(); 77 | sb.append(priority + " "); 78 | sb.append(weight + " "); 79 | sb.append(byteArrayToString(target, true)); 80 | return sb.toString(); 81 | } 82 | 83 | /** Returns the priority */ 84 | public int 85 | getPriority() { 86 | return priority; 87 | } 88 | 89 | /** Returns the weight */ 90 | public int 91 | getWeight() { 92 | return weight; 93 | } 94 | 95 | /** Returns the target URI */ 96 | public String 97 | getTarget() { 98 | return byteArrayToString(target, false); 99 | } 100 | 101 | void 102 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 103 | out.writeU16(priority); 104 | out.writeU16(weight); 105 | out.writeByteArray(target); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /org/xbill/DNS/WireParseException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * An exception thrown when a DNS message is invalid. 9 | * 10 | * @author Brian Wellington 11 | */ 12 | 13 | public class WireParseException extends IOException { 14 | 15 | public 16 | WireParseException() { 17 | super(); 18 | } 19 | 20 | public 21 | WireParseException(String s) { 22 | super(s); 23 | } 24 | 25 | public 26 | WireParseException(String s, Throwable cause) { 27 | super(s); 28 | initCause(cause); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /org/xbill/DNS/X25Record.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * X25 - identifies the PSDN (Public Switched Data Network) address in the 9 | * X.121 numbering plan associated with a name. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class X25Record extends Record { 15 | 16 | private static final long serialVersionUID = 4267576252335579764L; 17 | 18 | private byte [] address; 19 | 20 | X25Record() {} 21 | 22 | Record 23 | getObject() { 24 | return new X25Record(); 25 | } 26 | 27 | private static final byte [] 28 | checkAndConvertAddress(String address) { 29 | int length = address.length(); 30 | byte [] out = new byte [length]; 31 | for (int i = 0; i < length; i++) { 32 | char c = address.charAt(i); 33 | if (!Character.isDigit(c)) 34 | return null; 35 | out[i] = (byte) c; 36 | } 37 | return out; 38 | } 39 | 40 | /** 41 | * Creates an X25 Record from the given data 42 | * @param address The X.25 PSDN address. 43 | * @throws IllegalArgumentException The address is not a valid PSDN address. 44 | */ 45 | public 46 | X25Record(Name name, int dclass, long ttl, String address) { 47 | super(name, Type.X25, dclass, ttl); 48 | this.address = checkAndConvertAddress(address); 49 | if (this.address == null) { 50 | throw new IllegalArgumentException("invalid PSDN address " + 51 | address); 52 | } 53 | } 54 | 55 | void 56 | rrFromWire(DNSInput in) throws IOException { 57 | address = in.readCountedString(); 58 | } 59 | 60 | void 61 | rdataFromString(Tokenizer st, Name origin) throws IOException { 62 | String addr = st.getString(); 63 | this.address = checkAndConvertAddress(addr); 64 | if (this.address == null) 65 | throw st.exception("invalid PSDN address " + addr); 66 | } 67 | 68 | /** 69 | * Returns the X.25 PSDN address. 70 | */ 71 | public String 72 | getAddress() { 73 | return byteArrayToString(address, false); 74 | } 75 | 76 | void 77 | rrToWire(DNSOutput out, Compression c, boolean canonical) { 78 | out.writeCountedString(address); 79 | } 80 | 81 | String 82 | rrToString() { 83 | return byteArrayToString(address, true); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /org/xbill/DNS/ZoneTransferException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS; 4 | 5 | /** 6 | * An exception thrown when a zone transfer fails. 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class ZoneTransferException extends Exception { 12 | 13 | public 14 | ZoneTransferException() { 15 | super(); 16 | } 17 | 18 | public 19 | ZoneTransferException(String s) { 20 | super(s); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /org/xbill/DNS/spi/DNSJavaNameServiceDescriptor.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2005 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS.spi; 4 | 5 | import java.lang.reflect.Proxy; 6 | 7 | import sun.net.spi.nameservice.*; 8 | 9 | /** 10 | * The descriptor class for the dnsjava name service provider. 11 | * 12 | * @author Brian Wellington 13 | * @author Paul Cowan (pwc21@yahoo.com) 14 | */ 15 | public class DNSJavaNameServiceDescriptor implements NameServiceDescriptor { 16 | 17 | private static NameService nameService; 18 | 19 | static { 20 | ClassLoader loader = NameService.class.getClassLoader(); 21 | if (loader == null) { 22 | loader = Thread.currentThread().getContextClassLoader(); 23 | } 24 | nameService = (NameService) Proxy.newProxyInstance(loader, 25 | new Class[] { NameService.class }, 26 | new DNSJavaNameService()); 27 | } 28 | 29 | /** 30 | * Returns a reference to a dnsjava name server provider. 31 | */ 32 | public NameService 33 | createNameService() { 34 | return nameService; 35 | } 36 | 37 | public String 38 | getType() { 39 | return "dns"; 40 | } 41 | 42 | public String 43 | getProviderName() { 44 | return "dnsjava"; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /org/xbill/DNS/spi/services/sun.net.spi.nameservice.NameServiceDescriptor: -------------------------------------------------------------------------------- 1 | org.xbill.DNS.spi.DNSJavaNameServiceDescriptor 2 | -------------------------------------------------------------------------------- /org/xbill/DNS/tests/primary.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS.tests; 4 | 5 | import java.util.*; 6 | import org.xbill.DNS.*; 7 | 8 | public class primary { 9 | 10 | private static void 11 | usage() { 12 | System.out.println("usage: primary [-t] [-a | -i] origin file"); 13 | System.exit(1); 14 | } 15 | 16 | public static void 17 | main(String [] args) throws Exception { 18 | boolean time = false; 19 | boolean axfr = false; 20 | boolean iterator = false; 21 | int arg = 0; 22 | 23 | if (args.length < 2) 24 | usage(); 25 | 26 | while (args.length - arg > 2) { 27 | if (args[0].equals("-t")) 28 | time = true; 29 | else if (args[0].equals("-a")) 30 | axfr = true; 31 | else if (args[0].equals("-i")) 32 | iterator = true; 33 | arg++; 34 | } 35 | 36 | Name origin = Name.fromString(args[arg++], Name.root); 37 | String file = args[arg++]; 38 | 39 | long start = System.currentTimeMillis(); 40 | Zone zone = new Zone(origin, file); 41 | long end = System.currentTimeMillis(); 42 | if (axfr) { 43 | Iterator it = zone.AXFR(); 44 | while (it.hasNext()) { 45 | System.out.println(it.next()); 46 | } 47 | } else if (iterator) { 48 | Iterator it = zone.iterator(); 49 | while (it.hasNext()) { 50 | System.out.println(it.next()); 51 | } 52 | } else { 53 | System.out.println(zone); 54 | } 55 | if (time) 56 | System.out.println("; Load time: " + (end - start) + " ms"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /org/xbill/DNS/tests/xfrin.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS.tests; 4 | 5 | import java.util.*; 6 | import org.xbill.DNS.*; 7 | 8 | public class xfrin { 9 | 10 | private static void 11 | usage(String s) { 12 | System.out.println("Error: " + s); 13 | System.out.println("usage: xfrin [-i serial] [-k keyname/secret] " + 14 | "[-s server] [-p port] [-f] zone"); 15 | System.exit(1); 16 | } 17 | 18 | public static void 19 | main(String [] args) throws Exception { 20 | ZoneTransferIn xfrin; 21 | TSIG key = null; 22 | int ixfr_serial = -1; 23 | String server = null; 24 | int port = SimpleResolver.DEFAULT_PORT; 25 | boolean fallback = false; 26 | Name zname; 27 | 28 | int arg = 0; 29 | while (arg < args.length) { 30 | if (args[arg].equals("-i")) { 31 | ixfr_serial = Integer.parseInt(args[++arg]); 32 | if (ixfr_serial < 0) 33 | usage("invalid serial number"); 34 | } else if (args[arg].equals("-k")) { 35 | String s = args[++arg]; 36 | int index = s.indexOf('/'); 37 | if (index < 0) 38 | usage("invalid key"); 39 | key = new TSIG(s.substring(0, index), 40 | s.substring(index+1)); 41 | } else if (args[arg].equals("-s")) { 42 | server = args[++arg]; 43 | } else if (args[arg].equals("-p")) { 44 | port = Integer.parseInt(args[++arg]); 45 | if (port < 0 || port > 0xFFFF) 46 | usage("invalid port"); 47 | } else if (args[arg].equals("-f")) { 48 | fallback = true; 49 | } else if (args[arg].startsWith("-")) { 50 | usage("invalid option"); 51 | } else { 52 | break; 53 | } 54 | arg++; 55 | } 56 | if (arg >= args.length) 57 | usage("no zone name specified"); 58 | zname = Name.fromString(args[arg]); 59 | 60 | if (server == null) { 61 | Lookup l = new Lookup(zname, Type.NS); 62 | Record [] ns = l.run(); 63 | if (ns == null) { 64 | System.out.println("failed to look up NS record: " + 65 | l.getErrorString()); 66 | System.exit(1); 67 | } 68 | server = ns[0].rdataToString(); 69 | System.out.println("sending to server '" + server + "'"); 70 | } 71 | 72 | if (ixfr_serial >= 0) 73 | xfrin = ZoneTransferIn.newIXFR(zname, ixfr_serial, fallback, 74 | server, port, key); 75 | else 76 | xfrin = ZoneTransferIn.newAXFR(zname, server, port, key); 77 | 78 | List response = xfrin.run(); 79 | if (xfrin.isAXFR()) { 80 | if (ixfr_serial >= 0) 81 | System.out.println("AXFR-like IXFR response"); 82 | else 83 | System.out.println("AXFR response"); 84 | Iterator it = response.iterator(); 85 | while (it.hasNext()) 86 | System.out.println(it.next()); 87 | } else if (xfrin.isIXFR()) { 88 | System.out.println("IXFR response"); 89 | Iterator it = response.iterator(); 90 | while (it.hasNext()) { 91 | ZoneTransferIn.Delta delta; 92 | delta = (ZoneTransferIn.Delta) it.next(); 93 | System.out.println("delta from " + delta.start + 94 | " to " + delta.end); 95 | System.out.println("deletes"); 96 | Iterator it2 = delta.deletes.iterator(); 97 | while (it2.hasNext()) 98 | System.out.println(it2.next()); 99 | System.out.println("adds"); 100 | it2 = delta.adds.iterator(); 101 | while (it2.hasNext()) 102 | System.out.println(it2.next()); 103 | } 104 | } else if (xfrin.isCurrent()) { 105 | System.out.println("up to date"); 106 | } 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /org/xbill/DNS/utils/base16.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS.utils; 4 | 5 | import java.io.*; 6 | 7 | /** 8 | * Routines for converting between Strings of hex-encoded data and arrays of 9 | * binary data. This is not actually used by DNS. 10 | * 11 | * @author Brian Wellington 12 | */ 13 | 14 | public class base16 { 15 | 16 | private static final String Base16 = "0123456789ABCDEF"; 17 | 18 | private 19 | base16() {} 20 | 21 | /** 22 | * Convert binary data to a hex-encoded String 23 | * @param b An array containing binary data 24 | * @return A String containing the encoded data 25 | */ 26 | public static String 27 | toString(byte [] b) { 28 | ByteArrayOutputStream os = new ByteArrayOutputStream(); 29 | 30 | for (int i = 0; i < b.length; i++) { 31 | short value = (short) (b[i] & 0xFF); 32 | byte high = (byte) (value >> 4); 33 | byte low = (byte) (value & 0xF); 34 | os.write(Base16.charAt(high)); 35 | os.write(Base16.charAt(low)); 36 | } 37 | return new String(os.toByteArray()); 38 | } 39 | 40 | /** 41 | * Convert a hex-encoded String to binary data 42 | * @param str A String containing the encoded data 43 | * @return An array containing the binary data, or null if the string is invalid 44 | */ 45 | public static byte [] 46 | fromString(String str) { 47 | ByteArrayOutputStream bs = new ByteArrayOutputStream(); 48 | byte [] raw = str.getBytes(); 49 | for (int i = 0; i < raw.length; i++) { 50 | if (!Character.isWhitespace((char)raw[i])) 51 | bs.write(raw[i]); 52 | } 53 | byte [] in = bs.toByteArray(); 54 | if (in.length % 2 != 0) { 55 | return null; 56 | } 57 | 58 | bs.reset(); 59 | DataOutputStream ds = new DataOutputStream(bs); 60 | 61 | for (int i = 0; i < in.length; i += 2) { 62 | byte high = (byte) Base16.indexOf(Character.toUpperCase((char)in[i])); 63 | byte low = (byte) Base16.indexOf(Character.toUpperCase((char)in[i+1])); 64 | try { 65 | ds.writeByte((high << 4) + low); 66 | } 67 | catch (IOException e) { 68 | } 69 | } 70 | return bs.toByteArray(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /org/xbill/DNS/utils/hexdump.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 | 3 | package org.xbill.DNS.utils; 4 | 5 | /** 6 | * A routine to produce a nice looking hex dump 7 | * 8 | * @author Brian Wellington 9 | */ 10 | 11 | public class hexdump { 12 | 13 | private static final char [] hex = "0123456789ABCDEF".toCharArray(); 14 | 15 | /** 16 | * Dumps a byte array into hex format. 17 | * @param description If not null, a description of the data. 18 | * @param b The data to be printed. 19 | * @param offset The start of the data in the array. 20 | * @param length The length of the data in the array. 21 | */ 22 | public static String 23 | dump(String description, byte [] b, int offset, int length) { 24 | StringBuffer sb = new StringBuffer(); 25 | 26 | sb.append(length + "b"); 27 | if (description != null) 28 | sb.append(" (" + description + ")"); 29 | sb.append(':'); 30 | 31 | int prefixlen = sb.toString().length(); 32 | prefixlen = (prefixlen + 8) & ~ 7; 33 | sb.append('\t'); 34 | 35 | int perline = (80 - prefixlen) / 3; 36 | for (int i = 0; i < length; i++) { 37 | if (i != 0 && i % perline == 0) { 38 | sb.append('\n'); 39 | for (int j = 0; j < prefixlen / 8 ; j++) 40 | sb.append('\t'); 41 | } 42 | int value = (int)(b[i + offset]) & 0xFF; 43 | sb.append(hex[(value >> 4)]); 44 | sb.append(hex[(value & 0xF)]); 45 | sb.append(' '); 46 | } 47 | sb.append('\n'); 48 | return sb.toString(); 49 | } 50 | 51 | public static String 52 | dump(String s, byte [] b) { 53 | return dump(s, b, 0, b.length); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /org/xbill/DNS/windows/DNSServer.properties: -------------------------------------------------------------------------------- 1 | host_name=Host Name 2 | primary_dns_suffix=Primary Dns Suffix 3 | dns_suffix=DNS Suffix 4 | dns_servers=DNS Servers 5 | -------------------------------------------------------------------------------- /org/xbill/DNS/windows/DNSServer_de.properties: -------------------------------------------------------------------------------- 1 | host_name=Hostname 2 | primary_dns_suffix=Prim\u00E4res DNS-Suffix 3 | dns_suffix=DNS-Suffixsuchliste 4 | dns_servers=DNS-Server 5 | -------------------------------------------------------------------------------- /org/xbill/DNS/windows/DNSServer_fr.properties: -------------------------------------------------------------------------------- 1 | host_name=Nom de l'h\u00F4te 2 | primary_dns_suffix=Suffixe DNS principal 3 | dns_suffix=Suffixe DNS propre \u00E0 la connexion 4 | dns_servers=Serveurs DNS 5 | -------------------------------------------------------------------------------- /org/xbill/DNS/windows/DNSServer_ja.properties: -------------------------------------------------------------------------------- 1 | host_name=\u30db\u30b9\u30c8\u540d 2 | primary_dns_suffix=\u30d7\u30e9\u30a4\u30de\u30ea DNS \u30b5\u30d5\u30a3\u30c3\u30af\u30b9 3 | dns_suffix=DNS \u30b5\u30d5\u30a3\u30c3\u30af\u30b9 4 | dns_servers=DNS \u30b5\u30fc\u30d0\u30fc 5 | -------------------------------------------------------------------------------- /org/xbill/DNS/windows/DNSServer_pl.properties: -------------------------------------------------------------------------------- 1 | host_name=Nazwa hosta 2 | primary_dns_suffix=Sufiks podstawowej domeny DNS 3 | dns_suffix=Sufiks DNS konkretnego po\u0142\u0105czenia 4 | dns_servers=Serwery DNS 5 | -------------------------------------------------------------------------------- /tests/junit-3.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dblacka/jdnssec-dnsjava/c8b55cd406721e04f1ec8a349f00712fcce1df9b/tests/junit-3.8.1.jar -------------------------------------------------------------------------------- /tests/org/xbill/DNS/AFSDBRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import java.util.Arrays; 38 | import junit.framework.TestCase; 39 | 40 | public class AFSDBRecordTest extends TestCase 41 | { 42 | public void test_getObject() 43 | { 44 | AFSDBRecord d = new AFSDBRecord(); 45 | Record r = d.getObject(); 46 | assertTrue(r instanceof AFSDBRecord); 47 | } 48 | 49 | public void test_ctor_5arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("My.Name."); 52 | Name m = Name.fromString("My.OtherName."); 53 | 54 | AFSDBRecord d = new AFSDBRecord(n, DClass.IN, 0xABCDEL, 0xF1, m); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.AFSDB, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(0xF1, d.getSubtype()); 60 | assertEquals(m, d.getHost()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/CNAMERecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class CNAMERecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | CNAMERecord d = new CNAMERecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getTarget()); 46 | assertNull(d.getAlias()); 47 | } 48 | 49 | public void test_ctor_4arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("my.name."); 52 | Name a = Name.fromString("my.alias."); 53 | 54 | CNAMERecord d = new CNAMERecord(n, DClass.IN, 0xABCDEL, a); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.CNAME, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(a, d.getTarget()); 60 | assertEquals(a, d.getAlias()); 61 | } 62 | 63 | public void test_getObject() 64 | { 65 | CNAMERecord d = new CNAMERecord(); 66 | Record r = d.getObject(); 67 | assertTrue(r instanceof CNAMERecord); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/CompressionTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | import org.xbill.DNS.Compression; 39 | import org.xbill.DNS.Name; 40 | 41 | public class CompressionTest extends TestCase 42 | { 43 | public void setUp() 44 | { 45 | Options.set("verbosecompression"); 46 | } 47 | 48 | public void test() throws TextParseException 49 | { 50 | Compression c = new Compression(); 51 | Name n = Name.fromString("www.amazon.com."); 52 | 53 | c.add(10, n); 54 | assertEquals(10, c.get(n)); 55 | 56 | Name n2 = Name.fromString("www.cnn.com."); 57 | 58 | c.add(10, n2); 59 | assertEquals(10, c.get(n2)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/DClassTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class DClassTest extends TestCase 40 | { 41 | public void test_string() 42 | { 43 | // a regular one 44 | assertEquals("IN", DClass.string(DClass.IN)); 45 | 46 | // one with an alias 47 | assertEquals("CH", DClass.string(DClass.CH)); 48 | 49 | // one that doesn't exist 50 | assertTrue(DClass.string(20).startsWith("CLASS")); 51 | 52 | try { 53 | DClass.string(-1); 54 | fail("IllegalArgumentException not thrown"); 55 | } 56 | catch( IllegalArgumentException e ){ 57 | } 58 | 59 | // (max is 0xFFFF) 60 | try { 61 | DClass.string(0x10000); 62 | fail("IllegalArgumentException not thrown"); 63 | } 64 | catch( IllegalArgumentException e ){ 65 | } 66 | } 67 | 68 | public void test_value() 69 | { 70 | // regular one 71 | assertEquals(DClass.NONE, DClass.value("NONE")); 72 | 73 | // one with alias 74 | assertEquals(DClass.HS, DClass.value("HS")); 75 | assertEquals(DClass.HS, DClass.value("HESIOD")); 76 | 77 | // one thats undefined but within range 78 | assertEquals(21, DClass.value("CLASS21")); 79 | 80 | // something that unknown 81 | assertEquals(-1, DClass.value("THIS IS DEFINITELY UNKNOWN")); 82 | 83 | // empty string 84 | assertEquals(-1, DClass.value("")); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/DNAMERecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class DNAMERecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | DNAMERecord d = new DNAMERecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getTarget()); 46 | assertNull(d.getAlias()); 47 | } 48 | 49 | public void test_ctor_4arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("my.name."); 52 | Name a = Name.fromString("my.alias."); 53 | 54 | DNAMERecord d = new DNAMERecord(n, DClass.IN, 0xABCDEL, a); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.DNAME, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(a, d.getTarget()); 60 | assertEquals(a, d.getAlias()); 61 | } 62 | 63 | public void test_getObject() 64 | { 65 | DNAMERecord d = new DNAMERecord(); 66 | Record r = d.getObject(); 67 | assertTrue(r instanceof DNAMERecord); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/DNSSECSIG0Test.java: -------------------------------------------------------------------------------- 1 | package org.xbill.DNS; 2 | 3 | import java.security.KeyPair; 4 | import java.security.KeyPairGenerator; 5 | import java.security.PrivateKey; 6 | import java.security.PublicKey; 7 | import java.security.Security; 8 | import java.security.Signature; 9 | 10 | import junit.framework.TestCase; 11 | 12 | import org.xbill.DNS.DNSSEC.Algorithm; 13 | 14 | public class DNSSECSIG0Test extends TestCase { 15 | 16 | private static final String SIGNATURE_ALGORITHM = "SHA1withRSA"; 17 | private static final String KEY_ALGORITHM = "RSA"; 18 | int algorithm = Algorithm.RSASHA1; 19 | byte[] toSign = "The quick brown fox jumped over the lazy dog.".getBytes(); 20 | 21 | public void setUp() { 22 | } 23 | 24 | public void tearDown() { 25 | } 26 | 27 | public void testSIG0() throws Exception { 28 | Name sig0zoneName = new Name("sig0.invalid."); 29 | Name sig0hostName = new Name("sometext.sig0.invalid."); 30 | 31 | KeyPairGenerator rsagen = KeyPairGenerator.getInstance("RSA"); 32 | KeyPair rsapair = rsagen.generateKeyPair(); 33 | PrivateKey privKey = rsapair.getPrivate(); 34 | PublicKey pubKey = rsapair.getPublic(); 35 | 36 | KEYRecord keyRecord = new KEYRecord(sig0zoneName, DClass.IN, 37 | 0, KEYRecord.Flags.HOST, 38 | KEYRecord.Protocol.DNSSEC, 39 | DNSSEC.Algorithm.RSASHA1, 40 | pubKey); 41 | TXTRecord txtRecord = new TXTRecord(sig0hostName, DClass.IN, 0, "Hello World!"); 42 | Update updateMessage = new Update(sig0zoneName); 43 | updateMessage.add(txtRecord); 44 | 45 | SIG0.signMessage(updateMessage, keyRecord, privKey, null); 46 | Message message = new Message(updateMessage.toWire()); 47 | SIG0.verifyMessage(message, message.toWire(), keyRecord, null); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/DNSSECWithLunaProviderTest.java.disabled: -------------------------------------------------------------------------------- 1 | package org.xbill.DNS; 2 | 3 | import java.security.KeyPair; 4 | import java.security.KeyPairGenerator; 5 | import java.security.Security; 6 | import java.security.Signature; 7 | 8 | import junit.framework.TestCase; 9 | 10 | import org.xbill.DNS.DNSSEC.Algorithm; 11 | 12 | import com.chrysalisits.crypto.LunaJCAProvider; 13 | import com.chrysalisits.crypto.LunaTokenManager; 14 | import com.chrysalisits.cryptox.LunaJCEProvider; 15 | 16 | public class DNSSECWithLunaProviderTest extends TestCase { 17 | 18 | private static final String SIGNATURE_ALGORITHM = "SHA1withRSA"; 19 | private static final String KEY_ALGORITHM = "RSA"; 20 | int algorithm = Algorithm.RSASHA1; 21 | String partitionName = "dns"; 22 | String partitionPassword = "xX0x-XXXX-XxXx-xXxX"; 23 | LunaTokenManager tokenManager = LunaTokenManager.getInstance(); 24 | String lunaJCEProvider = "LunaJCEProvider"; 25 | String lunaJCAProvider = "LunaJCAProvider"; 26 | byte[] toSign = "The quick brown fox jumped over the lazy dog.".getBytes(); 27 | 28 | public void setUp() { 29 | Security.addProvider(new LunaJCEProvider()); 30 | Security.addProvider(new LunaJCAProvider()); 31 | tokenManager.Login(partitionName, partitionPassword); 32 | } 33 | 34 | public void tearDown() { 35 | tokenManager.Logout(); 36 | } 37 | 38 | public void testSignHSM() throws Exception { 39 | 40 | KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM, lunaJCAProvider); 41 | keyPairGenerator.initialize(512); 42 | KeyPair keyPair = keyPairGenerator.generateKeyPair(); 43 | 44 | Signature signer = Signature.getInstance(SIGNATURE_ALGORITHM, lunaJCAProvider); 45 | signer.initSign(keyPair.getPrivate()); 46 | signer.update(toSign); 47 | byte[] signature = signer.sign(); 48 | assertNotNull(signature); 49 | 50 | // verify the signature 51 | Signature verifier = Signature.getInstance(SIGNATURE_ALGORITHM, lunaJCAProvider); 52 | verifier.initVerify(keyPair.getPublic()); 53 | verifier.update(toSign); 54 | boolean verify = verifier.verify(signature); 55 | assertTrue(verify); 56 | 57 | } 58 | 59 | public void testSignWithDNSSECAndHSM() throws Exception { 60 | 61 | // generate a signature 62 | KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM, lunaJCAProvider); 63 | keyPairGenerator.initialize(512); 64 | KeyPair keyPair = keyPairGenerator.generateKeyPair(); 65 | byte[] signature = DNSSEC.sign(keyPair.getPrivate(), keyPair.getPublic(), algorithm, toSign, lunaJCAProvider); 66 | assertNotNull(signature); 67 | 68 | // verify the signature 69 | Signature verifier = Signature.getInstance(DNSSEC.algString(algorithm), lunaJCAProvider); 70 | verifier.initVerify(keyPair.getPublic()); 71 | verifier.update(toSign); 72 | boolean verify = verifier.verify(signature); 73 | assertTrue(verify); 74 | } 75 | 76 | public void testSignWithDNSSECAndSoftware() throws Exception { 77 | 78 | // generate a signature 79 | KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM); 80 | keyPairGenerator.initialize(512); 81 | KeyPair keyPair = keyPairGenerator.generateKeyPair(); 82 | byte[] signature = DNSSEC.sign(keyPair.getPrivate(), keyPair.getPublic(), algorithm, toSign); 83 | assertNotNull(signature); 84 | 85 | // verify the signature 86 | Signature verifier = Signature.getInstance(DNSSEC.algString(algorithm)); 87 | verifier.initVerify(keyPair.getPublic()); 88 | verifier.update(toSign); 89 | boolean verify = verifier.verify(signature); 90 | assertTrue(verify); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/DNSSECWithProviderTest.java: -------------------------------------------------------------------------------- 1 | package org.xbill.DNS; 2 | 3 | import java.security.KeyPair; 4 | import java.security.KeyPairGenerator; 5 | import java.security.Security; 6 | import java.security.Signature; 7 | 8 | import junit.framework.TestCase; 9 | 10 | import org.xbill.DNS.DNSSEC.Algorithm; 11 | 12 | 13 | public class DNSSECWithProviderTest extends TestCase { 14 | 15 | private static final String SIGNATURE_ALGORITHM = "SHA1withRSA"; 16 | private static final String KEY_ALGORITHM = "RSA"; 17 | int algorithm = Algorithm.RSASHA1; 18 | byte[] toSign = "The quick brown fox jumped over the lazy dog.".getBytes(); 19 | 20 | public void setUp() { 21 | } 22 | 23 | public void tearDown() { 24 | } 25 | 26 | public void testSignSoftware() throws Exception { 27 | 28 | KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM); 29 | keyPairGenerator.initialize(512); 30 | KeyPair keyPair = keyPairGenerator.generateKeyPair(); 31 | 32 | Signature signer = Signature.getInstance(SIGNATURE_ALGORITHM); 33 | signer.initSign(keyPair.getPrivate()); 34 | signer.update(toSign); 35 | byte[] signature = signer.sign(); 36 | assertNotNull(signature); 37 | 38 | // verify the signature 39 | Signature verifier = Signature.getInstance(SIGNATURE_ALGORITHM); 40 | verifier.initVerify(keyPair.getPublic()); 41 | verifier.update(toSign); 42 | boolean verify = verifier.verify(signature); 43 | assertTrue(verify); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/ExtendedFlagsTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class ExtendedFlagsTest extends TestCase 40 | { 41 | public void test_string() 42 | { 43 | // a regular one 44 | assertEquals("do", ExtendedFlags.string(ExtendedFlags.DO)); 45 | 46 | // one that doesn't exist 47 | assertTrue(ExtendedFlags.string(1).startsWith("flag")); 48 | 49 | try { 50 | ExtendedFlags.string(-1); 51 | fail("IllegalArgumentException not thrown"); 52 | } 53 | catch( IllegalArgumentException e ){ 54 | } 55 | 56 | // (max is 0xFFFF) 57 | try { 58 | ExtendedFlags.string(0x10000); 59 | fail("IllegalArgumentException not thrown"); 60 | } 61 | catch( IllegalArgumentException e ){ 62 | } 63 | } 64 | 65 | public void test_value() 66 | { 67 | // regular one 68 | assertEquals(ExtendedFlags.DO, ExtendedFlags.value("do")); 69 | 70 | // one thats undefined but within range 71 | assertEquals(16, ExtendedFlags.value("FLAG16")); 72 | 73 | // one thats undefined but out of range 74 | assertEquals(-1, ExtendedFlags.value("FLAG" + 0x10000)); 75 | 76 | // something that unknown 77 | assertEquals(-1, ExtendedFlags.value("THIS IS DEFINITELY UNKNOWN")); 78 | 79 | // empty string 80 | assertEquals(-1, ExtendedFlags.value("")); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/FormattedTimeTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import java.util.Date; 38 | import java.util.Calendar; 39 | import java.util.GregorianCalendar; 40 | import java.util.TimeZone; 41 | import junit.framework.TestCase; 42 | import org.xbill.DNS.FormattedTime; 43 | 44 | public class FormattedTimeTest extends TestCase 45 | { 46 | public void test_format() 47 | { 48 | GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); 49 | cal.set(2005, 2, 19, 4, 4, 5); 50 | String out = FormattedTime.format(cal.getTime()); 51 | assertEquals("20050319040405", out); 52 | } 53 | 54 | public void test_parse() throws TextParseException 55 | { 56 | // have to make sure to clear out the milliseconds since there 57 | // is occasionally a difference between when cal and cal2 are 58 | // instantiated. 59 | GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); 60 | cal.set(2005, 2, 19, 4, 4, 5); 61 | cal.set(Calendar.MILLISECOND, 0); 62 | 63 | Date out = FormattedTime.parse("20050319040405"); 64 | GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("UTC")); 65 | cal2.setTimeInMillis(out.getTime()); 66 | cal2.set(Calendar.MILLISECOND, 0); 67 | assertEquals(cal, cal2); 68 | } 69 | 70 | public void test_parse_invalid() 71 | { 72 | try { 73 | FormattedTime.parse("2004010101010"); 74 | fail("TextParseException not thrown"); 75 | } 76 | catch( TextParseException e ){ 77 | } 78 | try { 79 | FormattedTime.parse("200401010101010"); 80 | fail("TextParseException not thrown"); 81 | } 82 | catch( TextParseException e ){ 83 | } 84 | try { 85 | FormattedTime.parse("2004010101010A"); 86 | fail("TextParseException not thrown"); 87 | } 88 | catch( TextParseException e ){ 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/KXRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import java.util.Arrays; 38 | import junit.framework.TestCase; 39 | 40 | public class KXRecordTest extends TestCase 41 | { 42 | public void test_getObject() 43 | { 44 | KXRecord d = new KXRecord(); 45 | Record r = d.getObject(); 46 | assertTrue(r instanceof KXRecord); 47 | } 48 | 49 | public void test_ctor_5arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("My.Name."); 52 | Name m = Name.fromString("My.OtherName."); 53 | 54 | KXRecord d = new KXRecord(n, DClass.IN, 0xABCDEL, 0xF1, m); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.KX, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(0xF1, d.getPreference()); 60 | assertEquals(m, d.getTarget()); 61 | assertEquals(m, d.getAdditionalName()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/MBRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class MBRecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | MBRecord d = new MBRecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getAdditionalName()); 46 | assertNull(d.getMailbox()); 47 | } 48 | 49 | public void test_ctor_4arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("my.name."); 52 | Name a = Name.fromString("my.alias."); 53 | 54 | MBRecord d = new MBRecord(n, DClass.IN, 0xABCDEL, a); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.MB, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(a, d.getAdditionalName()); 60 | assertEquals(a, d.getMailbox()); 61 | } 62 | 63 | public void test_getObject() 64 | { 65 | MBRecord d = new MBRecord(); 66 | Record r = d.getObject(); 67 | assertTrue(r instanceof MBRecord); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/MDRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class MDRecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | MDRecord d = new MDRecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getAdditionalName()); 46 | assertNull(d.getMailAgent()); 47 | } 48 | 49 | public void test_ctor_4arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("my.name."); 52 | Name a = Name.fromString("my.alias."); 53 | 54 | MDRecord d = new MDRecord(n, DClass.IN, 0xABCDEL, a); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.MD, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(a, d.getAdditionalName()); 60 | assertEquals(a, d.getMailAgent()); 61 | } 62 | 63 | public void test_getObject() 64 | { 65 | MDRecord d = new MDRecord(); 66 | Record r = d.getObject(); 67 | assertTrue(r instanceof MDRecord); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/MFRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class MFRecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | MFRecord d = new MFRecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getAdditionalName()); 46 | assertNull(d.getMailAgent()); 47 | } 48 | 49 | public void test_ctor_4arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("my.name."); 52 | Name a = Name.fromString("my.alias."); 53 | 54 | MFRecord d = new MFRecord(n, DClass.IN, 0xABCDEL, a); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.MF, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(a, d.getAdditionalName()); 60 | assertEquals(a, d.getMailAgent()); 61 | } 62 | 63 | public void test_getObject() 64 | { 65 | MFRecord d = new MFRecord(); 66 | Record r = d.getObject(); 67 | assertTrue(r instanceof MFRecord); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/MGRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class MGRecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | MGRecord d = new MGRecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getMailbox()); 46 | } 47 | 48 | public void test_ctor_4arg() throws TextParseException 49 | { 50 | Name n = Name.fromString("my.name."); 51 | Name a = Name.fromString("my.alias."); 52 | 53 | MGRecord d = new MGRecord(n, DClass.IN, 0xABCDEL, a); 54 | assertEquals(n, d.getName()); 55 | assertEquals(Type.MG, d.getType()); 56 | assertEquals(DClass.IN, d.getDClass()); 57 | assertEquals(0xABCDEL, d.getTTL()); 58 | assertEquals(a, d.getMailbox()); 59 | } 60 | 61 | public void test_getObject() 62 | { 63 | MGRecord d = new MGRecord(); 64 | Record r = d.getObject(); 65 | assertTrue(r instanceof MGRecord); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/MRRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class MRRecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | MRRecord d = new MRRecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getNewName()); 46 | } 47 | 48 | public void test_ctor_4arg() throws TextParseException 49 | { 50 | Name n = Name.fromString("my.name."); 51 | Name a = Name.fromString("my.alias."); 52 | 53 | MRRecord d = new MRRecord(n, DClass.IN, 0xABCDEL, a); 54 | assertEquals(n, d.getName()); 55 | assertEquals(Type.MR, d.getType()); 56 | assertEquals(DClass.IN, d.getDClass()); 57 | assertEquals(0xABCDEL, d.getTTL()); 58 | assertEquals(a, d.getNewName()); 59 | } 60 | 61 | public void test_getObject() 62 | { 63 | MRRecord d = new MRRecord(); 64 | Record r = d.getObject(); 65 | assertTrue(r instanceof MRRecord); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/MXRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import java.util.Arrays; 38 | import junit.framework.TestCase; 39 | 40 | public class MXRecordTest extends TestCase 41 | { 42 | public void test_getObject() 43 | { 44 | MXRecord d = new MXRecord(); 45 | Record r = d.getObject(); 46 | assertTrue(r instanceof MXRecord); 47 | } 48 | 49 | public void test_ctor_5arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("My.Name."); 52 | Name m = Name.fromString("My.OtherName."); 53 | 54 | MXRecord d = new MXRecord(n, DClass.IN, 0xABCDEL, 0xF1, m); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.MX, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(0xF1, d.getPriority()); 60 | assertEquals(m, d.getTarget()); 61 | assertEquals(m, d.getAdditionalName()); 62 | } 63 | 64 | public void test_rrToWire() throws TextParseException 65 | { 66 | Name n = Name.fromString("My.Name."); 67 | Name m = Name.fromString("M.O.n."); 68 | 69 | MXRecord mr = new MXRecord(n, DClass.IN, 0xB12FL, 0x1F2B, m ); 70 | 71 | // canonical 72 | DNSOutput dout = new DNSOutput(); 73 | mr.rrToWire(dout, null, true); 74 | byte[] out = dout.toByteArray(); 75 | byte[] exp = new byte[] { 0x1F, 0x2B, 1, 'm', 1, 'o', 1, 'n', 0 }; 76 | assertTrue(Arrays.equals(exp, out)); 77 | 78 | // case sensitive 79 | dout = new DNSOutput(); 80 | mr.rrToWire(dout, null, false); 81 | out = dout.toByteArray(); 82 | exp = new byte[] { 0x1F, 0x2B, 1, 'M', 1, 'O', 1, 'n', 0 }; 83 | assertTrue(Arrays.equals(exp, out)); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/NSAP_PTRRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class NSAP_PTRRecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | NSAP_PTRRecord d = new NSAP_PTRRecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getTarget()); 46 | } 47 | 48 | public void test_ctor_4arg() throws TextParseException 49 | { 50 | Name n = Name.fromString("my.name."); 51 | Name a = Name.fromString("my.alias."); 52 | 53 | NSAP_PTRRecord d = new NSAP_PTRRecord(n, DClass.IN, 0xABCDEL, a); 54 | assertEquals(n, d.getName()); 55 | assertEquals(Type.NSAP_PTR, d.getType()); 56 | assertEquals(DClass.IN, d.getDClass()); 57 | assertEquals(0xABCDEL, d.getTTL()); 58 | assertEquals(a, d.getTarget()); 59 | } 60 | 61 | public void test_getObject() 62 | { 63 | NSAP_PTRRecord d = new NSAP_PTRRecord(); 64 | Record r = d.getObject(); 65 | assertTrue(r instanceof NSAP_PTRRecord); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/NSRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class NSRecordTest extends TestCase 40 | { 41 | public void test_ctor_0arg() 42 | { 43 | NSRecord d = new NSRecord(); 44 | assertNull(d.getName()); 45 | assertNull(d.getTarget()); 46 | assertNull(d.getAdditionalName()); 47 | } 48 | 49 | public void test_ctor_4arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("my.name."); 52 | Name a = Name.fromString("my.alias."); 53 | 54 | NSRecord d = new NSRecord(n, DClass.IN, 0xABCDEL, a); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.NS, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(a, d.getTarget()); 60 | assertEquals(a, d.getAdditionalName()); 61 | } 62 | 63 | public void test_getObject() 64 | { 65 | NSRecord d = new NSRecord(); 66 | Record r = d.getObject(); 67 | assertTrue(r instanceof NSRecord); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/OPTRecordTest.java: -------------------------------------------------------------------------------- 1 | package org.xbill.DNS; 2 | 3 | import junit.framework.TestCase; 4 | 5 | public class OPTRecordTest extends TestCase { 6 | 7 | private static final int DEFAULT_EDNS_RCODE = 0; 8 | private static final int DEFAULT_EDNS_VERSION = 0; 9 | private static final int DEFAULT_PAYLOAD_SIZE = 1024; 10 | 11 | public void testForNoEqualityWithDifferentEDNS_Versions() { 12 | final OPTRecord optRecordOne = new OPTRecord(DEFAULT_PAYLOAD_SIZE, DEFAULT_EDNS_RCODE, 0); 13 | final OPTRecord optRecordTwo = new OPTRecord(DEFAULT_PAYLOAD_SIZE, DEFAULT_EDNS_RCODE, 1); 14 | assertNotEqual(optRecordOne, optRecordTwo); 15 | } 16 | 17 | public void testForNoEqualityWithDifferentEDNS_RCodes() { 18 | final OPTRecord optRecordOne = new OPTRecord(DEFAULT_PAYLOAD_SIZE, 0, DEFAULT_EDNS_VERSION); 19 | final OPTRecord optRecordTwo = new OPTRecord(DEFAULT_PAYLOAD_SIZE, 1, DEFAULT_EDNS_VERSION); 20 | assertNotEqual(optRecordOne, optRecordTwo); 21 | } 22 | 23 | public void testForEquality() { 24 | final OPTRecord optRecordOne = new OPTRecord(DEFAULT_PAYLOAD_SIZE, DEFAULT_EDNS_RCODE, DEFAULT_EDNS_VERSION); 25 | final OPTRecord optRecordTwo = new OPTRecord(DEFAULT_PAYLOAD_SIZE, DEFAULT_EDNS_RCODE, DEFAULT_EDNS_VERSION); 26 | assertEquals(optRecordOne, optRecordTwo); 27 | assertEquals(optRecordTwo, optRecordOne); 28 | } 29 | 30 | private void assertNotEqual(final OPTRecord optRecordOne, final OPTRecord optRecordTwo) { 31 | assertTrue("Expecting no equality of " + optRecordOne + " compared to " + optRecordTwo, 32 | !optRecordOne.equals(optRecordTwo)); 33 | assertTrue("Expecting no equality of " + optRecordTwo + " compared to " + optRecordOne, 34 | !optRecordTwo.equals(optRecordOne)); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/OpcodeTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class OpcodeTest extends TestCase 40 | { 41 | public void test_string() 42 | { 43 | // a regular one 44 | assertEquals("IQUERY", Opcode.string(Opcode.IQUERY)); 45 | 46 | // one that doesn't exist 47 | assertTrue(Opcode.string(6).startsWith("RESERVED")); 48 | 49 | try { 50 | Opcode.string(-1); 51 | fail("IllegalArgumentException not thrown"); 52 | } 53 | catch( IllegalArgumentException e ){ 54 | } 55 | 56 | // (max is 0xF) 57 | try { 58 | Opcode.string(0x10); 59 | fail("IllegalArgumentException not thrown"); 60 | } 61 | catch( IllegalArgumentException e ){ 62 | } 63 | } 64 | 65 | public void test_value() 66 | { 67 | // regular one 68 | assertEquals(Opcode.STATUS, Opcode.value("STATUS")); 69 | 70 | // one thats undefined but within range 71 | assertEquals(6, Opcode.value("RESERVED6")); 72 | 73 | // one thats undefined but out of range 74 | assertEquals(-1, Opcode.value("RESERVED" + 0x10)); 75 | 76 | // something that unknown 77 | assertEquals(-1, Opcode.value("THIS IS DEFINITELY UNKNOWN")); 78 | 79 | // empty string 80 | assertEquals(-1, Opcode.value("")); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/RTRecordTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import java.util.Arrays; 38 | import junit.framework.TestCase; 39 | 40 | public class RTRecordTest extends TestCase 41 | { 42 | public void test_getObject() 43 | { 44 | RTRecord d = new RTRecord(); 45 | Record r = d.getObject(); 46 | assertTrue(r instanceof RTRecord); 47 | } 48 | 49 | public void test_ctor_5arg() throws TextParseException 50 | { 51 | Name n = Name.fromString("My.Name."); 52 | Name m = Name.fromString("My.OtherName."); 53 | 54 | RTRecord d = new RTRecord(n, DClass.IN, 0xABCDEL, 0xF1, m); 55 | assertEquals(n, d.getName()); 56 | assertEquals(Type.RT, d.getType()); 57 | assertEquals(DClass.IN, d.getDClass()); 58 | assertEquals(0xABCDEL, d.getTTL()); 59 | assertEquals(0xF1, d.getPreference()); 60 | assertEquals(m, d.getIntermediateHost()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/SectionTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class SectionTest extends TestCase 40 | { 41 | public void test_string() 42 | { 43 | // a regular one 44 | assertEquals("au", Section.string(Section.AUTHORITY)); 45 | 46 | try { 47 | Section.string(-1); 48 | fail("IllegalArgumentException not thrown"); 49 | } 50 | catch( IllegalArgumentException e ){ 51 | } 52 | 53 | // (max is 3) 54 | try { 55 | Section.string(4); 56 | fail("IllegalArgumentException not thrown"); 57 | } 58 | catch( IllegalArgumentException e ){ 59 | } 60 | } 61 | 62 | public void test_value() 63 | { 64 | // regular one 65 | assertEquals(Section.ADDITIONAL, Section.value("ad")); 66 | 67 | // something that unknown 68 | assertEquals(-1, Section.value("THIS IS DEFINITELY UNKNOWN")); 69 | 70 | // empty string 71 | assertEquals(-1, Section.value("")); 72 | } 73 | 74 | public void test_longString() 75 | { 76 | assertEquals("ADDITIONAL RECORDS", Section.longString(Section.ADDITIONAL)); 77 | 78 | try {Section.longString(-1);} catch( IllegalArgumentException e ){} 79 | try {Section.longString(4);} catch( IllegalArgumentException e ){} 80 | } 81 | 82 | public void test_updString() 83 | { 84 | assertEquals("ZONE", Section.updString(Section.ZONE)); 85 | 86 | try {Section.longString(-1);} catch( IllegalArgumentException e ){} 87 | try {Section.longString(4);} catch( IllegalArgumentException e ){} 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/TSIGTest.java: -------------------------------------------------------------------------------- 1 | package org.xbill.DNS; 2 | 3 | import java.io.IOException; 4 | import junit.framework.TestCase; 5 | 6 | public class TSIGTest extends TestCase 7 | { 8 | public void test_TSIG_query() throws TextParseException, IOException 9 | { 10 | TSIG key = new TSIG(TSIG.HMAC_SHA256, "example.", "12345678"); 11 | 12 | Name qname = Name.fromString("www.example."); 13 | Record rec = Record.newRecord(qname, Type.A, DClass.IN); 14 | Message msg = Message.newQuery(rec); 15 | msg.setTSIG(key, Rcode.NOERROR, null); 16 | byte [] bytes = msg.toWire(512); 17 | assertEquals(bytes[11], 1); 18 | 19 | Message parsed = new Message(bytes); 20 | int result = key.verify(parsed, bytes, null); 21 | assertEquals(result, Rcode.NOERROR); 22 | assertTrue(parsed.isSigned()); 23 | } 24 | 25 | public void test_TSIG_response() throws TextParseException, IOException 26 | { 27 | TSIG key = new TSIG(TSIG.HMAC_SHA256, "example.", "12345678"); 28 | 29 | Name qname = Name.fromString("www.example."); 30 | Record question = Record.newRecord(qname, Type.A, DClass.IN); 31 | Message query = Message.newQuery(question); 32 | query.setTSIG(key, Rcode.NOERROR, null); 33 | byte [] qbytes = query.toWire(); 34 | Message qparsed = new Message(qbytes); 35 | 36 | Message response = new Message(query.getHeader().getID()); 37 | response.setTSIG(key, Rcode.NOERROR, qparsed.getTSIG()); 38 | response.getHeader().setFlag(Flags.QR); 39 | response.addRecord(question, Section.QUESTION); 40 | Record answer = Record.fromString(qname, Type.A, DClass.IN, 300, 41 | "1.2.3.4", null); 42 | response.addRecord(answer, Section.ANSWER); 43 | byte [] bytes = response.toWire(512); 44 | 45 | Message parsed = new Message(bytes); 46 | int result = key.verify(parsed, bytes, qparsed.getTSIG()); 47 | assertEquals(result, Rcode.NOERROR); 48 | assertTrue(parsed.isSigned()); 49 | } 50 | 51 | public void test_TSIG_truncated() throws TextParseException, IOException 52 | { 53 | TSIG key = new TSIG(TSIG.HMAC_SHA256, "example.", "12345678"); 54 | 55 | Name qname = Name.fromString("www.example."); 56 | Record question = Record.newRecord(qname, Type.A, DClass.IN); 57 | Message query = Message.newQuery(question); 58 | query.setTSIG(key, Rcode.NOERROR, null); 59 | byte [] qbytes = query.toWire(); 60 | Message qparsed = new Message(qbytes); 61 | 62 | Message response = new Message(query.getHeader().getID()); 63 | response.setTSIG(key, Rcode.NOERROR, qparsed.getTSIG()); 64 | response.getHeader().setFlag(Flags.QR); 65 | response.addRecord(question, Section.QUESTION); 66 | for (int i = 0; i < 40; i++) { 67 | Record answer = Record.fromString(qname, Type.TXT, DClass.IN, 68 | 300, "foo" + i, null); 69 | response.addRecord(answer, Section.ANSWER); 70 | } 71 | byte [] bytes = response.toWire(512); 72 | 73 | Message parsed = new Message(bytes); 74 | assertTrue(parsed.getHeader().getFlag(Flags.TC)); 75 | int result = key.verify(parsed, bytes, qparsed.getTSIG()); 76 | assertEquals(result, Rcode.NOERROR); 77 | assertTrue(parsed.isSigned()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/TypeBitmapTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2011, org.xbill.DNS 4 | // All rights reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // * Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // 17 | // * Neither the name of the University of Colorado at Boulder nor the 18 | // names of its contributors may be used to endorse or promote 19 | // products derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | package org.xbill.DNS; 35 | 36 | import junit.framework.TestCase; 37 | 38 | public class TypeBitmapTest extends TestCase { 39 | public void test_empty() { 40 | TypeBitmap typeBitmap = new TypeBitmap(new int[]{}); 41 | assertEquals(typeBitmap.toString(), ""); 42 | } 43 | 44 | public void test_typeA() { 45 | TypeBitmap typeBitmap = new TypeBitmap(new int[]{1}); 46 | assertEquals(typeBitmap.toString(), "A"); 47 | } 48 | 49 | public void test_typeNSandSOA() { 50 | TypeBitmap typeBitmap = new TypeBitmap(new int[]{2, 6}); 51 | assertEquals(typeBitmap.toString(), "NS SOA"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/org/xbill/DNS/TypeTest.java: -------------------------------------------------------------------------------- 1 | // -*- Java -*- 2 | // 3 | // Copyright (c) 2005, Matthew J. Rutherford 4 | // Copyright (c) 2005, University of Colorado at Boulder 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // 14 | // * Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 18 | // * Neither the name of the University of Colorado at Boulder nor the 19 | // names of its contributors may be used to endorse or promote 20 | // products derived from this software without specific prior written 21 | // permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | package org.xbill.DNS; 36 | 37 | import junit.framework.TestCase; 38 | 39 | public class TypeTest extends TestCase 40 | { 41 | public void test_string() 42 | { 43 | // a regular one 44 | assertEquals("CNAME", Type.string(Type.CNAME)); 45 | 46 | // one that doesn't exist 47 | assertTrue(Type.string(65535).startsWith("TYPE")); 48 | 49 | try { 50 | Type.string(-1); 51 | fail("IllegalArgumentException not thrown"); 52 | } 53 | catch( IllegalArgumentException e ){ 54 | } 55 | } 56 | 57 | public void test_value() 58 | { 59 | // regular one 60 | assertEquals(Type.MAILB, Type.value("MAILB")); 61 | 62 | // one thats undefined but within range 63 | assertEquals(300, Type.value("TYPE300")); 64 | 65 | // something that unknown 66 | assertEquals(-1, Type.value("THIS IS DEFINITELY UNKNOWN")); 67 | 68 | // empty string 69 | assertEquals(-1, Type.value("")); 70 | } 71 | 72 | public void test_value_2arg() 73 | { 74 | assertEquals(301, Type.value("301", true)); 75 | } 76 | 77 | public void test_isRR() 78 | { 79 | assertTrue(Type.isRR(Type.CNAME)); 80 | assertFalse(Type.isRR(Type.IXFR)); 81 | } 82 | } 83 | --------------------------------------------------------------------------------