예제 #1
0
  /* Returns the number of records not successfully rendered. */
  private int sectionToWire(DNSOutput out, int section, Compression c, int maxLength) {
    int n = sections[section].size();
    int pos = out.current();
    int rendered = 0;
    int skipped = 0;
    Record lastrec = null;

    for (int i = 0; i < n; i++) {
      Record rec = (Record) sections[section].get(i);
      if (section == Section.ADDITIONAL && rec instanceof OPTRecord) {
        skipped++;
        continue;
      }

      if (lastrec != null && !sameSet(rec, lastrec)) {
        pos = out.current();
        rendered = i;
      }
      lastrec = rec;
      rec.toWire(out, section, c);
      if (out.current() > maxLength) {
        out.jump(pos);
        return n - rendered + skipped;
      }
    }
    return skipped;
  }
예제 #2
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeU16(order);
   out.writeU16(preference);
   out.writeCountedString(flags);
   out.writeCountedString(service);
   out.writeCountedString(regexp);
   replacement.toWire(out, null, canonical);
 }
예제 #3
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   host.toWire(out, c, canonical);
   admin.toWire(out, c, canonical);
   out.writeU32(serial);
   out.writeU32(refresh);
   out.writeU32(retry);
   out.writeU32(expire);
   out.writeU32(minimum);
 }
예제 #4
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   if (options == null) return;
   Iterator it = options.iterator();
   while (it.hasNext()) {
     Option opt = (Option) it.next();
     out.writeU16(opt.code);
     out.writeU16(opt.data.length);
     out.writeByteArray(opt.data);
   }
 }
예제 #5
0
 private static void mapToWire(DNSOutput out, TreeSet map, int mapbase) {
   int arraymax = (((Integer) map.last()).intValue()) & 0xFF;
   int arraylength = (arraymax / 8) + 1;
   int[] array = new int[arraylength];
   out.writeU8(mapbase);
   out.writeU8(arraylength);
   for (Iterator it = map.iterator(); it.hasNext(); ) {
     int typecode = ((Integer) it.next()).intValue();
     array[(typecode & 0xFF) / 8] |= (1 << (7 - typecode % 8));
   }
   for (int j = 0; j < arraylength; j++) out.writeU8(array[j]);
 }
예제 #6
0
 void toWire(DNSOutput out, int section, Compression c) {
   name.toWire(out, c);
   out.writeU16(type);
   out.writeU16(dclass);
   if (section == Section.QUESTION) return;
   out.writeU32(ttl);
   int lengthPosition = out.current();
   out.writeU16(0); /* until we know better */
   rrToWire(out, c, false);
   int rrlength = out.current() - lengthPosition - 2;
   out.save();
   out.jump(lengthPosition);
   out.writeU16(rrlength);
   out.restore();
 }
예제 #7
0
  /* Returns true if the message could be rendered. */
  private boolean toWire(DNSOutput out, int maxLength) {
    if (maxLength < Header.LENGTH) return false;

    Header newheader = null;

    int tempMaxLength = maxLength;
    if (tsigkey != null) tempMaxLength -= tsigkey.recordLength();

    OPTRecord opt = getOPT();
    byte[] optBytes = null;
    if (opt != null) {
      optBytes = opt.toWire(Section.ADDITIONAL);
      tempMaxLength -= optBytes.length;
    }

    int startpos = out.current();
    header.toWire(out);
    Compression c = new Compression();
    int flags = header.getFlagsByte();
    int additionalCount = 0;
    for (int i = 0; i < 4; i++) {
      int skipped;
      if (sections[i] == null) continue;
      skipped = sectionToWire(out, i, c, tempMaxLength);
      if (skipped != 0 && i != Section.ADDITIONAL) {
        flags = Header.setFlag(flags, Flags.TC, true);
        out.writeU16At(header.getCount(i) - skipped, startpos + 4 + 2 * i);
        for (int j = i + 1; j < Section.ADDITIONAL; j++) out.writeU16At(0, startpos + 4 + 2 * j);
        break;
      }
      if (i == Section.ADDITIONAL) additionalCount = header.getCount(i) - skipped;
    }

    if (optBytes != null) {
      out.writeByteArray(optBytes);
      additionalCount++;
    }

    if (flags != header.getFlagsByte()) out.writeU16At(flags, startpos + 2);

    if (additionalCount != header.getCount(Section.ADDITIONAL))
      out.writeU16At(additionalCount, startpos + 10);

    if (tsigkey != null) {
      TSIGRecord tsigrec = tsigkey.generate(this, out.toByteArray(), tsigerror, querytsig);

      tsigrec.toWire(out, Section.ADDITIONAL, c);
      out.writeU16At(additionalCount + 1, startpos + 10);
    }

    return true;
  }
예제 #8
0
파일: Message.java 프로젝트: lemmy/dnsjava
  /* Returns the number of records not successfully rendered. */
  private int sectionToWire(DNSOutput out, int section, Compression c, int maxLength) {
    int n = sections[section].size();
    int pos = out.current();
    int rendered = 0;
    Record lastrec = null;

    for (int i = 0; i < n; i++) {
      Record rec = (Record) sections[section].get(i);
      if (lastrec != null && !sameSet(rec, lastrec)) {
        pos = out.current();
        rendered = i;
      }
      lastrec = rec;
      rec.toWire(out, section, c);
      if (out.current() > maxLength) {
        out.jump(pos);
        return n - rendered;
      }
    }
    return 0;
  }
