Esempio n. 1
0
 /** Converts the Message to a String. */
 public String toString() {
   StringBuffer sb = new StringBuffer();
   OPTRecord opt = getOPT();
   if (opt != null) sb.append(header.toStringWithRcode(getRcode()) + "\n");
   else sb.append(header + "\n");
   if (isSigned()) {
     sb.append(";; TSIG ");
     if (isVerified()) sb.append("ok");
     else sb.append("invalid");
     sb.append('\n');
   }
   if (opt != null) {
     sb.append(";; OPT PSEUDOSECTION:\n");
     sb.append(";  EDNS: version: ");
     sb.append(opt.getVersion());
     sb.append(", flags:");
     if ((opt.getFlags() & ExtendedFlags.DO) != 0) {
       sb.append(" do");
     }
     sb.append("; udp: ");
     sb.append(opt.getPayloadSize());
     sb.append("\n");
   }
   for (int i = 0; i < 4; i++) {
     if (header.getOpcode() != Opcode.UPDATE) sb.append(";; " + Section.longString(i) + ":\n");
     else sb.append(";; " + Section.updString(i) + ":\n");
     sb.append(sectionToString(i) + "\n");
   }
   sb.append(";; Message size: " + numBytes() + " bytes");
   return sb.toString();
 }
Esempio n. 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();

    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;
  }
Esempio n. 3
0
 /** Returns the message's rcode (error code). This incorporates the EDNS extended rcode. */
 public int getRcode() {
   int rcode = header.getRcode();
   OPTRecord opt = getOPT();
   if (opt != null) rcode += (opt.getExtendedRcode() << 4);
   return rcode;
 }
Esempio n. 4
0
 private int maxUDPSize(Message query) {
   OPTRecord opt = query.getOPT();
   if (opt == null) return DEFAULT_UDPSIZE;
   else return opt.getPayloadSize();
 }