1 /*
2 * Copyright 2016 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty.handler.codec.dns;
17
18 import static io.netty.util.internal.ObjectUtil.checkNotNull;
19
20 import io.netty.util.internal.StringUtil;
21
22 public class DefaultDnsPtrRecord extends AbstractDnsRecord implements DnsPtrRecord {
23
24 private final String hostname;
25
26 /**
27 * Creates a new PTR record.
28 *
29 * @param name the domain name
30 * @param dnsClass the class of the record, usually one of the following:
31 * <ul>
32 * <li>{@link #CLASS_IN}</li>
33 * <li>{@link #CLASS_CSNET}</li>
34 * <li>{@link #CLASS_CHAOS}</li>
35 * <li>{@link #CLASS_HESIOD}</li>
36 * <li>{@link #CLASS_NONE}</li>
37 * <li>{@link #CLASS_ANY}</li>
38 * </ul>
39 * @param timeToLive the TTL value of the record
40 * @param hostname the hostname this PTR record resolves to.
41 */
42 public DefaultDnsPtrRecord(
43 String name, int dnsClass, long timeToLive, String hostname) {
44 super(name, DnsRecordType.PTR, dnsClass, timeToLive);
45 this.hostname = checkNotNull(hostname, "hostname");
46 }
47
48 @Override
49 public String hostname() {
50 return hostname;
51 }
52
53 @Override
54 public String toString() {
55 final StringBuilder buf = new StringBuilder(64).append(StringUtil.simpleClassName(this)).append('(');
56 final DnsRecordType type = type();
57 buf.append(name().isEmpty()? "<root>" : name())
58 .append(' ')
59 .append(timeToLive())
60 .append(' ');
61
62 DnsMessageUtil.appendRecordClass(buf, dnsClass())
63 .append(' ')
64 .append(type.name());
65
66 buf.append(' ')
67 .append(hostname);
68
69 return buf.toString();
70 }
71 }