Пример #1
0
  /**
   * Compares this Record to another Object.
   *
   * @param arg The Object to be compared.
   * @return The value 0 if the argument is a record equivalent to this record; a value less than 0
   *     if the argument is less than this record in the canonical ordering, and a value greater
   *     than 0 if the argument is greater than this record in the canonical ordering. The canonical
   *     ordering is defined to compare by name, class, type, and rdata.
   * @throws ClassCastException if the argument is not a Record.
   */
  public int compareTo(Record arg) {
    if (this == arg) {
      return (0);
    }

    int n = name.compareTo(arg.name);
    if (n != 0) {
      return (n);
    }
    // TODO: just compare the enum value...
    n = dclass.getValue() - arg.dclass.getValue();
    if (n != 0) {
      return (n);
    }
    n = type - arg.type;
    if (n != 0) {
      return (n);
    }
    byte[] rdata1 = rdataToWireCanonical();
    byte[] rdata2 = arg.rdataToWireCanonical();
    for (int i = 0; i < rdata1.length && i < rdata2.length; i++) {
      n = (rdata1[i] & 0xFF) - (rdata2[i] & 0xFF);
      if (n != 0) {
        return (n);
      }
    }
    return (rdata1.length - rdata2.length);
  }
Пример #2
0
 /** Converts a Record into a String representation */
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(name);
   if (sb.length() < 8) {
     sb.append("\t");
   }
   if (sb.length() < 16) {
     sb.append("\t");
   }
   sb.append("\t");
   if (Options.check("BINDTTL")) {
     sb.append(TTL.format(ttl));
   } else {
     sb.append(ttl);
   }
   sb.append("\t");
   if (dclass != DClass.IN || !Options.check("noPrintIN")) {
     sb.append(dclass.getName());
     sb.append("\t");
   }
   sb.append(Type.string(type));
   String rdata = rrToString();
   if (!rdata.equals("")) {
     sb.append("\t");
     sb.append(rdata);
   }
   return sb.toString();
 }
Пример #3
0
  public static Record fromWire(DNSInput in, int section, boolean isUpdate) throws IOException {
    int type;
    DClass dclass;
    long ttl;
    int length;
    Name name;
    Record rec;

    name = new Name(in);
    type = in.readU16();
    dclass = DClass.getType(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;
  }
Пример #4
0
 protected void toWireCanonical(DNSOutput out, boolean noTTL) {
   toWireCanonical(out, name, type, dclass.getValue(), noTTL ? 0 : ttl);
 }
Пример #5
0
 public void toWire(DNSOutput out, int section, Compression c) {
   toWire(out, section, c, name, type, dclass.getValue(), ttl);
 }