Home | History | Annotate | Download | only in DNS
      1 // Copyright (c) 2004 Brian Wellington (bwelling (at) xbill.org)
      2 
      3 package org.xbill.DNS;
      4 
      5 import java.io.*;
      6 
      7 /**
      8  * Implements common functionality for the many record types whose format
      9  * is an unsigned 16 bit integer followed by a name.
     10  *
     11  * @author Brian Wellington
     12  */
     13 
     14 abstract class U16NameBase extends Record {
     15 
     16 private static final long serialVersionUID = -8315884183112502995L;
     17 
     18 protected int u16Field;
     19 protected Name nameField;
     20 
     21 protected
     22 U16NameBase() {}
     23 
     24 protected
     25 U16NameBase(Name name, int type, int dclass, long ttl) {
     26 	super(name, type, dclass, ttl);
     27 }
     28 
     29 protected
     30 U16NameBase(Name name, int type, int dclass, long ttl, int u16Field,
     31 	    String u16Description, Name nameField, String nameDescription)
     32 {
     33 	super(name, type, dclass, ttl);
     34 	this.u16Field = checkU16(u16Description, u16Field);
     35 	this.nameField = checkName(nameDescription, nameField);
     36 }
     37 
     38 void
     39 rrFromWire(DNSInput in) throws IOException {
     40 	u16Field = in.readU16();
     41 	nameField = new Name(in);
     42 }
     43 
     44 void
     45 rdataFromString(Tokenizer st, Name origin) throws IOException {
     46 	u16Field = st.getUInt16();
     47 	nameField = st.getName(origin);
     48 }
     49 
     50 String
     51 rrToString() {
     52 	StringBuffer sb = new StringBuffer();
     53 	sb.append(u16Field);
     54 	sb.append(" ");
     55 	sb.append(nameField);
     56 	return sb.toString();
     57 }
     58 
     59 protected int
     60 getU16Field() {
     61 	return u16Field;
     62 }
     63 
     64 protected Name
     65 getNameField() {
     66 	return nameField;
     67 }
     68 
     69 void
     70 rrToWire(DNSOutput out, Compression c, boolean canonical) {
     71 	out.writeU16(u16Field);
     72 	nameField.toWire(out, null, canonical);
     73 }
     74 
     75 }
     76