示例#1
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;
  }
示例#2
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();

    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;
  }
示例#3
0
 /**
  * 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();
 }
示例#4
0
 /** 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();
 }
 /**
  * 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();
 }
 /*
  * 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();
 }
 /** Converts a Record into DNS uncompressed wire format. */
 public byte[] toWire(int section) {
   DNSOutput out = new DNSOutput();
   toWire(out, section, null);
   return out.toByteArray();
 }