/* 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; }
/* 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; }
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(); }
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(); }
/* 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; }