blob: df3c836457ae4f9e42ec9a220f41a949204b8865 [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001// Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2
3package org.xbill.DNS;
4
5import 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
14abstract class U16NameBase extends Record {
15
16private static final long serialVersionUID = -8315884183112502995L;
17
18protected int u16Field;
19protected Name nameField;
20
21protected
22U16NameBase() {}
23
24protected
25U16NameBase(Name name, int type, int dclass, long ttl) {
26 super(name, type, dclass, ttl);
27}
28
29protected
30U16NameBase(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
38void
39rrFromWire(DNSInput in) throws IOException {
40 u16Field = in.readU16();
41 nameField = new Name(in);
42}
43
44void
45rdataFromString(Tokenizer st, Name origin) throws IOException {
46 u16Field = st.getUInt16();
47 nameField = st.getName(origin);
48}
49
50String
51rrToString() {
52 StringBuffer sb = new StringBuffer();
53 sb.append(u16Field);
54 sb.append(" ");
55 sb.append(nameField);
56 return sb.toString();
57}
58
59protected int
60getU16Field() {
61 return u16Field;
62}
63
64protected Name
65getNameField() {
66 return nameField;
67}
68
69void
70rrToWire(DNSOutput out, Compression c, boolean canonical) {
71 out.writeU16(u16Field);
72 nameField.toWire(out, null, canonical);
73}
74
75}