this.type = TYPE.getType(dis.readUnsignedShort()); int clazzValue = dis.readUnsignedShort(); this.clazz = CLASS.getClass(clazzValue & 0x7fff);
/** * Generate a binary paket for this dns question. * @return The dns question. */ public byte[] toByteArray() { if (byteArray == null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); DataOutputStream dos = new DataOutputStream(baos); try { dos.write(NameUtil.toByteArray(this.name)); dos.writeShort(type.getValue()); dos.writeShort(clazz.getValue() | (unicastQuery ? (1 << 15) : 0)); dos.flush(); } catch (IOException e) { // Should never happen throw new IllegalStateException(e); } byteArray = baos.toByteArray(); } return byteArray; }
/** * Resolve the given name and type which is expected to yield DNSSEC authenticated results. * * @param name the DNS name to resolve. * @param type the class of the RR type to resolve. * @param <D> the RR type to resolve. * @return the resolver result. * @throws IOException in case an exception happens while resolving. * @see #resolveDnssecReliable(Question) */ public <D extends Data> ResolverResult<D> resolveDnssecReliable(DNSName name, Class<D> type) throws IOException { TYPE t = TYPE.getType(type); Question q = new Question(name, t); return resolveDnssecReliable(q); }
/** * Parse a byte array and rebuild the dns question from it. * @param dis The input stream. * @param data The plain data (for dns name references). * @return The parsed dns question. * @throws IOException On errors (read outside of packet). */ public static Question parse(DataInputStream dis, byte[] data) throws IOException { String name = NameUtil.parse(dis, data); TYPE type = TYPE.getType(dis.readUnsignedShort()); CLASS clazz = CLASS.getClass(dis.readUnsignedShort()); return new Question (name, type, clazz); }
public final <D extends Data> ResolverResult<D> resolve(DNSName name, Class<D> type) throws IOException { TYPE t = TYPE.getType(type); Question q = new Question(name, t); return resolve(q); }