예제 #9
0
  void rrToWire(DNSOutput out, Compression c, boolean canonical) {
    out.writeU8(hashAlg);
    out.writeU8(flags);
    out.writeU16(iterations);

    if (salt != null) {
      out.writeU8(salt.length);
      out.writeByteArray(salt);
    } else out.writeU8(0);

    out.writeU8(next.length);
    out.writeByteArray(next);
    types.toWire(out);
  }
예제 #10
0
파일: Message.java 프로젝트: lemmy/dnsjava
  /* Returns true if the message could be rendered. */
  private boolean toWire(DNSOutput out, int maxLength) {
    if (maxLength < Header.LENGTH) return false;

    Header newheader = null;

    int tempMaxLength = maxLength;
    if (tsigkey != null) tempMaxLength -= tsigkey.recordLength();

    int startpos = out.current();
    header.toWire(out);
    Compression c = new Compression();
    for (int i = 0; i < 4; i++) {
      int skipped;
      if (sections[i] == null) continue;
      skipped = sectionToWire(out, i, c, tempMaxLength);
      if (skipped != 0) {
        if (i != Section.ADDITIONAL) {
          if (newheader == null) newheader = (Header) header.clone();
          newheader.setFlag(Flags.TC);
          int count = newheader.getCount(i);
          newheader.setCount(i, count - skipped);
          for (int j = i + 1; j < 4; j++) newheader.setCount(j, 0);

          out.save();
          out.jump(startpos);
          newheader.toWire(out);
          out.restore();
        }
        break;
      }
    }

    if (tsigkey != null) {
      TSIGRecord tsigrec = tsigkey.generate(this, out.toByteArray(), tsigerror, querytsig);

      if (newheader == null) newheader = (Header) header.clone();
      tsigrec.toWire(out, Section.ADDITIONAL, c);
      newheader.incCount(Section.ADDITIONAL);

      out.save();
      out.jump(startpos);
      newheader.toWire(out);
      out.restore();
    }

    return true;
  }
예제 #11
0
파일: LOCRecord.java 프로젝트: uppaljs/sef
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeU8(0); /* version */
   out.writeU8(toLOCformat(size));
   out.writeU8(toLOCformat(hPrecision));
   out.writeU8(toLOCformat(vPrecision));
   out.writeU32(latitude);
   out.writeU32(longitude);
   out.writeU32(altitude);
 }
예제 #12
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeU16(certType);
   out.writeU16(keyTag);
   out.writeU8(alg);
   out.writeByteArray(cert);
 }
예제 #13
0
파일: Message.java 프로젝트: lemmy/dnsjava
 /**
  * Returns an array containing the wire format representation of the Message with the specified
  * maximum length. This will generate a truncated message (with the TC bit) if the message doesn't
  * fit, and will also sign the message with the TSIG key set by a call to setTSIG(). This method
  * may return null if the message could not be rendered at all; this could happen if maxLength is
  * smaller than a DNS header, for example.
  *
  * @param maxLength The maximum length of the message.
  * @return The wire format of the message, or null if the message could not be rendered into the
  *     specified length.
  * @see Flags
  * @see TSIG
  */
 public byte[] toWire(int maxLength) {
   DNSOutput out = new DNSOutput();
   toWire(out, maxLength);
   size = out.current();
   return out.toByteArray();
 }
예제 #14
0
파일: Message.java 프로젝트: lemmy/dnsjava
 /** Returns an array containing the wire format representation of the Message. */
 public byte[] toWire() {
   DNSOutput out = new DNSOutput();
   toWire(out);
   size = out.current();
   return out.toByteArray();
 }
예제 #15
0
 /*
  * Converts a Record into canonical DNS uncompressed wire format (all names are
  * converted to lowercase), optionally ignoring the TTL.
  */
 private byte[] toWireCanonical(boolean noTTL) {
   DNSOutput out = new DNSOutput();
   toWireCanonical(out, noTTL);
   return out.toByteArray();
 }
예제 #16
0
 private void toWireCanonical(DNSOutput out, boolean noTTL) {
   name.toWireCanonical(out);
   out.writeU16(type);
   out.writeU16(dclass);
   if (noTTL) {
     out.writeU32(0);
   } else {
     out.writeU32(ttl);
   }
   int lengthPosition = out.current();
   out.writeU16(0); /* until we know better */
   rrToWire(out, null, true);
   int rrlength = out.current() - lengthPosition - 2;
   out.save();
   out.jump(lengthPosition);
   out.writeU16(rrlength);
   out.restore();
 }
예제 #17
0
 /** Converts a Record into DNS uncompressed wire format. */
 public byte[] toWire(int section) {
   DNSOutput out = new DNSOutput();
   toWire(out, section, null);
   return out.toByteArray();
 }
예제 #18
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeByteArray(address);
 }
예제 #19
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeU32(((long) addr) & 0xFFFFFFFFL);
 }
예제 #20
0
 /**
  * Converts the rdata in a Record into canonical DNS uncompressed wire format (all names are
  * converted to lowercase).
  */
 public byte[] rdataToWireCanonical() {
   DNSOutput out = new DNSOutput();
   rrToWire(out, null, true);
   return out.toByteArray();
 }
예제 #21
0
 void optionToWire(DNSOutput out) {
   out.writeByteArray(data);
 }
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeU16(u16Field);
   nameField.toWire(out, null, canonical);
 }
예제 #23
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeCountedString(address);
   if (subAddress != null) out.writeCountedString(subAddress);
 }