Example #1
0
 Message(DNSInput in) throws IOException {
   this(new Header(in));
   boolean isUpdate = (header.getOpcode() == Opcode.UPDATE);
   boolean truncated = header.getFlag(Flags.TC);
   try {
     for (int i = 0; i < 4; i++) {
       int count = header.getCount(i);
       if (count > 0) sections[i] = new ArrayList(count);
       for (int j = 0; j < count; j++) {
         int pos = in.current();
         Record rec = Record.fromWire(in, i, isUpdate);
         sections[i].add(rec);
         if (i == Section.ADDITIONAL) {
           if (rec.getType() == Type.TSIG) tsigstart = pos;
           if (rec.getType() == Type.SIG) {
             SIGRecord sig = (SIGRecord) rec;
             if (sig.getTypeCovered() == 0) sig0start = pos;
           }
         }
       }
     }
   } catch (WireParseException e) {
     if (!truncated) throw e;
   }
   size = in.current();
 }
Example #2
0
 void rrFromWire(DNSInput in) throws IOException {
   if (in.remaining() > 0) options = new ArrayList();
   while (in.remaining() > 0) {
     int code = in.readU16();
     int len = in.readU16();
     byte[] data = in.readByteArray(len);
     options.add(new Option(code, data));
   }
 }
  private static Record newRecord(
      Name name, int type, int dclass, long ttl, int length, DNSInput in) throws IOException {
    Record rec;
    int recstart;
    rec = getEmptyRecord(name, type, dclass, ttl, in != null);
    if (in != null) {
      if (in.remaining() < length) throw new WireParseException("truncated record");
      in.setActive(length);

      rec.rrFromWire(in);

      if (in.remaining() > 0) throw new WireParseException("invalid record length");
      in.clearActive();
    }
    return rec;
  }
  static Record fromWire(DNSInput in, int section, boolean isUpdate) throws IOException {
    int type, dclass;
    long ttl;
    int length;
    Name name;
    Record rec;

    name = new Name(in);
    type = in.readU16();
    dclass = in.readU16();

    if (section == Section.QUESTION) return newRecord(name, type, dclass);

    ttl = in.readU32();
    length = in.readU16();
    if (length == 0 && isUpdate) return newRecord(name, type, dclass, ttl);
    rec = newRecord(name, type, dclass, ttl, length, in);
    return rec;
  }
Example #5
0
 public TypeBitmap(DNSInput in) throws WireParseException {
   this();
   int lastbase = -1;
   while (in.remaining() > 0) {
     if (in.remaining() < 2) throw new WireParseException("invalid bitmap descriptor");
     int mapbase = in.readU8();
     if (mapbase < lastbase) throw new WireParseException("invalid ordering");
     int maplength = in.readU8();
     if (maplength > in.remaining()) throw new WireParseException("invalid bitmap");
     for (int i = 0; i < maplength; i++) {
       int current = in.readU8();
       if (current == 0) continue;
       for (int j = 0; j < 8; j++) {
         if ((current & (1 << (7 - j))) == 0) continue;
         int typecode = mapbase * 256 + +i * 8 + j;
         types.add(Mnemonic.toInteger(typecode));
       }
     }
   }
 }